Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
DbContext
✓ import { DbContext } from 'linkgress-orm'
✗ const { DbContext } = require('linkgress-orm')
Package is ESM-only; CommonJS require is not supported.
DbEntity
✓ import { DbEntity } from 'linkgress-orm'
✗ import { DbEntity } from 'linkgress-orm/src/DbEntity'
All exports are at the package root; do not use deep imports as they are not part of the public API.
DbColumn
✓ import { DbColumn } from 'linkgress-orm'
✗ import DbColumn from 'linkgress-orm'
DbColumn is a named export, not a default export.
integer
✓ import { integer } from 'linkgress-orm'
✗ import { Integer } from 'linkgress-orm'
Type helpers are lowercase and exported as functions.
varchar
✓ import { varchar } from 'linkgress-orm'
Define entities, configure DbContext with relationships, then execute a query with filtering and ordering.
import { DbContext, DbEntity, DbColumn, DbEntityTable, DbModelConfig, integer, varchar } from 'linkgress-orm';
import postgres from 'postgres';
const sql = postgres('postgres://user:pass@localhost:5432/mydb');
class User extends DbEntity {
id!: DbColumn<number>;
username!: DbColumn<string>;
email!: DbColumn<string>;
posts?: Post[];
}
class Post extends DbEntity {
id!: DbColumn<number>;
title!: DbColumn<string>;
userId!: DbColumn<number>;
user?: User;
}
class AppDatabase extends DbContext {
get users(): DbEntityTable<User> {
return this.table(User);
}
get posts(): DbEntityTable<Post> {
return this.table(Post);
}
protected override setupModel(model: DbModelConfig): void {
model.entity(User, entity => {
entity.toTable('users');
entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'users_id_seq' }));
entity.property(e => e.username).hasType(varchar('username', 100)).isRequired();
entity.property(e => e.email).hasType(varchar('email', 255)).isRequired();
entity.hasMany(e => e.posts, () => Post).withForeignKey(p => p.userId).withPrincipalKey(u => u.id);
});
model.entity(Post, entity => {
entity.toTable('posts');
entity.property(e => e.id).hasType(integer('id').primaryKey().generatedAlwaysAsIdentity({ name: 'posts_id_seq' }));
entity.property(e => e.title).hasType(varchar('title', 200)).isRequired();
entity.property(e => e.userId).hasType(integer('user_id'));
entity.belongsTo(e => e.user, () => User).withForeignKey(p => p.userId).withPrincipalKey(u => u.id);
});
}
}
async function main() {
const db = new AppDatabase(sql);
const users = await db.users.select().where(u => u.username.like('john%')).orderBy(u => u.id.asc()).execute();
console.log(users);
}
main().catch(console.error);
Errors
Common errors & fixes
TypeError: postgres is not a function
Importing `postgres` incorrectly: the package exports a default function, not a named export.
fixUse `import postgres from 'postgres';` (default import) not `import { postgres } from 'postgres'`. Cannot find module 'linkgress-orm' or its corresponding type declarations.
TypeScript is unable to resolve the package because `skipLibCheck` is false and type roots not configured.
fixEnsure `skipLibCheck: true` in tsconfig.json, or add the package to `types`.
Property 'users' does not exist on type 'AppDatabase'.
The getter `users` is not defined or returns `void` instead of `DbEntityTable<User>`.
fixEnsure the getter returns `this.table(User);` with proper type annotation.
Expected 1 argument, but got 0.
Calling `db.users.select()` without required arguments? Actually `select()` can be empty; this error may occur with `update()` or `delete()` without conditions.
fixFor `update()` and `delete()`, ensure you use `.where()` first or provide conditions.
Query failed: relation "users" does not exist
The database table name does not match the entity configuration, or migration hasn't been run.
fixUse `entity.toTable('users')` to map to the correct table name, or run migrations to create the table. Audit
Dependencies
pgoptionalPostgreSQL client driver required for database connectivity
postgresoptionalAlternative PostgreSQL client driver