Database tables and data models as TypeScript classes, on top of @antelopejs/interface-database: declare fields and indexes with decorators, then read and write rows through a typed model.
Table,@RegisterTable,@Field,@Indexand@Fixturedeclare tables, indexes and seed rows;RegisterSchemaprovisions them.BasicDataModelandGetModelgive each table typed CRUD methods with optional validation.@Encrypted,@Hashed,@Localized,@CreationTimeand@UpdateTimetransform field values on write and read.@Modelinjects a model into an@antelopejs/interface-apicontroller.
The package runs in your module and has no implementing module of its own. The project needs a module that implements @antelopejs/interface-database:
| Module | Notes |
|---|---|
@antelopejs/mongodb |
MongoDB |
@antelopejs/rethinkdb |
RethinkDB |
Add the package to the module that declares tables:
pnpm add @antelopejs/interface-database-decoratorsThen add a database module to the project:
ajs project modules add @antelopejs/mongodbimport {
BasicDataModel,
Field,
GetModel,
Index,
RegisterSchema,
RegisterTable,
Table,
} from "@antelopejs/interface-database-decorators";
@RegisterTable("recipes", "cookbook")
class Recipe extends Table {
@Index()
@Field("string")
declare slug: string;
@Field("string")
declare tagline: string;
}
class RecipeModel extends BasicDataModel(Recipe) {}
export async function construct() {
await RegisterSchema("cookbook");
}
export async function start() {
const recipes = GetModel(RecipeModel);
await recipes.insert({ slug: "grilled-halloumi", tagline: "Smoky skewers" });
const [recipe] = await recipes.getBy("slug", "grilled-halloumi");
await recipes.update(recipe._id, { tagline: "Smoky halloumi skewers" });
}RegisterSchema creates every table registered for the schema and inserts their fixtures. Call it once, in the module that declares the tables.
Requires AntelopeJS core 1.x and the following peer dependencies:
| Package | Supported | Tested with |
|---|---|---|
@antelopejs/interface-api |
>=0.0.15 <1.0.0 |
0.0.15 |
@antelopejs/interface-core |
>=0.2.4 <1.0.0 |
0.2.4 |
@antelopejs/interface-database |
>=0.1.11 <1.0.0 |
0.1.11 |
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm test