Data & ORM
StreetJS talks to PostgreSQL over a native wire driver — no pg, no Prisma. Use the built-in repository pattern for direct, typed data access, or add @streetjs/orm for entity decorators, relations, and model-driven migrations.
Why a native data layer
Third-party ORMs add a heavy dependency, a query engine you don’t control, and an abstraction that often leaks at exactly the wrong moment. StreetJS implements the PostgreSQL wire protocol itself and exposes two layers of data access on top of it — so you can start with plain typed repositories and adopt entity mapping only when a richer domain model earns it. Either way, queries stay parameterized and the dependency footprint stays small.
What’s included
Native PostgreSQL driver
A from-scratch implementation of the PostgreSQL wire protocol with connection pooling — parameterized queries, no pg dependency.
Repository pattern
Typed repositories for CRUD and custom queries, with parameter binding handled for you. The fastest path to data access.
Repository docs →Entity decorators & relations
@Entity, @Column, @HasMany, @HasOne, @BelongsTo, @ManyToMany with eager (batched, N+1-safe) and lazy loading.
Model-driven migrations
Diff entity metadata against the live schema to generate idempotent up/down SQL. Additive by default; opt in to column drops.
npm →@streetjs/orm is a 0.x preview. Relations, eager/lazy loading, querying, and model-driven migration generation are implemented and tested (offline plus live PostgreSQL in CI). The native driver and repositories are stable and shipped in the core framework.
Example
Define entities with decorators; the query planner keeps everything parameterized:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import 'reflect-metadata';
import { Entity, PrimaryKey, Column, HasMany, BelongsTo } from '@streetjs/orm';
@Entity('users')
class User {
@PrimaryKey() id!: number;
@Column() email!: string;
@HasMany(() => Post, 'authorId') posts?: Post[];
}
@Entity('posts')
class Post {
@PrimaryKey() id!: number;
@Column() authorId!: number;
@Column() published!: boolean;
@BelongsTo(() => User, 'authorId') author?: User;
}
Need a different store? First-party plugins cover MySQL, MongoDB, Redis, and Supabase. See the Plugins page.
Next steps
- Read the Database guide
- Learn the repository pattern
- Install
@streetjs/orm