Database
NAIDE supports JSON file storage, SQLite, and PostgreSQL out of the box.
JSON File Store
Zero-dependency file-based storage, great for prototyping:
db "data/"
schema User:
id auto
name str required min(2)
email str required email
server app port 3000:
crud "/api/users" User
This creates a data/ directory with JSON files for each schema. CRUD routes are auto-generated.
SQLite
Production-ready embedded database:
db.sql "sqlite" "app.db"
schema Todo:
id auto
title str required
done bool default(false)
created_at timestamp
server app port 3000:
crud "/api/todos" Todo
Uses better-sqlite3 under the hood with WAL mode for concurrent access.
PostgreSQL
db.sql "postgres" "postgresql://localhost/mydb"
schema Product:
id auto
name str required
price num required min(0)
in_stock bool default(true)
Schema Definitions
Schemas define structure, validation, and auto-generate CRUD operations:
| Type | Description |
|---|---|
auto | Auto-incrementing ID |
str | String |
int | Integer |
num | Number (float) |
bool | Boolean |
timestamp | ISO timestamp |
enum | Enumerated values |
Modifiers
| Modifier | Description |
|---|---|
required | Field must be present |
optional | Field is optional |
unique | Value must be unique |
default(val) | Default value |
min(n) | Minimum value or length |
max(n) | Maximum value or length |
email | Email format validation |
pattern("regex") | Regex validation |
CRUD Routes
crud "/api/users" User generates:
| Method | Path | Action |
|---|---|---|
| GET | /api/users | List all |
| GET | /api/users/:id | Get by ID |
| POST | /api/users | Create |
| PUT | /api/users/:id | Update |
| DELETE | /api/users/:id | Delete |
Schema Migration
When your schema changes, NAIDE can auto-migrate the database:
schema User v2:
id auto
name str required min(2)
email str required email
role str default("user") # new field
The version tag triggers automatic migration for file-based and SQLite stores.