Understanding Database Basics
Before diving into IlanaORM, letβs understand some key concepts:What is a Database?
What is a Database?
A database is like a digital filing cabinet that stores information in an organized way. Instead of paper files, it stores data in tables.
What are Tables?
What are 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
What is an ORM?
What is an ORM?
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 runningnpx 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 shelvesseeds/- The initial books you put on shelvesfactories/- 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
Yourilana.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
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
