JCC Express

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:

  • mysql2
  • postgres
  • sqlite
  • better-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.ts
  • app/Config/index.ts (exports database)
  • .env values such as DB_ORM, DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD

Minimal shape from app/Config/database.ts:

TypeScript

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:

env

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 flow
  • DB_ORM=sequelize -> Sequelize connection path
  • DB_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

TypeScript

Raw SQL

TypeScript

Or:

TypeScript

Use bound parameters (?) instead of string interpolation to reduce SQL injection risk.


More method usage examples

Inserts

TypeScript

Updates

TypeScript

Deletes

TypeScript

Filtering and ordering

TypeScript

Column selection

TypeScript

Counting and aggregates

TypeScript

Pagination (offset/limit style)

TypeScript

Conditional create/update patterns

TypeScript

Raw expression inside builder

TypeScript

Transactions

JCC DB supports transaction wrappers:

TypeScript

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:

Bash

Queue tables:

Bash

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.