Braveheart
Braveheart
Explore posts from servers
DTDrizzle Team
Created by Braveheart on 1/10/2024 in #help
Temporal custom type "TypeError: SQLite3 can only bind numbers, strings, bigints, buffers, and nul"
No description
3 replies
DTDrizzle Team
Created by Braveheart on 1/3/2024 in #help
Performing Drizzle ORM migration in vitest results in permission errors
In a test i'm using Drizzle ORM to do migrations in vitest beforeAll, but it doesn't work like when I run a script from
"db:migrate": "tsx db/migrate.ts", //runs with no issues
"db:migrate": "tsx db/migrate.ts", //runs with no issues
which then calls this
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}
import { migrate } from 'drizzle-orm/better-sqlite3/migrator'
import { db } from './db'

import { fileURLToPath } from 'url'
import { dirname, join } from 'path'

export const migrateWrapper = async () => {
await migrate(db, { migrationsFolder: migrationsPath }) // does the actual migration
}
but when running in a test file I get root cause error:
// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
await resetDatabase() //includes the migration call
await seedRecurringEvents()
})
// console.log('yearly-recurring-events.test.ts')
beforeAll(async () => {
await resetDatabase() //includes the migration call
await seedRecurringEvents()
})
Caused by: SqliteError: disk I/O error
❯ PreparedQuery.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/better-sqlite3/session.ts:103:20
❯ BetterSQLiteSession.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/session.ts:140:67
❯ SQLiteSyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/dialect.ts:721:11
.
.
Caused by: SqliteError: disk I/O error
❯ PreparedQuery.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/better-sqlite3/session.ts:103:20
❯ BetterSQLiteSession.run node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/session.ts:140:67
❯ SQLiteSyncDialect.migrate node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/src/sqlite-core/dialect.ts:721:11
.
.
and then results in
Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
'
Migrating the database...

stderr | Module.migrateWrapper (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/db/migrateUtil.ts:19:13)
Failed to migrate the database: DrizzleError: Failed to run the query '
CREATE TABLE IF NOT EXISTS "__drizzle_migrations" (
id SERIAL PRIMARY KEY,
hash text NOT NULL,
created_at numeric
)
'
1 replies
DTDrizzle Team
Created by Braveheart on 12/29/2023 in #help
Extract type from drizzle join for use elsewhere or exporting
I get the type in the same function scope like so
let query = db
.select()
.from(schema.event)
.where(and(...filters))
.leftJoin(schema.recurring_pattern, eq(schema.event.id, schema.recurring_pattern.event_id))

const eventRecurringPatterns = await query.execute()
let query = db
.select()
.from(schema.event)
.where(and(...filters))
.leftJoin(schema.recurring_pattern, eq(schema.event.id, schema.recurring_pattern.event_id))

const eventRecurringPatterns = await query.execute()
eventRecurringPatterns is typed with {event ,recurring_pattern} but how do I extract this type for use in other function params? Maybe with Parameters<typeof theJoin> I want to avoid doing it manually I imagine it starts something like this screenshot
3 replies
DTDrizzle Team
Created by Braveheart on 12/27/2023 in #help
disk I/O error when running migration in context of vitest runner
I'm building a robust drizzle event selector https://github.com/quantuminformation/drizzle-sqlite-recurring-events In my test suite I am doing this:
7 replies
DTDrizzle Team
Created by Braveheart on 12/26/2023 in #help
inferSelect doesnt take into account defaults in schema
No description
13 replies
DTDrizzle Team
Created by Braveheart on 12/26/2023 in #help
value.getTime is not a function
this code in this basic repo https://github.com/quantuminformation/drizzle-sqlite-recurring-events when running pnpm run db:seed gives error
//https://github.com/quantuminformation/drizzle-sqlite-recurring-events/blob/main/db/seed.ts
const events = await db
.insert(schema.event)
.values([
{
name: 'Event 1',
startTime: new Date(2025, 1, 1, 19, 0, 0).getTime(),
endTime: new Date(2025, 1, 1, 20, 0, 0).getTime(),
},
])
.returning()
//https://github.com/quantuminformation/drizzle-sqlite-recurring-events/blob/main/db/seed.ts
const events = await db
.insert(schema.event)
.values([
{
name: 'Event 1',
startTime: new Date(2025, 1, 1, 19, 0, 0).getTime(),
endTime: new Date(2025, 1, 1, 20, 0, 0).getTime(),
},
])
.returning()
TypeError: value.getTime is not a function
at SQLiteTimestamp.mapToDriverValue (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/node_modules/.pnpm/[email protected][email protected]/node_modules/src/sqlite-core/columns/integer.ts:150:22)
TypeError: value.getTime is not a function
at SQLiteTimestamp.mapToDriverValue (/Users/nikos/WebstormProjects/drizzle-sqlite-recurring-events/node_modules/.pnpm/[email protected][email protected]/node_modules/src/sqlite-core/columns/integer.ts:150:22)
you can see that getTime works when debugging in vscode so I don't know where this error originates
3 replies
DTDrizzle Team
Created by Braveheart on 11/25/2023 in #help
Steps to fix errors like `drizzle/meta/0000_snapshot.json data is malformed`
No description
1 replies