refactor: introduce database provider abstraction, isolate MSSQL layer
- Add provider contract (src/providers/provider.js): query() -> {rows,
rowsAffected, insertId}, callback transaction(fn), exec() for stored
procs, initialize/purge lifecycle
- Add MssqlProvider (src/providers/mssql/index.js) wrapping an mssql
ConnectionPool with normalized results, tx commit/rollback and
constraint-error classifiers (unique 2627/2601, FK 547)
- LibDashStore constructor now takes a provider instead of a pool
(breaking); adds LibDashStore.create() async factory; keeps pool as
transitional bridge until store modules are converted (see TODO.md)
- Move MSSQL-specific code into the provider: src/sql/* ->
src/providers/mssql/queries/*, src/schema.js ->
src/providers/mssql/schema.js, purge SQL -> purgeSql.js
- Update scripts, generate-schema-graph.js and package.json exports
(./providers/mssql, ./providers/provider)
- Add TODO.md with the remaining provider/SQLite migration plan
No SQL or behavioral changes.
This commit is contained in:
30
src/index.js
30
src/index.js
@@ -123,7 +123,24 @@ import manifestattachmentGetById from './store/manifestattachment/getById.js';
|
||||
import manifestattachmentOrder from './store/manifestattachment/order.js';
|
||||
|
||||
export default class LibDashStore {
|
||||
constructor(pool) {
|
||||
/**
|
||||
* @param {import('./providers/provider.js').DatabaseProvider} provider
|
||||
*/
|
||||
constructor(provider) {
|
||||
if (
|
||||
!provider ||
|
||||
typeof provider.query !== 'function' ||
|
||||
typeof provider.transaction !== 'function'
|
||||
) {
|
||||
throw new TypeError(
|
||||
'LibDashStore requires a database provider (query/transaction/initialize/purge).',
|
||||
);
|
||||
}
|
||||
|
||||
this.provider = provider;
|
||||
// Transitional: store modules still use the raw mssql pool.
|
||||
// They are converted to provider.query() area by area (see TODO.md).
|
||||
const pool = provider.pool;
|
||||
this.pool = pool;
|
||||
|
||||
this.companyuser = {
|
||||
@@ -317,11 +334,16 @@ export default class LibDashStore {
|
||||
order: manifestattachmentOrder(pool),
|
||||
};
|
||||
|
||||
this.purge = storePurge(pool);
|
||||
this.initialize = storeInitialize(pool);
|
||||
this.purge = storePurge(provider);
|
||||
this.initialize = storeInitialize(provider);
|
||||
|
||||
return this.initialize().then(() => this);
|
||||
}
|
||||
|
||||
/** Recommended async factory (constructor returning a promise is confusing). */
|
||||
static async create(provider) {
|
||||
return new LibDashStore(provider);
|
||||
}
|
||||
}
|
||||
|
||||
export { SCHEMA_SCRIPTS } from './schema.js';
|
||||
export { SCHEMA_SCRIPTS } from './providers/mssql/schema.js';
|
||||
|
||||
Reference in New Issue
Block a user