generated from hyper63/adapter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
38 lines (33 loc) · 921 Bytes
/
mod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { DB, join } from './deps.js'
import adapter from './adapter.js'
import PORT_NAME from './port_name.js'
export default (args = { dir: '.', name: 'hyper-queue.db' }) => ({
id: 'queue',
port: PORT_NAME,
load: () => {
// allow passing a string or object with { dir } field
let file
if (typeof args === 'string') {
file = args
} else if (typeof args === 'object') {
const dir = args.dir || '.'
const name = args.name || 'hyper-queue.db'
file = join(dir, name)
}
if (!file || typeof file !== 'string') {
throw new Error('{ dir, name } or path to file required')
}
const db = new DB(file)
addEventListener('unload', () => {
if (db) {
try {
db.close(true)
} catch (e) {
console.log(e)
}
}
})
return { db } // load env
},
link: (env) => (_) => adapter(env), // link adapter
})