yeah
All checks were successful
Deploy App / build (push) Successful in 10s
Deploy App / deploy (push) Successful in 11s

This commit is contained in:
valere
2026-02-02 21:00:28 +01:00
parent e257e076c4
commit b9a3d0184f
98 changed files with 5068 additions and 3713 deletions

32
server/db/index.ts Normal file
View File

@@ -0,0 +1,32 @@
import { drizzle } from 'drizzle-orm/libsql'
import * as schema from './schema'
let _db: ReturnType<typeof drizzle> | null = null
export function useDB() {
if (_db) return _db
const config = useRuntimeConfig()
let dbPath = config.pathDb || process.env.PATH_DB
if (!dbPath) {
throw new Error('PATH_DB is not configured')
}
// Convertir le chemin en URL file:// si ce n'est pas déjà une URL
if (!dbPath.startsWith('file:') && !dbPath.startsWith('libsql:') && !dbPath.startsWith('http')) {
// Si c'est un chemin relatif, le rendre absolu
if (!dbPath.startsWith('/')) {
dbPath = `file:${process.cwd()}/${dbPath}`
} else {
dbPath = `file:${dbPath}`
}
}
console.log('🗄️ Connexion à la DB:', dbPath)
_db = drizzle(dbPath, { schema })
return _db
}
export { schema }