sunrise-cms/database/getNextContractId.js

17 lines
505 B
JavaScript

import sqlite from 'better-sqlite3';
import { sunriseDB } from '../helpers/database.helpers.js';
export default function getNextContractId(contractId) {
const database = sqlite(sunriseDB, { readonly: true });
const result = database
.prepare(`select contractId
from Contracts
where recordDelete_timeMillis is null
and contractId > ?
order by contractId
limit 1`)
.pluck()
.get(contractId);
database.close();
return result;
}