const MatsushibaDB = require('matsushibadb');// Create databaseconst db = new MatsushibaDB('quickstart.db');// Create tabledb.run(` CREATE TABLE tasks ( id INTEGER PRIMARY KEY, title TEXT NOT NULL, completed BOOLEAN DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP )`);console.log('Database created successfully!');
// Get all tasksconst allTasks = db.all('SELECT * FROM tasks');console.log('All tasks:', allTasks);// Get incomplete tasksconst incompleteTasks = db.all('SELECT * FROM tasks WHERE completed = 0');console.log('Incomplete tasks:', incompleteTasks);// Get task countconst taskCount = db.get('SELECT COUNT(*) as count FROM tasks');console.log('Total tasks:', taskCount.count);
// Mark first task as completeddb.run('UPDATE tasks SET completed = 1 WHERE id = 1');// Delete completed tasksdb.run('DELETE FROM tasks WHERE completed = 1');console.log('Tasks updated and cleaned up!');
// Todo app with MatsushibaDBconst db = new MatsushibaDB('todo.db');// Create todos tabledb.run(` CREATE TABLE IF NOT EXISTS todos ( id INTEGER PRIMARY KEY, title TEXT NOT NULL, description TEXT, completed BOOLEAN DEFAULT 0, priority INTEGER DEFAULT 1, due_date DATETIME, created_at DATETIME DEFAULT CURRENT_TIMESTAMP )`);// Add todofunction addTodo(title, description = '', priority = 1, dueDate = null) { return db.run(` INSERT INTO todos (title, description, priority, due_date) VALUES (?, ?, ?, ?) `, [title, description, priority, dueDate]);}// Get todosfunction getTodos(completed = null) { let sql = 'SELECT * FROM todos'; let params = []; if (completed !== null) { sql += ' WHERE completed = ?'; params.push(completed); } sql += ' ORDER BY priority DESC, created_at DESC'; return db.all(sql, params);}// Toggle todo completionfunction toggleTodo(id) { db.run('UPDATE todos SET completed = NOT completed WHERE id = ?', [id]);}
Begin with basic operations and gradually add complexity.
2
Use Transactions
Wrap related operations in transactions for data consistency.
3
Handle Errors
Always implement proper error handling for database operations.
4
Optimize Queries
Use indexes and optimize queries as your data grows.
5
Monitor Performance
Track query performance and database health.
This quick start guide covers the basics. For production applications, be sure to implement proper security, error handling, and performance optimization. Check out our comprehensive guides for more advanced features!