Multi-database
A single Jsorm instance handles all databases. Routing is resolved by model.$$metadata.database.
Configuration
Section titled “Configuration”import { defineConfig } from "@jsorm/core";
export default defineConfig({ models: "src/models", databases: { main: { access: "server", provider: "sqlite-node", options: { database: "./main.db" }, }, cache: { access: "server", provider: "sqlite-node", options: { database: "./cache.db" }, }, },});Models per database
Section titled “Models per database”export const User = defineModel("users", { db: "main", fields: { /* ... */ },});
// src/models/cache/Session.tsexport const Session = defineModel("sessions", { db: "cache", fields: { /* ... */ },});import { jsorm, User, cache } from "./models/jsorm.server.js";
// User belongs to "main"await jsorm.users.get();
// Session belongs to "cache"await jsorm.cache.sessions.get();The client automatically resolves the correct provider for each model.
Module augmentation
Section titled “Module augmentation”The CLI generates types.d.ts with the JsormDatabases augmentation and the Models interface:
declare module "@jsorm/core" { interface JsormDatabases { main: DatabaseConfig; // always required cache: DatabaseConfig; // generated by CLI }}
interface Models { User: typeof import("./src/models/server/main/User").User; Session: typeof import("./src/models/server/cache/Session").Session;}main is always required in the base interface of @jsorm/core.
Why module augmentation for databases but not for models?
JsormDatabases is used to validate the db parameter in defineModel() — it needs to be available before models exist. Models are typed via ModelsTypes (generic in Jsorm<TModels>), not via module augmentation.
