Skip to content

Installation

  • Node.js 18 or higher
  • TypeScript 5.0 or higher (strict: true recommended)
  • pnpm, npm, or bun

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.

Terminal window
pnpm dlx jsorm@latest init
  1. Prompts for schema entry path — defaults to src/schema/index.ts

  2. Generates schema structure with an example User model:

    src/schema/main/user.ts
    src/schema/index.ts
  3. Prompts for adapter(s) — installs the adapter package and its driver peer dependency

  4. Provisions the Rust engine binary into node_modules/.jsorm/engine, verifies checksum and executable permissions

  5. Writes jsorm.config.ts — connection and migration sources inline, ready to edit

  6. Creates .env with a DATABASE_URL placeholder (if one doesn’t exist)

  7. Creates .migrations/schema.json — empty snapshot for migration generation

After init, your project has a central config file that both the runtime and CLI share:

// jsorm.config.ts
import { 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.

PackagePurposePeer dependency
jsormCore ORM, singleton runtime, config, migrations, CLI
jsorm-pgPostgreSQL adapterpg
jsorm-mysqlMySQL adaptermysql2
jsorm-sqliteSQLite adaptersqlite3

Only install adapters you actually use.

  1. JSORM_ENGINE_PATH environment variable
  2. node_modules/.jsorm/engine/jsorm-engine (.exe on Windows)
  3. 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 versions

Ensure your tsconfig.json includes:

{
"compilerOptions": {
"strict": true,
"target": "ES2020",
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}
  1. Always use pnpm dlx jsorm@latest init for new projects — it ensures engine and config are correctly wired.
  2. Keep DATABASE_URL and other credentials in .env, never committed to source.
  3. Use strict: true in tsconfig.json for full type inference.
  4. One jsorm.config.ts per project — used by both runtime and CLI.