Database tables and data models as TypeScript classes for AntelopeJS. Declare fields and indexes with decorators, then read and write rows through a typed model.
Documentation · Implementations · All interfaces and providers
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.await row.setHashAsync(field, value)andawait row.testHashAsync(field, value)hash a password off the event loop. Use them on a server: assigning a@Hashedfield blocks the event loop for about 150 ms. See Table modifiers.@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.
The package declares these @antelopejs/* 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.4.0 |
@antelopejs/interface-database |
>=0.1.11 <1.0.0 |
0.3.0 |
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm testAntelopeJS is a TypeScript framework where modules depend on contracts and the application chooses the provider behind each one. AntelopeJS DMS, the open-source back office, is built on it.
| Area | Contracts | Providers |
|---|---|---|
| API | interface-api · interface-api-util · interface-data-api |
api |
| Auth | interface-auth |
auth-jwt |
| Database | interface-database · interface-database-decorators · interface-database-catalog · interface-mongodb · interface-rethinkdb |
postgres · mongodb · rethinkdb |
| Redis | interface-redis · interface-redis-scheduler |
redis |
interface-email |
nodemailer · brevo |
|
| File storage | interface-file-storage |
file-storage-local · file-storage-s3 |
| Payments | interface-payment · interface-subscriptions · interface-stripe |
stripe · mollie · checkout-com · payment-subscriptions |