summaryrefslogtreecommitdiff
path: root/nodejs/database
diff options
context:
space:
mode:
authorJulien Dessaux2024-05-07 00:34:26 +0200
committerJulien Dessaux2024-05-07 00:34:26 +0200
commit1f6daef0180bc737a2883203f6d513e5b81712ed (patch)
tree6ec44d46114a7e3e7c0239395d623454ca2d43a4 /nodejs/database
parent[golang] bootstrapped a client in yet another language (diff)
downloadspacetraders-1f6daef0180bc737a2883203f6d513e5b81712ed.tar.gz
spacetraders-1f6daef0180bc737a2883203f6d513e5b81712ed.tar.bz2
spacetraders-1f6daef0180bc737a2883203f6d513e5b81712ed.zip
[node] improved sql migrations code
Diffstat (limited to '')
-rw-r--r--nodejs/database/db.ts8
1 files changed, 2 insertions, 6 deletions
diff --git a/nodejs/database/db.ts b/nodejs/database/db.ts
index 115d6a3..2fba09b 100644
--- a/nodejs/database/db.ts
+++ b/nodejs/database/db.ts
@@ -2,12 +2,6 @@ import fs from 'fs';
import path from 'path';
import Database from 'better-sqlite3';
-let allMigrations: Array<string> = [];
-fs.readdir('./database/', function(err, files) {
- if (err) throw err;
- allMigrations = files.filter(e => e.match(/\.sql$/)).map(e => path.join('./database', e));
-});
-
export type DbData = {data: string};
export const db = new Database(
@@ -18,6 +12,8 @@ db.pragma('foreign_keys = ON');
db.pragma('journal_mode = WAL');
function init(): void {
+ const filenames = fs.readdirSync('./database/');
+ const allMigrations = filenames.filter(e => e.match(/\.sql$/)).map(e => path.join('./database', e));
db.transaction(function migrate() {
let version;
try {