Skip to main content

title: Quick Start description: Start with model + migration + seed in one pass.

Quick Start

Version: 1.1.4

Quick setup

Install the package, Express.js, and the minimum TypeScript tooling first:
npm install @alpha.consultings/eloquent-orm.js express
npm install -D typescript ts-node @types/express @types/node
dotenv and @faker-js/faker are already included by the package runtime. Install them separately only if your own app imports them directly:
npm install dotenv @faker-js/faker
Set one active app connection and one active test connection in .env. Do not place multiple connection names in DB_CONNECTION. Quick .env key list:
  • DB_CONNECTION
  • DB_TEST_CONNECTION
  • DB_* or PG_* or SQLITE_* or MONGO_*
Minimal SQLite .env:
DB_CONNECTION=sqlite
DB_TEST_CONNECTION=sqlite_test
SQLITE_PATH=./storage/app.sqlite
SQLITE_TEST_PATH=./storage/app.test.sqlite
eloquent make:model Post --with-migration
eloquent make:service Post
eloquent make:controller Post
This creates:
  • src/app/models/Post.ts
  • src/app/services/PostService.ts
  • src/app/controllers/PostController.ts
  • a migration file for your configured target

Runtime setup

This ORM is compatible with Express.js and is typically used in Express route handlers. In this setup, registerModels runs safely at startup and models work without integration issues.
  1. Ensure model registration is completed at app bootstrap.
import { registerModels } from "@alpha.consultings/eloquent-orm.js";
import { User } from "./app/models/User";
import { Post } from "./app/models/Post";

registerModels([User, Post]);
  1. Generate and apply migrations in order.
eloquent make:migration --all
eloquent migrate:run --test --all-migrations
  1. Seed test fixtures and run a demo scenario.
eloquent db:seed --test --class BlogScenarioSeeder
eloquent demo:scenario --test --random
  1. Create, query, update, and delete records.
const created = await Post.create({ title: "Hello ORM JS" });
const found = await Post.find(created.id as number);

if (found) {
  found.update({ title: "Hello ORM JS Updated" });
  await found.save();
}

await Post.deleteById(created.id as number);
  1. If the model uses soft deletes, restore instead of recreating.
const deleted = await Post.find(1);
if (deleted) {
  await deleted.restore();
}

Next steps