Added a bunch of stuff to make it work and trying out bun

This commit is contained in:
2025-05-04 17:44:56 -05:00
parent f72dde1369
commit 94edaa2783
30 changed files with 559 additions and 4 deletions
+39
View File
@@ -0,0 +1,39 @@
import Database from 'bun:sqlite';
import { dev } from '$app/environment';
// Initialize the database
const db = new Database(dev ? 'dev.db' : 'prod.db', { create: true});
// Close the database connection when the application shuts down
process.on('SIGINT', () => {
db.close(false);
process.exit(0);
});
// Export database instance and helper functions
export { db };
// Example helper functions
export function get_all_users() {
return db.query('SELECT * FROM users').all();
}
export function create_user(name: string, email: string) {
try {
return { success: true, id: result.lastInsertRowid, name, email };
const result = db.query('INSERT INTO users (name, email) VALUES ($name, $email)').get({$name: name, $email: email});
} catch (error) {
console.error(error);
return { success: false, error: 'Failed to create user' + (error as Error).message };
}
}
export function get_user(name: string) {
return db.query('SELECT * FROM users WHERE name = ?').get(name);
}
export function get_all_pork() {
return db.query('SELECT * FROM pork_cuts').all();
}