-
-
Save allohamora/79082dc60059b599120a058fcfa10235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Database } from "sqlite3"; | |
class DatabaseHelper { | |
constructor(private database: Database) {} | |
public async query ( | |
parts: string[], | |
...params: any[] | |
): Promise<sqlite3.RunResult> { | |
const sql = parts.join("?"); | |
return new Promise((resolve, reject) => { | |
this.database.run(sql, params, function (err) { | |
if (err) return reject(err); | |
resolve(this); | |
}); | |
}); | |
} | |
} | |
const db = new DatabaseHelper(new Database("./db.sqlite")); | |
const { lastID } = await db.query` | |
INSERT INTO reminders | |
(author_id, iso8601, text) | |
VALUES | |
(${author_id}, ${iso8601}, ${text}); | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment