cityssm/parking-ticket-system

View on GitHub
database/parkingDB/getParkingLocation.js

Summary

Maintainability
A
0 mins
Test Coverage
B
85%
import sqlite from 'better-sqlite3';
import { parkingDB as databasePath } from '../../data/databasePaths.js';
export default function getParkingLocation(locationKey, connectedDatabase) {
    const database = connectedDatabase ?? sqlite(databasePath, { readonly: true });
    const location = database
        .prepare(`select locationKey, locationName, locationClassKey, isActive
        from ParkingLocations
        where locationKey = ?`)
        .get(locationKey);
    if (connectedDatabase === undefined) {
        database.close();
    }
    return location;
}