! AlexNotTheLion
! AlexNotTheLion
Explore posts from servers
DTDrizzle Team
Created by ! AlexNotTheLion on 4/2/2024 in #help
friendship query that returns the other user object
I have two tables:
friendships:{id:uuid, sender: uuid, target: uuid, status: enum("accepted","pending")}
friendships:{id:uuid, sender: uuid, target: uuid, status: enum("accepted","pending")}
and
profiles:{id:uuid, username:string}
profiles:{id:uuid, username:string}
I want to query the friendships table for the local user id from the supabase client (supabase auth table syncs rows to the profiles table), and return an object like {id:friendship.id, status:friendship.status, user:profile} where the user is the other user, unfortunately most ai coding assistants dont have full or up to date knowledge of drizzle orms (including the one on the drizzle docs site) so is this possible with just drizzle syntax's and how can i do this ?
8 replies
DTDrizzle Team
Created by ! AlexNotTheLion on 2/19/2024 in #help
(Solved) Filter where json array contains
I have a json array of strings, an invite list of user ids (clerk is managing my users which is why its not a relation), im trying to get all results from the events table where the current users id is in the invite list or the host, using planetscale (mysql) and i cannot figure out the correct syntax this is what i have so far
const user = await currentUser();
if (user === null) return [];

const query = await db.query.events.findMany({
where: or(eq(events.user_id, user.id), inArray(events.invited_users, [user.id]))
});
const user = await currentUser();
if (user === null) return [];

const query = await db.query.events.findMany({
where: or(eq(events.user_id, user.id), inArray(events.invited_users, [user.id]))
});
and this is the schema for the events table
export const events = mysqlTable('event', {
id: serial('id').primaryKey(),
user_id: text('user_id').notNull(),
start: timestamp('start', { mode: 'date' }).defaultNow().notNull(),
end: timestamp('end', { mode: 'date' }).defaultNow().notNull(),
title: varchar('title', { length: 50 }),
description: varchar('description', { length: 500 }).default(""),
invited_users: json("invited_users").$type<string[]>().default([]),
});
export const events = mysqlTable('event', {
id: serial('id').primaryKey(),
user_id: text('user_id').notNull(),
start: timestamp('start', { mode: 'date' }).defaultNow().notNull(),
end: timestamp('end', { mode: 'date' }).defaultNow().notNull(),
title: varchar('title', { length: 50 }),
description: varchar('description', { length: 500 }).default(""),
invited_users: json("invited_users").$type<string[]>().default([]),
});
6 replies
DTDrizzle Team
Created by ! AlexNotTheLion on 11/7/2023 in #help
[Solved] cannot find package 'mysql2'
I've setup drizzle with a planetscale db and pushed a simple user schema, however running the pnpm drizzle-kit studio command as indicated in the docs comes back with the following error
Cannot find package 'mysql2' imported from C:\Users\username\Desktop\testProj\node_modules\.pnpm\[email protected]_@[email protected]\node_modules\drizzle-orm\mysql2\index.mjs
Cannot find package 'mysql2' imported from C:\Users\username\Desktop\testProj\node_modules\.pnpm\[email protected]_@[email protected]\node_modules\drizzle-orm\mysql2\index.mjs
does anyone know why ?
2 replies