img2db/database.ts

26 lines
586 B
TypeScript
Raw Permalink Normal View History

2024-04-04 01:18:32 +00:00
import { Database } from "bun:sqlite";
// all of these do the same thing
const db = new Database("mydb.sqlite");
createTable();
function createTable() {
db.run(`
CREATE TABLE IF NOT EXISTS images (
id INTEGER PRIMARY KEY AUTOINCREMENT,
image BLOB,
type TEXT
);
`);
}
export const query_getImages = db.query(`SELECT id, type FROM images`);
export const query_getImage = db.query(
`SELECT image, type FROM images WHERE id = $id`,
);
export const query_saveImage = db.query(
`INSERT INTO images (image, type) VALUES ($image, $type) RETURNING id`,
);