Introduction
Introduction
Almost every real application needs a database. JCC Express MVC keeps this flexible by supporting:
- JCC ORM (default) for SQL with a Knex-backed query layer
- Sequelize as an alternative SQL ORM
- Mongoose for MongoDB document workflows
In practice, most projects start with the default JCC stack, then switch ORM mode only when needed.
Supported database engines
With the default JCC SQL path (DB_ORM=jcc), connection clients include:
mysql2postgressqlitebetter-sqlite3
For document databases, use DB_ORM=mongoose with your Mongo connection settings.
Configuration
Database settings live in your app config and environment values:
app/Config/database.tsapp/Config/index.ts(exportsdatabase).envvalues such asDB_ORM,DB_CONNECTION,DB_HOST,DB_PORT,DB_DATABASE,DB_USERNAME,DB_PASSWORD
Minimal shape from app/Config/database.ts:
SQLite configuration
For SQLite style connections (sqlite or better-sqlite3), the default JCC database layer resolves to a file database (db.sqlite) at project root.
Typical env setup:
If you need a different file location, align your adapter/config with your deployment path strategy.
Choosing ORM mode
The provider layer uses your env/config to decide connection behavior:
DB_ORM=jcc-> JCC/Knex SQL flowDB_ORM=sequelize-> Sequelize connection pathDB_ORM=mongoose-> Mongoose connection path
Keep DB_ORM and DB_CONNECTION consistent (for example, do not pair DB_ORM=mongoose with SQL-only assumptions in your app code).
Running queries
Query builder style
Raw SQL
Or:
Use bound parameters (?) instead of string interpolation to reduce SQL injection risk.
More method usage examples
Inserts
Updates
Deletes
Filtering and ordering
Column selection
Counting and aggregates
Pagination (offset/limit style)
Conditional create/update patterns
Raw expression inside builder
Transactions
JCC DB supports transaction wrappers:
Keep schema-altering or implicit-commit statements out of transactional write flows unless you fully understand your database engine behavior.
Migrations and seeders
Use ArtisanNode for schema and seed lifecycle:
Queue tables:
Practical recommendations
- Start with the default JCC stack unless a project requirement mandates Sequelize or Mongoose.
- Keep migrations in version control and run them in CI/CD.
- Prefer parameterized queries over manual string building.
- Validate production env values (
DB_ORM, credentials, host/port) early in deployment.
Summary
- JCC gives you one database entry point with multiple ORM backends.
- Config is env-driven and centered in
app/Config/database.ts. - Use
DB.table(...),DB.runQuery(...), and migrations/seeders for day-to-day database work.
