You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
750 B
42 lines
750 B
/**
|
|
* db
|
|
*
|
|
* @author Björn Hase <me@herr-hase.wtf>
|
|
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
|
|
* @link https://git.node001.net/HerrHase/signpost.git
|
|
*
|
|
*/
|
|
|
|
import Database from 'better-sqlite3'
|
|
|
|
function getOrCreateSqlite(options = {}) {
|
|
|
|
let db
|
|
|
|
options = Object.assign({
|
|
uri: process.env.NANO_SQLITE_PATH,
|
|
wal: 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.pragma('journal_mode = WAL')
|
|
}
|
|
|
|
return db
|
|
}
|
|
|
|
export default getOrCreateSqlite
|