26 lines
586 B
TypeScript
26 lines
586 B
TypeScript
|
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`,
|
||
|
);
|