title="…" adds a filename bar, {3,5-7} highlights those lines, andshowLineNumbers adds a gutter. Every block gets a Copy button.import { Prorm, DataTypes } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: ':memory:' });
const User = db.define('User', {
id: { type: DataTypes.INTEGER(), primaryKey: true, autoIncrement: true },
email: { type: DataTypes.STRING(255), allowNull: false, unique: true },
});
export { db, User };```ts title="src/models/user.ts" {3,5-7} showLineNumbers
import { Prorm, DataTypes } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: ':memory:' });
const User = db.define('User', {
id: { type: DataTypes.INTEGER(), primaryKey: true, autoIncrement: true },
email: { type: DataTypes.STRING(255), allowNull: false, unique: true },
});
export { db, User };
```{1}, {2-4},{1,3,6-8}. The checker reports a range past the end of its block.console, shell-session and sh blocks render as a terminal. A line that$ is a command and the rest is output. The prompt is drawn by\ continues on the next line. An sh block with no$ lines is treated as all commands.$ npm install ts-prorm-orm better-sqlite3
added 3 packages in 2s
$ npx orm-cli migrate \
--config prorm.config.json
Applied 2 migrations.```console title="Create the schema"
$ npm install ts-prorm-orm better-sqlite3
added 3 packages in 2s
$ npx orm-cli migrate \
--config prorm.config.json
Applied 2 migrations.
```bash for a script that a reader saves to a file, not for a session theydiff block colours + and - lines. diff-<lang> also highlights the const db = new Prorm({
- dialect: 'sqlite',
- storage: ':memory:',
+ dialect: 'postgres',
+ host: 'localhost',
+ database: 'app',
});```diff-ts title="src/db.ts"
const db = new Prorm({
- dialect: 'sqlite',
- storage: ':memory:',
+ dialect: 'postgres',
+ host: 'localhost',
+ database: 'app',
});
```+, - or a space. A plain diff block is shown asgit diff with its @@ hunks works too.tree block renders a project layout. Indent two spaces per level, end a/, and put a comment after #, with a space before it.src/
models/
user.ts # the User model
post.ts
migrations/
001-init.ts # run by `orm-cli migrate`
index.ts
prorm.config.json```tree
src/
models/
user.ts # the User model
post.ts
migrations/
001-init.ts # run by `orm-cli migrate`
index.ts
prorm.config.json
```ts and typescript block is compiled against src/ byscripts/check-docs-snippets.mjs. That includes blocks inside tabs, steps and<details>, and ones with meta after the language. Use the real exported APIs<!-- snippet:skip --> on the line before its fence. Use it rarely:Note:, Tip:, Warning:, Danger: or Deprecated:, still works.[!NOTE]
Useful information a reader should know, even when skimming.
[!TIP] Faster startups
Keep oneProrminstance per process; its pool is the expensive part.
[!IMPORTANT]
Key information a reader needs to succeed.
[!WARNING] sync({ force: true })drops the table first.
[!CAUTION]
This deletes production data and can't be undone.
Deprecated: the queryoption ofcreateMaterializedView(). Passdefinitioninstead.
> [!NOTE]
> Useful information a reader should know, even when skimming.
> [!TIP] Faster startups
> Keep one `Prorm` instance per process; its pool is the expensive part.
> [!IMPORTANT]
> Key information a reader needs to succeed.
> [!WARNING]
> `sync({ force: true })` drops the table first.
> [!CAUTION]
> This deletes production data and can't be undone.
> **Deprecated:** the `query` option of `createMaterializedView()`. Pass `definition` instead.import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'postgres', host: 'localhost', database: 'app', username: 'app' });import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'mysql', host: 'localhost', database: 'app', username: 'app' });import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: 'app.db' });<!-- tabs -->
<!-- tab: PostgreSQL -->
```ts
import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'postgres', host: 'localhost', database: 'app', username: 'app' });
```
<!-- tab: MySQL -->
```ts
import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'mysql', host: 'localhost', database: 'app', username: 'app' });
```
<!-- tab: SQLite -->
SQLite needs no server; a file path is the whole configuration.
```ts
import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: 'app.db' });
```
<!-- /tabs -->5432 unless you set port.3306 unless you set port.storage is a file path, or ':memory:'.<!-- tabs sync="pm" -->. Named groups sync only with groups of the same$ npm install ts-prorm-orm$ pnpm add ts-prorm-orm$ yarn add ts-prorm-orm$ bun add ts-prorm-orm### heading inside becomes a numbered step on$ npm install ts-prorm-orm better-sqlite3import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: ':memory:' });
await db.connect();import { Prorm, DataTypes } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: ':memory:' });
const User = db.define('User', {
id: { type: DataTypes.INTEGER(), primaryKey: true, autoIncrement: true },
name: { type: DataTypes.STRING(100), allowNull: false },
});
await db.sync();<!-- steps -->
### Install the package
```console
$ npm install ts-prorm-orm better-sqlite3
```
### Connect
```ts
import { Prorm } from 'ts-prorm-orm';
const db = new Prorm({ dialect: 'sqlite', storage: ':memory:' });
await db.connect();
```
### Define a model and create its table
```ts
…
```
<!-- /steps -->{icon:name} adds an icon.database, code, book, rocket, shield,lock, key, terminal, gear, bolt, search, layers, cloud,chart, plug, users, file, diagram, check and globe. An unknown<!-- cards -->
- {icon:database} [Models](models.md) — Define tables as classes.
- {icon:search} [Querying](querying.md) — Filter, sort and paginate.
- {icon:layers} [Migrations](migrations.md) — Change the schema safely.
<!-- /cards --><details> element for material most readers can skip. Leave a<summary> so the content inside is read as Markdown, and a</details> before whatever follows it: until a blank line,Prorm instance owns its connection pool. Two instances against the same<details>
<summary>Why is the pool per process?</summary>
Each `Prorm` instance owns its connection pool. Two instances against the same
database hold two pools, which doubles the connections the server has to
keep open.
</details><!-- badge: … --> line directly after a heading puts a small badge on thatv4.9 is blue, and deprecated and experimental<kbd>.query option#### Streaming reads
<!-- badge: v4.9 -->
<!-- badge: experimental -->
#### The `query` option
<!-- badge: deprecated -->
Press <kbd>Ctrl</kbd> + <kbd>K</kbd> to search.mermaid block. Prefer flowchart, sequenceDiagram,stateDiagram-v2, erDiagram, classDiagram, gantt and pie. Quote aA["text (x)"]. Labels can't contain```mermaid
flowchart LR
A["Model.findAll()"] --> B["Query builder"]
B --> C{"Dialect"}
C -->|postgres| D["SQL + RETURNING"]
C -->|sqlite| E["SQL"]
```| Option | Type | Default | Meaning |
|---|---|---|---|
dialect | string | (required) | Which database to talk to. |
storage | string | — | SQLite only: a file path, or ':memory:'. |
pool.max | number | 10 | The most connections the pool opens. |
<!-- tabs -->, a<!-- tab X --> without its colon, a badge that doesn't follow a heading, a$ node scripts/check-docs-links.mjs
$ node scripts/check-docs-snippets.mjs docs/guides/writing-docs.mdts example must compile against src/. Use the real exporteddocs/guides/klock-errors.md, and any<!-- generated -->.