Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM node:20-alpine AS builder
FROM node:24-alpine AS builder
WORKDIR /app
COPY package*.json package-lock.json* ./
RUN --mount=type=cache,target=/root/.npm npm ci
COPY . .
RUN npm run build && npm run build:backend

FROM node:20-alpine AS runner
FROM node:24-alpine AS runner
WORKDIR /app
RUN apk add --no-cache ca-certificates wget
COPY package*.json package-lock.json* ./
Expand Down
52 changes: 17 additions & 35 deletions addon/lib/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Pool } = require('pg');
const sqlite3 = require('sqlite3').verbose();
const { DatabaseSync } = require('node:sqlite');
const path = require('path');
const fs = require('fs');
const crypto = require('crypto');
Expand Down Expand Up @@ -76,21 +76,16 @@ class Database {
fs.mkdirSync(dir, { recursive: true });
}

this.db = new sqlite3.Database(fullPath);
this.db = new DatabaseSync(fullPath);
this.type = 'sqlite';

return new Promise((resolve, reject) => {
this.db.serialize(() => {
this.db.run('PRAGMA foreign_keys = ON');
this.db.run('PRAGMA journal_mode = WAL');
this.db.run('PRAGMA busy_timeout = 5000');
this.db.run('PRAGMA synchronous = NORMAL');
this.db.run('PRAGMA cache_size = 10000');
this.db.run('PRAGMA temp_store = MEMORY');
this.db.run('PRAGMA mmap_size = 268435456'); // 256MB
resolve();
});
});
this.db.exec('PRAGMA foreign_keys = ON');
this.db.exec('PRAGMA journal_mode = WAL');
this.db.exec('PRAGMA busy_timeout = 5000');
this.db.exec('PRAGMA synchronous = NORMAL');
this.db.exec('PRAGMA cache_size = 10000');
this.db.exec('PRAGMA temp_store = MEMORY');
this.db.exec('PRAGMA mmap_size = 268435456');
}

async initializePostgreSQL(uri) {
Expand Down Expand Up @@ -215,12 +210,9 @@ class Database {
}

if (this.type === 'sqlite') {
return new Promise((resolve, reject) => {
this.db.run(query, params, function(err) {
if (err) reject(err);
else resolve({ lastID: this.lastID, changes: this.changes });
});
});
const stmt = this.db.prepare(query);
const result = stmt.run(...params);
return { lastID: result.lastInsertRowid, changes: result.changes };
} else {
const result = await this.db.query(query, params);
return result;
Expand All @@ -233,12 +225,8 @@ class Database {
}

if (this.type === 'sqlite') {
return new Promise((resolve, reject) => {
this.db.get(query, params, (err, row) => {
if (err) reject(err);
else resolve(row);
});
});
const stmt = this.db.prepare(query);
return stmt.get(...params) ?? null;
} else {
const result = await this.db.query(query, params);
return result.rows[0] || null;
Expand All @@ -251,12 +239,8 @@ class Database {
}

if (this.type === 'sqlite') {
return new Promise((resolve, reject) => {
this.db.all(query, params, (err, rows) => {
if (err) reject(err);
else resolve(rows);
});
});
const stmt = this.db.prepare(query);
return stmt.all(...params);
} else {
const result = await this.db.query(query, params);
return result.rows;
Expand Down Expand Up @@ -629,9 +613,7 @@ class Database {
async close() {
if (this.db) {
if (this.type === 'sqlite') {
return new Promise((resolve) => {
this.db.close(resolve);
});
this.db.close()
} else {
await this.db.end();
}
Expand Down
Loading