Update
This commit is contained in:
1 parent
911dcace72
commit
9c68c414d8
53 files changed
+2919
-469
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { mkdirSync } from 'node:fs'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { TABLE_DEFINITIONS } from './db/tableRegistry'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const dbPath = join(__dirname, 'data', 'assignment-monitor.sqlite3')
|
||||
mkdirSync(dirname(dbPath), { recursive: true })
|
||||
|
||||
export const db = new DatabaseSync(dbPath)
|
||||
|
||||
for (const table of TABLE_DEFINITIONS) {
|
||||
const columnsSql = table.columns.map(c => `"${c.name}" ${c.sqlType}`).join(', ')
|
||||
db.exec(`CREATE TABLE IF NOT EXISTS "${table.name}" (id INTEGER PRIMARY KEY AUTOINCREMENT, ${columnsSql})`)
|
||||
}
|
||||
|
||||
console.log(`[db] SQLite bereit unter ${dbPath}`)
|
||||
Reference in new issue
Block a user