Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/db.server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { drizzle, type PostgresJsDatabase } from 'drizzle-orm/postgres-js'
import postgres, { type Sql } from 'postgres'
import invariant from 'tiny-invariant'
import * as schema from './db/schema'
import { relations } from './db/relations'

let drizzleClient: PostgresJsDatabase<typeof schema>
let drizzleClient: PostgresJsDatabase<typeof relations>
let pg: Sql<any>
declare global {
var __db__:
| {
drizzle: PostgresJsDatabase<typeof schema>
drizzle: PostgresJsDatabase<typeof relations>
pg: Sql<any>
}
| undefined
Expand Down Expand Up @@ -39,7 +39,7 @@ function initClient() {
max: maxConnections,
})

const drizzleDb = drizzle(rawPg, { schema })
const drizzleDb = drizzle({ client: rawPg, relations })

return { drizzle: drizzleDb, pg: rawPg }
}
Expand All @@ -57,3 +57,6 @@ function parsePoolSize(value: string | undefined): number {
}

export { drizzleClient, pg }
export type DrizzleTransaction = Parameters<
Parameters<typeof drizzleClient.transaction>[0]
>[0]
Loading
Loading