DiamondDragon
DiamondDragon
Explore posts from servers
DTDrizzle Team
Created by DiamondDragon on 6/20/2024 in #help
Use results of a column to pass where conditions elsewhere in the query?
I have a field that stores filters that I parse into the SQL conditions for a where clause. Or at least, that's the goal. That field is in my views table. Is it possible to pass the result of that field in views into a nested where condition?
export async function getTableData(opts: { db: Db; tableShortId: string; viewShortId: string }) {

const { db, tableShortId, viewShortId } = opts

const tableData = await db.query.views.findFirst({
where: and(eq(views.shortId, viewShortId), eq(views.tableId, tableShortId)),
columns: {
shortId: true,
},
with: {
// Get the view for the table
table: {
columns: { shortId: true },
with: {
fields: {
columns: { shortId: true },
},
records: {
//! is it possible to filter records by view.jsonColumn after being parsed
columns: { shortId: true },
with: {
export async function getTableData(opts: { db: Db; tableShortId: string; viewShortId: string }) {

const { db, tableShortId, viewShortId } = opts

const tableData = await db.query.views.findFirst({
where: and(eq(views.shortId, viewShortId), eq(views.tableId, tableShortId)),
columns: {
shortId: true,
},
with: {
// Get the view for the table
table: {
columns: { shortId: true },
with: {
fields: {
columns: { shortId: true },
},
records: {
//! is it possible to filter records by view.jsonColumn after being parsed
columns: { shortId: true },
with: {
1 replies
DTDrizzle Team
Created by DiamondDragon on 6/10/2024 in #help
construction a dynamic query builder generically ?
Ok i'm not really sure how to ask this but I'm trying to allow a user the ability in UI to build out a query builder where they can add many filters with potentially nested filters with AND/OR conjuctions. Like airtable. Anyone have any patterns how to do this? I had attempted to try to construct a mapping on the SQL operators and the drizzle functions but I can't get the types to work . I'm playing aroung just with the sql operator to try making ti work with more raw SQL. trying to wrap my head around this and its a pattern i've seen few apps implement and never seen any code online to use as a guide Ideally a user can do a query in the UI like below and the queries can be constructed dynamically.
Filter employes where
name = john AND
salary >= 50,000 AND
relatedDepartment contains 'billing' AND
( department_city does not contain NYC OR
whatever... equals blah
)
Filter employes where
name = john AND
salary >= 50,000 AND
relatedDepartment contains 'billing' AND
( department_city does not contain NYC OR
whatever... equals blah
)
const operators: Record<OperatorNames, Operator> = {
contains: {
label: 'Contains',
name: 'contains',
sql: 'LIKE',
drizzle: (column: Column, value: string | SQLWrapper): typeof like => {
return like(column, value)
},
},
// other operators...
}
const operators: Record<OperatorNames, Operator> = {
contains: {
label: 'Contains',
name: 'contains',
sql: 'LIKE',
drizzle: (column: Column, value: string | SQLWrapper): typeof like => {
return like(column, value)
},
},
// other operators...
}
1 replies
HHono
Created by DiamondDragon on 6/8/2024 in #help
Serialization of Date?
Is there any suggested guidance on how to handle js/json serialization? I ran into an issue using the hono client where the types break due to a Date being typed as a string after being returned from a hono route I see there are no data transformers provided by hono, so wondering what suggestions there are. https://discord.com/channels/1011308539819597844/1248521918554963979
6 replies
DTDrizzle Team
Created by DiamondDragon on 5/19/2024 in #help
Losing custom $types in pg jsonb using drizzle-zod
Not sure if this is an expected limitation of zod here
export const records = pgTable('records', {
id: uuid('id')
.primaryKey()
.$defaultFn(() => uuidv7()),
tableId: uuid('table_id')
.references(() => tables.id, { onDelete: 'cascade' })
.notNull(),
organizationId: uuid('organization_id')
.references(() => organizations.id, { onDelete: 'cascade' })
.notNull(),
recordByFieldId: jsonb('record_by_field_id').$type<RecordData>(),

})
export const records = pgTable('records', {
id: uuid('id')
.primaryKey()
.$defaultFn(() => uuidv7()),
tableId: uuid('table_id')
.references(() => tables.id, { onDelete: 'cascade' })
.notNull(),
organizationId: uuid('organization_id')
.references(() => organizations.id, { onDelete: 'cascade' })
.notNull(),
recordByFieldId: jsonb('record_by_field_id').$type<RecordData>(),

})
produces using $inferInsert
type Record = {
organizationId: string;
tableId: string;
id?: string;
recordByFieldId?: RecordData | null;
createdAt?: Date;
updatedAt?: Date | null;
}
type Record = {
organizationId: string;
tableId: string;
id?: string;
recordByFieldId?: RecordData | null;
createdAt?: Date;
updatedAt?: Date | null;
}
But when using drizzle zod, i lose RecordData
export const insertRecordSchema = createInsertSchema(records)
export type InsertRecord = z.infer<typeof insertRecordSchema>

// results in
type InsertRecord = {
organizationId: string;
tableId: string;
id?: string;
recordByFieldId?: any;
createdAt?: Date;
updatedAt?: Date | null;
}
export const insertRecordSchema = createInsertSchema(records)
export type InsertRecord = z.infer<typeof insertRecordSchema>

// results in
type InsertRecord = {
organizationId: string;
tableId: string;
id?: string;
recordByFieldId?: any;
createdAt?: Date;
updatedAt?: Date | null;
}
1 replies
CDCloudflare Developers
Created by DiamondDragon on 4/23/2024 in #pages-help
Can't deploy a nextjs pages site in subdirectory
No description
1 replies
DTDrizzle Team
Created by DiamondDragon on 4/17/2024 in #help
Generated SQL error / type error with operations on unique index
No description
1 replies
DTDrizzle Team
Created by DiamondDragon on 4/16/2024 in #help
Drizzle studio shows as blank page on Arc browser
No description
1 replies
CDCloudflare Developers
Created by DiamondDragon on 4/13/2024 in #workers-help
cron not running locally on the trigger specified
I'm using hono here but when i go to http://localhost:8787/__scheduled?cron=***** i see the response log
Hello
[wrangler:inf] GET /__scheduled 200 OK (11ms)
╭─────────────────────────────────────────────────────
Hello
[wrangler:inf] GET /__scheduled 200 OK (11ms)
╭─────────────────────────────────────────────────────
but I dont see anymore subsequent logs of the trigger again. am i doing anything wrong?
async function scheduledHandler(
event: ScheduledEvent,
env: Env,
ctx: ExecutionContext,
) {
const testMessages = [
'Hello',
'Goodbye',
'Welcome',
'Farewell',
'Greetings',
'I am leaving',
]
ctx.waitUntil(
(async () => {
const randomIndex = Math.floor(Math.random() * testMessages.length)
const randomMessage = testMessages[randomIndex]
console.log(randomMessage)
})(),
)
}

export default { fetch: app.fetch.bind(app), scheduled: scheduledHandler }
async function scheduledHandler(
event: ScheduledEvent,
env: Env,
ctx: ExecutionContext,
) {
const testMessages = [
'Hello',
'Goodbye',
'Welcome',
'Farewell',
'Greetings',
'I am leaving',
]
ctx.waitUntil(
(async () => {
const randomIndex = Math.floor(Math.random() * testMessages.length)
const randomMessage = testMessages[randomIndex]
console.log(randomMessage)
})(),
)
}

export default { fetch: app.fetch.bind(app), scheduled: scheduledHandler }
4 replies
CDCloudflare Developers
Created by DiamondDragon on 4/13/2024 in #pages-help
Project is set up for npm but it is currently being run via bun this might lead to build errors
Don't recall using npm when i init the repo but anyways, wondering what settings were set on npm that i should check out if im using bun
❯ nr
✔ script to run › preview
$ bun pages:build && wrangler pages dev .vercel/output/static
$ bunx @cloudflare/next-on-pages
⚡️ @cloudflare/next-on-pages CLI v.1.11.0

⚡️ The project is set up for npm but it is currently being run via bun this might lead to build errors, please be sure to use the same package manager your project uses when running @cloudflare/next-on-pages

⚡️ Detected Package Manager: bun (1.1.1)
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲ Vercel CLI 34.0.0
WARNING: You should not upload the `.next` directory.
▲ Installing dependencies...
▲ removed 3 packages, and changed 96 packages in 18s

156 packages are looking for funding
▲ run `npm fund` for details
▲ Detected Next.js version: 14.2.0
▲ Detected `package-lock.json` generated by npm 7+
▲ Running "npm run build"
> next-cf@0.1.0 build
> next build
▲ ▲ Next.js 14.2.0
- Environments: .env.local
▲ Creating an optimized production build ...
▲ ✓ Compiled successfully
❯ nr
✔ script to run › preview
$ bun pages:build && wrangler pages dev .vercel/output/static
$ bunx @cloudflare/next-on-pages
⚡️ @cloudflare/next-on-pages CLI v.1.11.0

⚡️ The project is set up for npm but it is currently being run via bun this might lead to build errors, please be sure to use the same package manager your project uses when running @cloudflare/next-on-pages

⚡️ Detected Package Manager: bun (1.1.1)
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲ Vercel CLI 34.0.0
WARNING: You should not upload the `.next` directory.
▲ Installing dependencies...
▲ removed 3 packages, and changed 96 packages in 18s

156 packages are looking for funding
▲ run `npm fund` for details
▲ Detected Next.js version: 14.2.0
▲ Detected `package-lock.json` generated by npm 7+
▲ Running "npm run build"
> next-cf@0.1.0 build
> next build
▲ ▲ Next.js 14.2.0
- Environments: .env.local
▲ Creating an optimized production build ...
▲ ✓ Compiled successfully
5 replies
TTCTheo's Typesafe Cult
Created by DiamondDragon on 4/9/2024 in #questions
Recommended guides for knowing which html tags to style globally?
my design skills aren't great and i've gotten to know CSS mainly through tailwind. Most of my experience is designing app components but i'm working on some blogs and am finding myself sometimes confused where i tend to end up apply tw classes on many different main tags and what nto. I notice a lot of projects style their globals.css for some of the common tags. I'm wondering if there are guides that suggest like "you should do x to your body gloally, y to your h1's etc). I feel like im a little bit dyslexic so i hate getting "lost" in my tw classes , esp. across pages or components
7 replies
DTDrizzle Team
Created by DiamondDragon on 4/7/2024 in #help
Missing nested where clause
No description
23 replies
DTDrizzle Team
Created by DiamondDragon on 3/21/2024 in #help
bun:sqlite - why is my sqlite3 version mismatched?
I'm trying to better understand JSONB functionality in sqlite so i replaced the 3.43 version on my mac by default with 3.45 from homebrew. but noticed some version mismatch the code I'm running using the bun:sqlite driver is console.log(db.all(sqlSELECT sqlite_version())) which returns 3.43 but as you can see below, in my terminal i have 3.45 installed. But i can't figure out why it's not working
which sqlite3
/opt/homebrew/opt/sqlite/bin/sqlite3

sqlite3 --version
3.45.2 2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77 (64-bit)
bun run src/scripts/save-jsonb.ts
[
{
version: "3.43.2",
}
]
which sqlite3
/opt/homebrew/opt/sqlite/bin/sqlite3

sqlite3 --version
3.45.2 2024-03-12 11:06:23 d8cd6d49b46a395b13955387d05e9e1a2a47e54fb99f3c9b59835bbefad6af77 (64-bit)
bun run src/scripts/save-jsonb.ts
[
{
version: "3.43.2",
}
]
sqlite3 src/db/db.db
SQLite version 3.45.2 2024-03-12 11:06:23
Enter ".help" for usage hints.
sqlite>
sqlite3 src/db/db.db
SQLite version 3.45.2 2024-03-12 11:06:23
Enter ".help" for usage hints.
sqlite>
when i go into the db from my project in vscode
1 replies
TtRPC
Created by DiamondDragon on 1/13/2024 in #❓-help
No typesafety after migrating to 11?
No description
16 replies
DTDrizzle Team
Created by DiamondDragon on 12/2/2023 in #help
createInsertSchema does not infer notNull() correclty?
"drizzle-orm": "^0.28.6", "drizzle-zod": "^0.5.1",
export const testTable = pgTable('accounts', {
id: varchar('id').primaryKey(),
optional: varchar('optional'),
notOptional: varchar('not_optional').notNull(),
unique: varchar('unique').unique().notNull(),
})

const testSchema = createInsertSchema(testTable)
type TestTypeWrong = z.infer<typeof testSchema>
type TestTypeCorrect = typeof testTable.$inferInsert
export const testTable = pgTable('accounts', {
id: varchar('id').primaryKey(),
optional: varchar('optional'),
notOptional: varchar('not_optional').notNull(),
unique: varchar('unique').unique().notNull(),
})

const testSchema = createInsertSchema(testTable)
type TestTypeWrong = z.infer<typeof testSchema>
type TestTypeCorrect = typeof testTable.$inferInsert
Results
type TestTypeWrong = {
id?: string;
optional?: string;
notOptional?: string;
unique?: string;
}
type TestTypeCorrect = {
id: string;
notOptional: string;
unique: string;
optional?: string;
}
type TestTypeWrong = {
id?: string;
optional?: string;
notOptional?: string;
unique?: string;
}
type TestTypeCorrect = {
id: string;
notOptional: string;
unique: string;
optional?: string;
}
2 replies
DTDrizzle Team
Created by DiamondDragon on 9/27/2023 in #help
Help with proper types (values)
No description
2 replies
DTDrizzle Team
Created by DiamondDragon on 9/23/2023 in #help
TypeError: client.unsafe is not a function
No description
7 replies
DTDrizzle Team
Created by DiamondDragon on 9/7/2023 in #help
No transactions support in neon-http driver even though neon provides a transaction function
https://neon.tech/docs/serverless/serverless-driver#when-to-use-the-neon-function-vs-pool-or-client I tried to execute a db operation such as below. I am getting throw new Error('No transactions support in neon-http driver'); I'm not sure if the kind of code below is an "interactive" or "non-interactive" transaction, but wondering if maybe I am missing something. Does drizzle support the neon(...) transaction() function?
await db.transaction(async tx => {
// Insert New Contact
const insertedContact = await tx
.insert(contacts)
.values(newContact)
.returning()
if (newEmails) {
// Take in array of email objects
for (const email of newEmails) {
// Insert or update New Email
const insertedEmail = await tx
.insert(emails)
.values(email)
.onConflictDoUpdate({ target: emails.emailId, set: email })
.returning({ id: emails.emailId })
// For each email, add relationship to join table
await tx.insert(emailsToContacts).values({
contactId: insertedContact[0].contactId,
emailId: insertedEmail[0].id,
})
}
}
await db.transaction(async tx => {
// Insert New Contact
const insertedContact = await tx
.insert(contacts)
.values(newContact)
.returning()
if (newEmails) {
// Take in array of email objects
for (const email of newEmails) {
// Insert or update New Email
const insertedEmail = await tx
.insert(emails)
.values(email)
.onConflictDoUpdate({ target: emails.emailId, set: email })
.returning({ id: emails.emailId })
// For each email, add relationship to join table
await tx.insert(emailsToContacts).values({
contactId: insertedContact[0].contactId,
emailId: insertedEmail[0].id,
})
}
}
19 replies
DTDrizzle Team
Created by DiamondDragon on 8/28/2023 in #help
Column Unique name appears to be incorrect when spreading common fields to multiple tables
No description
25 replies
DTDrizzle Team
Created by DiamondDragon on 8/23/2023 in #help
Check Constraint not working?
No description
3 replies
DTDrizzle Team
Created by DiamondDragon on 8/22/2023 in #help
Custom type not inferring correct zod schema?
No description
3 replies