sqlite
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user