Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/db/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function generateDatabaseSchema(nuxt: Nuxt, hub: ResolvedHubConfig) {
}

async function setupDatabaseClient(nuxt: Nuxt, hub: ResolvedHubConfig) {
const { driver, connection } = hub.db as ResolvedDatabaseConfig
const { dialect, driver, connection, mode } = hub.db as ResolvedDatabaseConfig

// For types, d1-http uses sqlite-proxy
const driverForTypes = driver === 'd1-http' ? 'sqlite-proxy' : driver
Expand Down Expand Up @@ -236,10 +236,11 @@ declare module 'hub:db' {
// Setup Drizzle ORM

// Generate simplified drizzle() implementation
const modeOption = dialect === 'mysql' ? `, mode: '${mode || 'default'}'` : ''
let drizzleOrmContent = `import { drizzle } from 'drizzle-orm/${driver}'
import * as schema from './db/schema.mjs'

const db = drizzle({ connection: ${JSON.stringify(connection)}, schema })
const db = drizzle({ connection: ${JSON.stringify(connection)}, schema${modeOption} })
export { db, schema }
`

Expand Down Expand Up @@ -368,7 +369,7 @@ function getDb() {
if (!_db) {
const hyperdrive = process.env.${bindingName} || globalThis.__env__?.${bindingName} || globalThis.${bindingName}
if (!hyperdrive) throw new Error('${bindingName} binding not found')
_db = drizzle({ connection: hyperdrive.connectionString, schema })
_db = drizzle({ connection: hyperdrive.connectionString, schema${modeOption} })
}
return _db
}
Expand Down
8 changes: 8 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ export type DatabaseConfig = {
* @default true
*/
applyMigrationsDuringBuild?: boolean
/**
* MySQL mode for Drizzle ORM relational queries.
* Only applicable when dialect is 'mysql'.
*
* @default 'default'
* @see https://orm.drizzle.team/docs/rqb#modes
*/
mode?: 'default' | 'planetscale'
}

export type ResolvedDatabaseConfig = DatabaseConfig & {
Expand Down
Loading