Skip to main content

Understanding Database Basics

Before diving into IlanaORM, let’s understand some key concepts:
A database is like a digital filing cabinet that stores information in an organized way. Instead of paper files, it stores data in tables.
Tables are like spreadsheets with rows and columns:
  • Columns define what type of information you store (name, email, age)
  • Rows contain the actual data for each record
ORM stands for Object-Relational Mapping. It’s a tool that lets you work with database data using regular JavaScript objects instead of writing SQL queries.Without ORM (SQL):
With ORM (JavaScript):

Project Structure

After running npx ilana setup, your project will have this structure:
Think of it like organizing a library:
  • models/ - The catalog system (how you find books)
  • migrations/ - The blueprints for building shelves
  • seeds/ - The initial books you put on shelves
  • factories/ - The system for generating fake books for testing

Environment Setup

1. Environment Variables

Create a .env file in your project root:
.env

2. Configuration File

Your ilana.config.js should load environment variables:
ilana.config.js

Development Workflow

1. Plan Your Data Structure

Before coding, think about what data you need:

2. Create Models and Migrations

3. Define Your Database Schema

Edit the migration files to define your table structure:
create_users_table.js

4. Run Migrations

5. Create Seeders (Optional)

Generate sample data for development:
UserSeeder.js
Run seeders:

Development Best Practices

1. Use Descriptive Names

2. Define Relationships Early

3. Use Factories for Testing

UserFactory.js

4. Handle Errors Gracefully

Common Development Commands

Debugging Tips

1. Enable Query Logging

ilana.config.js

2. Check Migration Status

3. Inspect Your Database

For SQLite, you can use tools like:

Next Steps

Learn Models

Understand how to define and use models

Database Configuration

Advanced configuration options
Pro Tip: Start with SQLite for development. It’s file-based, requires no setup, and you can easily reset it by deleting the .sqlite file.