#Problems to use Knex into hook

8 messages · Page 1 of 1 (latest)

zenith barn
#

Hi

I have a problem tu use the directus orm , for some reason I only can read the register, but I can not store any register , I am using the following code

const res = await context.database("upload_file_error_log").insert({ collection: "courses", message, }).then(e => console.log('e ', e)).catch(err => console.log('err ', err));

what I doing wrong?

fading forumBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

gilded coral
#

Try using the ItemsService to make sure Directus logic/events get triggered and permissions get checked when working with data:

const service = new context.services.ItemsService('my-collection', { knex: context.database, schema: await context.getSchema() });

const result = await service.createOne({ ...itemData });
zenith barn
#

@gilded coral Hi !, I got this error regardind your example, I apply the following code

`const service = new context.services.ItemsService('upload_file_error_log', { knex: context.database, schema: await context.getSchema() });

    const result = await service.createOne({ 
      collection: "courses",
      message,
    });`
gilded coral
#

make sure context is the right context, second argument of your defineHook function

zenith barn
#

Got it I will check