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:

TypeDescription
autoAuto-incrementing ID
strString
intInteger
numNumber (float)
boolBoolean
timestampISO timestamp
enumEnumerated values

Modifiers

ModifierDescription
requiredField must be present
optionalField is optional
uniqueValue must be unique
default(val)Default value
min(n)Minimum value or length
max(n)Maximum value or length
emailEmail format validation
pattern("regex")Regex validation

CRUD Routes

crud "/api/users" User generates:

MethodPathAction
GET/api/usersList all
GET/api/users/:idGet by ID
POST/api/usersCreate
PUT/api/users/:idUpdate
DELETE/api/users/:idDelete

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.