You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
630 B
22 lines
630 B
import { drizzle } from 'drizzle-orm/libsql';
|
|
import path from 'path';
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
// 打包时需要保证migrator被引入
|
|
import('drizzle-orm/better-sqlite3/migrator')
|
|
}
|
|
|
|
const tempCwd = path.resolve(process.cwd(), 'packages/drizzle-pkg');
|
|
|
|
let dbUrl = process.env.DATABASE_URL;
|
|
if (dbUrl && dbUrl.startsWith('file:')) {
|
|
let filePath = dbUrl.slice(5);
|
|
if (!path.isAbsolute(filePath)) {
|
|
filePath = path.resolve(tempCwd, filePath);
|
|
process.env.DATABASE_URL = 'file:' + filePath;
|
|
}
|
|
}
|
|
|
|
const _db = drizzle(process.env.DATABASE_URL!);
|
|
|
|
export { _db as dbGlobal }
|