This commit is contained in:
seb
2026-09-22 07:25:16 +02:00
parent 4ed6260e91
commit cca131d83a
148 changed files with 5343 additions and 3466 deletions

View File

@@ -133,8 +133,12 @@ export class MssqlProvider {
const tx = pool.transaction();
await tx.begin();
try {
const runner = this.makeExecutor(() => tx.request());
const result = await fn(runner);
const executor = this.makeExecutor(() => tx.request());
const runner = async (sql, params) => executor.query(sql, params);
runner.query = runner;
runner.exec = (proc, opts) => executor.exec(proc, opts);
runner.dialect = 'mssql';
const result = await fn(runner, tx);
await tx.commit();
return result;
} catch (err) {
@@ -148,17 +152,32 @@ export class MssqlProvider {
}
async initialize() {
// Implemented by store/initialize.js — no-op here (keeps parity with
// other providers, which may run migrations internally instead).
const pool = await this.ensurePool();
const { SCHEMA_SCRIPTS } = await import('./schema.js');
for (const script of SCHEMA_SCRIPTS) {
if (script && script.trim()) {
await pool.request().query(script);
}
}
}
async purge() {
// Implemented by store/purge.js — no-op here.
const pool = await this.ensurePool();
const { buildPurgeSql } = await import('./purgeSql.js');
await pool.request().query(buildPurgeSql());
}
close() {
return this.pool ? this.pool.close() : Promise.resolve();
}
isUniqueConstraintError(err) {
return isUniqueConstraintError(err);
}
isForeignKeyConstraintError(err) {
return isForeignKeyConstraintError(err);
}
}
/** mssql: 2627 = PK/unique violation, 2601 = unique index violation */

View File

@@ -44,3 +44,14 @@ OUTPUT INSERTED.id, INSERTED.[type], INSERTED.prefix, INSERTED.padding, INSERTED
WHERE id = @id
AND company_id = @companyId
`;
export const GET_FOR_UPDATE = `
SELECT id, [type], prefix, padding, [next] AS [next]
FROM numbers WITH (UPDLOCK, ROWLOCK)
WHERE company_id = @companyId AND [type] = @type;
`;
export const INCREMENT = `
UPDATE numbers SET [next] = [next] + 1 WHERE id = @id;
`;