Blume
Blume
Explore posts from servers
DTDrizzle Team
Created by Blume on 10/15/2023 in #help
Use column name in like operator
I was able to solve it via
or(eq(tagsWithNoteIds.tag, Tags.tag), sql`${tagsWithNoteIds.tag} LIKE ${Tags.tag} || '%'`)
or(eq(tagsWithNoteIds.tag, Tags.tag), sql`${tagsWithNoteIds.tag} LIKE ${Tags.tag} || '%'`)
Not as pretty but does the job
2 replies
DTDrizzle Team
Created by Blume on 10/14/2023 in #help
many-to-many query with where filter on second level
I was able to solve it with
const selectTags = DB.$with("sq").as(
DB.select({ noteId: NotesToTags.noteId, tags: sql<string[]>`array_agg(${Tags.tag})`.as("tags") })
.from(NotesToTags)
.leftJoin(Tags, eq(Tags.id, NotesToTags.tagId))
.where(like(Tags.tag, `${query.tag ?? ""}%`))
.groupBy(NotesToTags.noteId),
);

const result = await DB.with(selectTags)
.select()
.from(Notes)
.innerJoin(selectTags, eq(selectTags.noteId, Notes.id))
.where(and(eq(Notes.authorId, query.authorId)));
const selectTags = DB.$with("sq").as(
DB.select({ noteId: NotesToTags.noteId, tags: sql<string[]>`array_agg(${Tags.tag})`.as("tags") })
.from(NotesToTags)
.leftJoin(Tags, eq(Tags.id, NotesToTags.tagId))
.where(like(Tags.tag, `${query.tag ?? ""}%`))
.groupBy(NotesToTags.noteId),
);

const result = await DB.with(selectTags)
.select()
.from(Notes)
.innerJoin(selectTags, eq(selectTags.noteId, Notes.id))
.where(and(eq(Notes.authorId, query.authorId)));
2 replies
DTDrizzle Team
Created by ippo on 9/15/2023 in #help
TRIGGERS in Drizzle
Thanks!
13 replies
DTDrizzle Team
Created by ippo on 9/15/2023 in #help
TRIGGERS in Drizzle
Hmm I see, I'm not yet using migration files (Early project) but maybe I can use a custom migration file for stuff like that
13 replies
DTDrizzle Team
Created by ippo on 9/15/2023 in #help
TRIGGERS in Drizzle
Have you been able to do it? I have no Idea how I would do this in the schema file... And how would drizzle-kit know how to write the migration when using plain SQL? A drizzle-native way to add triggers would be really cool
13 replies