The database package exposes an Active Record-style Model base class and a chainable ModelQueryBuilder. The canonical table property in the inspected source is static table, not static tableName.
Define a model#
import { Model } from "@veap/database";
export class Article extends Model {
static table = "articles";
static fillable = ["title", "slug", "body"];
declare title: string;
declare slug: string;
declare body: string;
}The model base class supports configurable primary keys, automatic UUID generation, timestamp columns, casts, soft deletes, hidden attributes, fillable/guarded mass assignment, and global scopes. Declare the database schema with migrations; a model declaration does not create the table by itself.
Create and query records#
const article = await Article.create({
title: "First article",
slug: "first-article",
body: "Hello from Veap",
});
const found = await Article.query()
.where("slug", "first-article")
.first();
if (found) {
found.title = "Updated title";
await found.save();
}Model exposes static helpers including query(), find(), findOrFail(), all(), count(), where(), create(), forceCreate(), firstOrCreate(), firstOrNew(), updateOrCreate(), withTrashed(), and onlyTrashed(). Confirm exact argument and return types in the installed declaration files before relying on a helper in a public library.
Mass assignment#
Use fillable or guarded deliberately when accepting data from request boundaries. forceCreate() intentionally bypasses mass-assignment restrictions; never pass an unvalidated request object to it.
Query builder#
const results = await Article.query()
.where("publishedAt", "<=", new Date())
.orderBy("createdAt", "desc")
.limit(20)
.get();The query builder converts camelCase column names to snake_case for selected helpers and delegates methods that exist on the underlying Knex query builder. The exact methods available through delegation depend on Knex and should not be mistaken for a separately stable Veap API.
Serialization and casts#
hidden controls which attributes are omitted from toJSON(). casts configures supported attribute conversions; use the cast types exported by the installed version. Verify date/time and JSON semantics with integration tests against the actual database driver.
Soft deletes#
Set static softDeletes = true and ensure the table has the configured deleted-at column. Queries normally exclude deleted records; withTrashed() includes them and onlyTrashed() restricts results to deleted rows. Use these helpers only when the schema and application lifecycle support soft deletion.