jakeleventhal
jakeleventhal
Explore posts from servers
DTDrizzle Team
Created by jakeleventhal on 5/10/2024 in #help
Best way to get count in extras
what i want is to be able to do something like:
extras: {
productsCount: db.select({value: count()}).from(products).where(...)
extras: {
productsCount: db.select({value: count()}).from(products).where(...)
2 replies
DTDrizzle Team
Created by J O A Q U I N on 4/19/2024 in #help
Stuck not being able to acces my project's DB locally through drizzle.studio
this didnt work for me
4 replies
DTDrizzle Team
Created by jakeleventhal on 3/19/2024 in #help
How do you use batch API with local development
for postgres-js for instance, wouldnt batch implementation just be something like this:
// user code:
await db.batch(statements satisfies Array<SQL>);

// under the hood code:
await db.execute(sql`
BEGIN TRANSACTION
${statements.join(';\n')}
COMMIT TRANSACTION
`);
// user code:
await db.batch(statements satisfies Array<SQL>);

// under the hood code:
await db.execute(sql`
BEGIN TRANSACTION
${statements.join(';\n')}
COMMIT TRANSACTION
`);
3 replies
DTDrizzle Team
Created by jakeleventhal on 1/8/2024 in #help
How to run drizzle-kit studio out of docker?
i explain in the GH issue
13 replies
DTDrizzle Team
Created by jakeleventhal on 8/12/2023 in #help
What exactly is the `check` command doing?
+1
12 replies
DTDrizzle Team
Created by jakeleventhal on 1/22/2024 in #help
Getting seemingly incorrect relation error
ty
11 replies
DTDrizzle Team
Created by jakeleventhal on 1/22/2024 in #help
Getting seemingly incorrect relation error
yeah that should work actually
11 replies
DTDrizzle Team
Created by jakeleventhal on 1/22/2024 in #help
Getting seemingly incorrect relation error
productSet: one(productSets) in order to add a relation name i also need fields and references
11 replies
DTDrizzle Team
Created by jakeleventhal on 1/22/2024 in #help
Getting seemingly incorrect relation error
how would i do that without an additional foreign key
11 replies
DTDrizzle Team
Created by jakeleventhal on 1/18/2024 in #help
How do you define one-to-one relations in the same table?
a digital listing and a physical listing were each separate rows in the database
21 replies
DTDrizzle Team
Created by jakeleventhal on 1/18/2024 in #help
How do you define one-to-one relations in the same table?
i suppose that could work as well. so when i make the connection, just make sure assign both foreign keys
21 replies
DTDrizzle Team
Created by jakeleventhal on 1/18/2024 in #help
How do you define one-to-one relations in the same table?
well it should be one-to-one because of the unique constriant on physicalListingId
21 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
ty
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
your solution actually works!
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
settings table is actually branding, just named settings to make it easier to understand in this example. i updated my message above
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
but what i was trying to do was basically this
export const settingsRelations = relations(settings, ({ one }) => ({
packageInsert: one(designs),
packageSticker: one(designs)
}));

export const designRelations = relations(designs, ({ one }) => ({
packageInsertSettings: one(settings, {
fields: [designs.packageInsertId],
references: [settings.id]
}),
packageStickerSettings: one(settings, {
fields: [designs.packageStickerId],
references: [settings.id]
})
}));
export const settingsRelations = relations(settings, ({ one }) => ({
packageInsert: one(designs),
packageSticker: one(designs)
}));

export const designRelations = relations(designs, ({ one }) => ({
packageInsertSettings: one(settings, {
fields: [designs.packageInsertId],
references: [settings.id]
}),
packageStickerSettings: one(settings, {
fields: [designs.packageStickerId],
references: [settings.id]
})
}));
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
here is my drizzle rendition
export const settings = pgTable('Settings', {
id: text('id')
.primaryKey()
.$defaultFn(() => sql`gen_random_uuid()::text`)
.notNull()
});

export const designs = pgTable(
'Design',
{
id: text('id')
.primaryKey()
.$defaultFn(() => sql`gen_random_uuid()::text`)
.notNull(),
packageInsertId: text('packageInsertId').references(() => settings.id, {
onDelete: 'cascade',
onUpdate: 'cascade'
}),
packageStickerId: text('packageStickerId').references(() => settings.id, {
onDelete: 'cascade',
onUpdate: 'cascade'
})
},
(table) => ({
packageInsertIdKey: uniqueIndex('Design_packageInsertId_key').on(table.packageInsertId),
packageStickerIdKey: uniqueIndex('Design_packageStickerId_key').on(table.packageStickerId)
})
);
export const settings = pgTable('Settings', {
id: text('id')
.primaryKey()
.$defaultFn(() => sql`gen_random_uuid()::text`)
.notNull()
});

export const designs = pgTable(
'Design',
{
id: text('id')
.primaryKey()
.$defaultFn(() => sql`gen_random_uuid()::text`)
.notNull(),
packageInsertId: text('packageInsertId').references(() => settings.id, {
onDelete: 'cascade',
onUpdate: 'cascade'
}),
packageStickerId: text('packageStickerId').references(() => settings.id, {
onDelete: 'cascade',
onUpdate: 'cascade'
})
},
(table) => ({
packageInsertIdKey: uniqueIndex('Design_packageInsertId_key').on(table.packageInsertId),
packageStickerIdKey: uniqueIndex('Design_packageStickerId_key').on(table.packageStickerId)
})
);
i didnt include the relations becuase i couldnt get them to work
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
sure, here is the prisma version of the tables that was working:
model Settings {
id String @id @default(uuid())

packageInsert Design? @relation(name: "packageInsert")
packageSticker Design?
}

model Design {
id String @id @default(uuid())

packageInsert Settings? @relation(fields: [packageInsertId], references: [id], onDelete: Cascade, "packageInsert")
packageInsertId String? @unique
packageSticker Settings? @relation(fields: [packageStickerId], references: [id], onDelete: Cascade)
packageStickerId String? @unique
}
model Settings {
id String @id @default(uuid())

packageInsert Design? @relation(name: "packageInsert")
packageSticker Design?
}

model Design {
id String @id @default(uuid())

packageInsert Settings? @relation(fields: [packageInsertId], references: [id], onDelete: Cascade, "packageInsert")
packageInsertId String? @unique
packageSticker Settings? @relation(fields: [packageStickerId], references: [id], onDelete: Cascade)
packageStickerId String? @unique
}
(aka i could do this query)
prisma.settings.findFirst({ include: { packageSticker: true, packageInsert: true } })
prisma.settings.findFirst({ include: { packageSticker: true, packageInsert: true } })
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
my specific use case is as follows: a user is able to add a design for a package sticker as well as a package insert. designs can also be used for other things so in my use case i have designs.packageStickerSettingId and designs.packageInsertSettingsId. essentially what i want to be able to do is query the user's settings along with the deisgn values for packageSticker and packageInsert by doing a query like
db.query.settings.findFirst({ with: { packageSticker: true, packageInsert: true } })
db.query.settings.findFirst({ with: { packageSticker: true, packageInsert: true } })
14 replies
DTDrizzle Team
Created by jakeleventhal on 1/20/2024 in #help
Anyone have any idea about this bug?
How else are you to make that kind of query
14 replies