/** * db * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * @link https://gitea.node001.net/HerrHase/urban-bucket.git * */ import { Database } from 'bun:sqlite' function getOrCreateSqlite(options = {}): Database { let db // check version for merge options // safeIntegers only aviable in version >= 1.1.14 if (Bun.version < '1.1.14') { options = Object.assign({ uri: process.env.NANO_SQLITE_PATH, wal: true }, options) } else { options = Object.assign({ uri: process.env.NANO_SQLITE_PATH, wal: true, safeIntegers: true }, options) } const uri = options.uri delete options.uri const wal = options.wal delete options.wal // if (Object.keys(options).length === 0) { db = new Database(uri) } else { db = new Database(uri, options) } if (wal) { db.exec('PRAGMA journal_mode = WAL;') } return db } export default getOrCreateSqlite