basic stuff
This commit is contained in:
commit
6d36cb75ec
4 changed files with 78 additions and 0 deletions
25
db.js
Normal file
25
db.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
import sqlite3 from 'sqlite3'
|
||||
import { open } from 'sqlite'
|
||||
|
||||
let db;
|
||||
|
||||
const sql = `CREATE TABLE IF NOT EXISTS action (addr TEXT, action TEXT)`
|
||||
|
||||
async function initDb() {
|
||||
if (db) return db;
|
||||
|
||||
db = await open({
|
||||
filename: `${process.cwd()}/main.db`,
|
||||
driver: sqlite3.Database
|
||||
});
|
||||
|
||||
let sqlCmds = sql.split('\n');
|
||||
|
||||
for (let cmd of sqlCmds) {
|
||||
await db.run(cmd);
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
export { initDb };
|
Loading…
Add table
Add a link
Reference in a new issue