Skip to main content

Getting Started with MatsushibaDB

Welcome to MatsushibaDB! This guide will help you get up and running quickly with your first database operations.

Prerequisites

Before you begin, ensure you have:
  • Node.js 16+ or Python 3.8+ (depending on your preferred platform)
  • Docker (optional, for containerized deployment)
  • Basic knowledge of databases and SQL

Installation Options

Choose your preferred installation method:

Quick Installation

Node.js (NPM)

npm install matsushibadb

Python (pip)

pip install matsushibadb

Docker

docker run -d -p 8000:8000 --name matsushiba-db matsushibadb/matsushibadb:latest

Your First Database

Let’s create your first database and perform some basic operations:
const MatsushibaDB = require('matsushibadb');

// Create a new database
const db = new MatsushibaDB('my-first-db.db');

// Create a table
db.run(`
  CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL,
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  )
`);

// Insert data
db.run('INSERT INTO users (name, email) VALUES (?, ?)', 
       ['John Doe', '[email protected]']);

// Query data
const users = db.all('SELECT * FROM users');
console.log('Users:', users);

// Close the database
db.close();

Understanding the Basics

Database Operations

MatsushibaDB supports all standard SQL operations:
  • CREATE: Create tables, indexes, and views
  • INSERT: Add new records
  • SELECT: Query data with complex conditions
  • UPDATE: Modify existing records
  • DELETE: Remove records
  • DROP: Remove tables and structures

Data Types

MatsushibaDB supports comprehensive data types:
  • INTEGER: Whole numbers
  • REAL: Floating-point numbers
  • TEXT: String data
  • BLOB: Binary data
  • DATETIME: Date and time values
  • JSON: Structured JSON data

Transactions

Ensure data consistency with transactions:
// Begin transaction
db.run('BEGIN TRANSACTION');

try {
  // Multiple operations
  db.run('INSERT INTO users (name, email) VALUES (?, ?)', 
         ['Alice', '[email protected]']);
  db.run('INSERT INTO users (name, email) VALUES (?, ?)', 
         ['Bob', '[email protected]']);
  
  // Commit if successful
  db.run('COMMIT');
} catch (error) {
  // Rollback on error
  db.run('ROLLBACK');
  throw error;
}

Next Steps

Now that you have the basics, explore these topics:

Common Patterns

Connection Management

// Single connection
const db = new MatsushibaDB('app.db');

// Connection pooling for production
const { MatsushibaPool } = require('matsushibadb');
const pool = new MatsushibaPool({
  database: 'app.db',
  min: 5,
  max: 20
});

// Use pool
const connection = await pool.acquire();
try {
  const result = connection.all('SELECT * FROM users');
  return result;
} finally {
  pool.release(connection);
}

Error Handling

try {
  const result = db.run('INSERT INTO users (name, email) VALUES (?, ?)', 
                        ['John', '[email protected]']);
  console.log('User created with ID:', result.lastInsertRowid);
} catch (error) {
  if (error.code === 'SQLITE_CONSTRAINT') {
    console.error('User with this email already exists');
  } else {
    console.error('Database error:', error.message);
  }
}

Best Practices

1

Use Prepared Statements

Always use parameterized queries to prevent SQL injection and improve performance.
2

Handle Errors Gracefully

Implement proper error handling for all database operations.
3

Use Transactions

Wrap related operations in transactions to maintain data consistency.
4

Optimize Queries

Use indexes and query optimization techniques for better performance.
5

Monitor Performance

Track query performance and database health metrics.

Need Help?

  • Documentation: Browse our comprehensive guides
  • Examples: Check out real-world examples
  • Community: Join our Discord server
  • Support: Get help from our support team
This is just the beginning! MatsushibaDB offers many advanced features including real-time capabilities, advanced security, and enterprise-grade monitoring. Explore our documentation to unlock its full potential.