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:
46
src/providers/mssql/queries/numbers.js
Normal file
46
src/providers/mssql/queries/numbers.js
Normal file
@@ -0,0 +1,46 @@
|
||||
export const ENSURE_TYPE = `
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM numbers
|
||||
WHERE company_id = @companyId AND [type] = @type
|
||||
)
|
||||
BEGIN
|
||||
INSERT INTO numbers (company_id, [type])
|
||||
VALUES (@companyId, @type);
|
||||
END
|
||||
`;
|
||||
|
||||
export const LIST_BY_COMPANY = `
|
||||
SELECT
|
||||
id,
|
||||
[type],
|
||||
prefix,
|
||||
padding,
|
||||
[next] AS [next]
|
||||
FROM numbers
|
||||
WHERE company_id = @companyId
|
||||
ORDER BY [type]
|
||||
`;
|
||||
|
||||
export const GET_BY_COMPANY_AND_ID = `
|
||||
SELECT
|
||||
id,
|
||||
[type],
|
||||
prefix,
|
||||
padding,
|
||||
[next] AS [next]
|
||||
FROM numbers
|
||||
WHERE id = @id
|
||||
AND company_id = @companyId
|
||||
`;
|
||||
|
||||
export const UPDATE_BY_COMPANY_AND_ID = `
|
||||
UPDATE numbers
|
||||
SET
|
||||
prefix = @prefix,
|
||||
padding = @padding,
|
||||
[next] = @next
|
||||
OUTPUT INSERTED.id, INSERTED.[type], INSERTED.prefix, INSERTED.padding, INSERTED.[next]
|
||||
WHERE id = @id
|
||||
AND company_id = @companyId
|
||||
`;
|
||||
Reference in New Issue
Block a user