sunrise-cms/helpers/lotOccupancyDB/getPreviousMapId.ts

30 lines
602 B
TypeScript

import { acquireConnection } from './pool.js'
export async function getPreviousMapId(
mapId: number | string
): Promise<number | undefined> {
const database = await acquireConnection()
const result: {
mapId: number
} = database
.prepare(
`select mapId from Maps
where recordDelete_timeMillis is null
and mapName < (select mapName from Maps where mapId = ?)
order by mapName desc
limit 1`
)
.get(mapId)
database.release()
if (result === undefined) {
return undefined
}
return result.mapId
}
export default getPreviousMapId