mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 22:34:56 +00:00
Fix DBAL Prisma adapter to handle undefined dialect and use SQLite adapter as fallback
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -11,28 +11,24 @@ export function createPrismaContext(
|
|||||||
|
|
||||||
let prisma: PrismaClient
|
let prisma: PrismaClient
|
||||||
|
|
||||||
// For SQLite, we need to use the driver adapter
|
// For SQLite (or when dialect cannot be inferred), we need to use the driver adapter
|
||||||
if (inferredDialect === 'sqlite') {
|
if (inferredDialect === 'sqlite' || !databaseUrl || inferredDialect === undefined) {
|
||||||
const dbPath = databaseUrl?.replace('file:', '') || '../../prisma/prisma/dev.db'
|
const dbPath = databaseUrl?.replace('file:', '').replace('sqlite://', '') || '../../prisma/prisma/dev.db'
|
||||||
const db = new Database(dbPath)
|
const db = new Database(dbPath)
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||||
const adapter = new PrismaBetterSqlite3(db)
|
const adapter = new PrismaBetterSqlite3(db)
|
||||||
prisma = new PrismaClient({ adapter } as any)
|
prisma = new PrismaClient({ adapter } as any)
|
||||||
} else {
|
} else {
|
||||||
// For other databases, use the URL directly
|
// For PostgreSQL/MySQL with explicit connection strings
|
||||||
prisma = new PrismaClient(
|
// Note: Prisma 7 removed datasources config, so this may not work
|
||||||
databaseUrl
|
// Consider using adapters for all database types
|
||||||
? {
|
throw new Error(`Prisma 7 requires adapters. Unsupported database dialect: ${inferredDialect}. Please use SQLite or implement adapters for other databases.`)
|
||||||
datasources: { db: { url: databaseUrl } },
|
|
||||||
} as any
|
|
||||||
: undefined
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
prisma,
|
prisma,
|
||||||
queryTimeout: options?.queryTimeout ?? 30000,
|
queryTimeout: options?.queryTimeout ?? 30000,
|
||||||
dialect: inferredDialect ?? 'generic'
|
dialect: inferredDialect ?? 'sqlite'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user