Installation
Prerequisites
Section titled “Prerequisites”- Node.js 18 or higher
- TypeScript 5.0 or higher (
strict: truerecommended) - pnpm, npm, or bun
Bootstrap with jsorm init
Section titled “Bootstrap with jsorm init”The recommended entry point for any new project is the interactive jsorm init command. It handles everything: adapter selection, package installation, engine binary provisioning, and config file generation.
pnpm dlx jsorm@latest initnpx jsorm@latest initbunx jsorm@latest init-
Prompts for schema entry path — defaults to
src/schema/index.ts -
Generates schema structure with an example
Usermodel:src/schema/main/user.tssrc/schema/index.ts -
Prompts for adapter(s) — installs the adapter package and its driver peer dependency
-
Provisions the Rust engine binary into
node_modules/.jsorm/engine, verifies checksum and executable permissions -
Writes
jsorm.config.ts— connection and migration sources inline, ready to edit -
Creates
.envwith aDATABASE_URLplaceholder (if one doesn’t exist) -
Creates
.migrations/schema.json— empty snapshot for migration generation
Generated jsorm.config.ts
Section titled “Generated jsorm.config.ts”After init, your project has a central config file that both the runtime and CLI share:
// jsorm.config.tsimport { defineConnectionSource, defineJsormConfig } from 'jsorm';import { pgAdapter } from 'jsorm-pg';
const main = defineConnectionSource({ adapter: pgAdapter({ name: 'main', connectionString: process.env.DATABASE_URL!, pool: { min: 2, max: 10 }, }),});
export default defineJsormConfig({ connectionSources: { main }, defaults: { connectionSource: 'main', },});The global jsorm singleton automatically lazy-loads this file from process.cwd() on first use.
Packages
Section titled “Packages”| Package | Purpose | Peer dependency |
|---|---|---|
jsorm | Core ORM, singleton runtime, config, migrations, CLI | — |
jsorm-pg | PostgreSQL adapter | pg |
jsorm-mysql | MySQL adapter | mysql2 |
jsorm-sqlite | SQLite adapter | sqlite3 |
Only install adapters you actually use.
Engine binary lookup order
Section titled “Engine binary lookup order”JSORM_ENGINE_PATHenvironment variablenode_modules/.jsorm/engine/jsorm-engine(.exeon Windows)- Legacy
.jsorm/bin/jsorm-engine
If the binary is missing or integrity check fails, jsorm throws a blocking error with an actionable message:
[JSORM ENGINE MISSING] Run: pnpx jsorm init[JSORM ENGINE INVALID] Integrity check failed[JSORM VERSION MISMATCH] Incompatible AST/Engine versionsEdge runtime note
Section titled “Edge runtime note”TypeScript configuration
Section titled “TypeScript configuration”Ensure your tsconfig.json includes:
{ "compilerOptions": { "strict": true, "target": "ES2020", "module": "NodeNext", "moduleResolution": "NodeNext" }}Best practices
Section titled “Best practices”- Always use
pnpm dlx jsorm@latest initfor new projects — it ensures engine and config are correctly wired. - Keep
DATABASE_URLand other credentials in.env, never committed to source. - Use
strict: trueintsconfig.jsonfor full type inference. - One
jsorm.config.tsper project — used by both runtime and CLI.