Atinux/nuxt-guestbook

Drizzle Partial Select not possible

Closed this issue · 9 comments

Because the way Drizzle is initialized, it is somehow not possible to do partial selects with drizzle. Is there somehow a nice workaround to get this working? I am using the same setup in a project of mine and running in this issue. Also, would it be possible to provide drizzle with the schema, so the query syntax is working?

Thank you for this nice template!

Could you give me an example of partial selects @Lennart-Franck ?

Of course @Atinux, just the plain partial select as seen in the drizzle documentation: https://orm.drizzle.team/docs/select#partial-select

Well from what I see:

const result = await db.select({
  field1: users.id,
  field2: users.name,
}).from(users);

Can become:

const result = await useDB().select({
  field1: tables.users.id,
  field2: tables.users.name,
}).from(users);

If i use it for example like that:

export default eventHandler(() => {
  return useDB().select({
    authorName: tables.comments.author
  }).from(tables.comments)
})

I get the following error:
Expected 0 arguments, but got 1.

Well you need to call .all() at the end

Still getting the error when I use the following code:

export default eventHandler(() => {
  return useDB().select({
    authorName: tables.comments.author
  }).from(tables.comments).all()
})

Oh well it seems to be a TS error, the code works though right? (tested locally and it works)

Okay, firstly, thank you very much for taking your time with me @Atinux! And second, yeah, it looks like a TS error because the code gets executed. Do you maybe know how to fix this TS error?

Sadly I have no idea, drizzle should actually handle this 🤔