@omitdb / @omitjson / @omitmigrate
Three annotations that control whether a field is stored, serialized, or managed by the migrator.
Reference
| Annotation | Stored in DB | Returned in reads | Managed by migrator |
|---|---|---|---|
@omitdb | No (excluded from INSERT SET, no column) | No | N/A |
@omitjson | Yes | No (unless explicitly .select()ed) | Yes |
@omitmigrate | Depends on manual DDL | Yes | No (skips column in CREATE/ALTER) |
@omitdb — No Database Column
The field exists only at the type level. It's excluded from INSERT SET clauses and never stored. Useful for computed fields, transient data, or columns managed externally.
src/interfaces.ts
// @omitdb
internalNote?: string; // TS-only field
const user = await User.insert({
name: "Alice",
internalNote: "secret",
});
console.log(user.internalNote); // undefined (excluded from insert)
// The column does NOT exist in the database table@omitjson — Strip from Reads
The field IS stored in the database but stripped from all read results unless explicitly selected. Useful for internal audit data, system fields, or values only needed for backend processing.
src/interfaces.ts
// @omitjson
auditData?: string; // stored but hidden from reads
const user = await User.insert({ name: "Alice", auditData: "created-by-admin" });
console.log(user.auditData); // undefined (stripped)
// Explicit .select() returns it:
const withAudit = await User.query()
.select("name", "auditData")
.where("name", "=", "Alice")
.get();
console.log(withAudit[0].auditData); // "created-by-admin"
// Raw SQL confirms it's stored:
const raw = await orm.execRaw("SELECT auditData FROM users WHERE name = ?", ["Alice"]);
console.log(raw.rows[0].auditData); // "created-by-admin"@omitmigrate — Skip Migrator
The migrator ignores this column during migrate() — it won't create, alter, or drop it. You manage the DDL manually. The field is still usable in queries.
src/interfaces.ts
// @omitmigrate
tempField?: string; // manual DDL only
// After migrate(), no column exists for tempField.
// You must CREATE it manually:
await orm.execRaw("ALTER TABLE users ADD COLUMN tempField TEXT");Errors
| Issue | Cause | Fix |
|---|---|---|
| @omitdb field visible in query result | Misconfiguration or cache | Regenerate schema and verify the annotation is on the correct field |
| @omitmigrate column created by migrate() | The migrator version may not support @omitmigrate | Update to SlintORM v1.5+ |
Conventions
@omitdbis for fields that should never touch the database (computed, transient, external-managed)@omitjsonis for fields that live in the DB but should be hidden from API responses@omitmigrateis for legacy columns or DB-native features (triggers, generated columns)@secretinternally applies@omitjson— you don't need both