sqlite
This commit is contained in:
@@ -68,6 +68,7 @@ function parseDeliveryPayload(req) {
|
||||
name: f.originalname,
|
||||
content: f.buffer, // Raw Buffer directly accepted by libdashstore/attachments.js
|
||||
size: f.size,
|
||||
thumbavif: metaObj.thumbavif ?? null,
|
||||
meta: metaObj.meta ?? null,
|
||||
};
|
||||
});
|
||||
@@ -136,7 +137,7 @@ function logDeliveryFiles(files, label) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug logging: dump everything tedious/mssql puts on a SQL error.
|
||||
* Debug logging: dump everything the SQL driver puts on a SQL error.
|
||||
*/
|
||||
function logStoreError(label, error) {
|
||||
console.error(`[delivery diag] ${label} store error:`);
|
||||
|
||||
@@ -15,6 +15,10 @@ export default {
|
||||
googleClientId: process.env.GOOGLE_CLIENT_ID,
|
||||
implicitCreate: process.env.IMPLICIT_CREATE === 'true',
|
||||
jwtSecret: process.env.JWT_SECRET || 'fallback_secret_please_change_in_production',
|
||||
dbProvider: process.env.DB_PROVIDER || (process.env.SQLITE_PATH ? 'sqlite' : 'mssql'),
|
||||
sqlite: {
|
||||
filename: process.env.SQLITE_PATH || process.env.SQLITE_FILENAME || resolve(__dirname, '../../data/dash.db'),
|
||||
},
|
||||
mssql: {
|
||||
server: process.env.MSSQL_SERVER,
|
||||
database: process.env.MSSQL_DATABASE,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import chalk from 'chalk';
|
||||
import sql from 'mssql';
|
||||
import LibDashStore from 'libdashstore';
|
||||
import { MssqlProvider } from 'libdashstore/providers/mssql';
|
||||
import { BetterSqlite3Provider } from 'libdashstore/providers/better-sqlite3';
|
||||
import env from '../config/env.js';
|
||||
|
||||
let pool;
|
||||
let provider;
|
||||
let store;
|
||||
let connecting;
|
||||
|
||||
@@ -31,6 +31,7 @@ const STORE_NAMESPACES = [
|
||||
'numbers',
|
||||
'companysetting',
|
||||
'articlesupplier',
|
||||
'manifestattachment',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -119,10 +120,13 @@ export async function getStore() {
|
||||
|
||||
if (!connecting) {
|
||||
connecting = (async () => {
|
||||
pool = await new sql.ConnectionPool(getMssqlConfig()).connect();
|
||||
store = wrapStoreWithTiming(
|
||||
await new LibDashStore(new MssqlProvider(pool))
|
||||
);
|
||||
if (env.dbProvider === 'sqlite' || env.dbProvider === 'better-sqlite3') {
|
||||
provider = new BetterSqlite3Provider(env.sqlite);
|
||||
} else {
|
||||
provider = new MssqlProvider(getMssqlConfig());
|
||||
}
|
||||
await provider.initialize();
|
||||
store = wrapStoreWithTiming(await new LibDashStore(provider));
|
||||
return store;
|
||||
})().finally(() => {
|
||||
connecting = undefined;
|
||||
@@ -137,9 +141,9 @@ export async function ensureConnection() {
|
||||
}
|
||||
|
||||
export async function closeStore() {
|
||||
if (pool) {
|
||||
await pool.close();
|
||||
pool = undefined;
|
||||
if (provider) {
|
||||
await provider.close();
|
||||
provider = undefined;
|
||||
store = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Normalize mssql / Node binary values to a non-empty Buffer, or null.
|
||||
* Normalize SQL driver / Node binary values to a non-empty Buffer, or null.
|
||||
* @param {unknown} value
|
||||
* @returns {Buffer | null}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user