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:
69
src/providers/mssql/queries/company.js
Normal file
69
src/providers/mssql/queries/company.js
Normal file
@@ -0,0 +1,69 @@
|
||||
export const GET_BY_NAME = `
|
||||
SELECT id, name, root_category_id, default_language_id, taxrate, reducedtaxrate, taxfreerate
|
||||
FROM company
|
||||
WHERE name = @name
|
||||
`;
|
||||
|
||||
export const GET_BY_ID = `
|
||||
SELECT id, name, root_category_id, default_language_id, taxrate, reducedtaxrate, taxfreerate
|
||||
FROM company
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const GET_COMPANY_ROOT_CATEGORY = `
|
||||
SELECT root_category_id AS rootCategoryId FROM company WHERE id = @companyId
|
||||
`;
|
||||
|
||||
export const CREATE = `
|
||||
INSERT INTO company (
|
||||
name,
|
||||
root_category_id,
|
||||
default_language_id,
|
||||
taxrate,
|
||||
reducedtaxrate,
|
||||
taxfreerate,
|
||||
poscustomergroup_id
|
||||
)
|
||||
OUTPUT INSERTED.id
|
||||
VALUES (
|
||||
@name,
|
||||
@rootCategoryId,
|
||||
@languageId,
|
||||
@taxrate,
|
||||
@reducedtaxrate,
|
||||
@taxfreerate,
|
||||
@posCustomerGroupId
|
||||
)
|
||||
`;
|
||||
|
||||
export const UPDATE = `
|
||||
UPDATE company
|
||||
SET
|
||||
name = @name,
|
||||
default_language_id = @languageId,
|
||||
taxrate = @taxrate,
|
||||
reducedtaxrate = @reducedtaxrate
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const LIST = `
|
||||
SELECT
|
||||
c.id,
|
||||
c.name,
|
||||
c.root_category_id AS rootCategoryId,
|
||||
c.default_language_id AS languageId,
|
||||
tr.rate AS taxrate,
|
||||
rtr.rate AS reducedtaxrate,
|
||||
tfr.rate AS taxfreerate
|
||||
FROM company c
|
||||
INNER JOIN companyuser cu ON cu.company_id = c.id
|
||||
LEFT JOIN tax tr ON tr.id = c.taxrate
|
||||
LEFT JOIN tax rtr ON rtr.id = c.reducedtaxrate
|
||||
LEFT JOIN tax tfr ON tfr.id = c.taxfreerate
|
||||
WHERE cu.google_auth_id = @googleAuthId
|
||||
`;
|
||||
|
||||
export const DELETE = `
|
||||
DELETE FROM company
|
||||
WHERE id = @companyId
|
||||
`;
|
||||
Reference in New Issue
Block a user