Skip to content

About

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.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

2 watching

Forks

Latest commit

 

History

80 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@antelopejs/interface-database-decorators

npm License Discord Docs

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.

What it offers

  • Table, @RegisterTable, @Field, @Index and @Fixture declare tables, indexes and seed rows; RegisterSchema provisions them.
  • BasicDataModel and GetModel give each table typed CRUD methods with optional validation.
  • @Encrypted, @Hashed, @Localized, @CreationTime and @UpdateTime transform field values on write and read.
  • @Model injects a model into an @antelopejs/interface-api controller.

Implementations

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

Install

Add the package to the module that declares tables:

pnpm add @antelopejs/interface-database-decorators

Then add a database module to the project:

ajs project modules add @antelopejs/mongodb

Quick start

import {
  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.

Documentation

Compatibility

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

Contributing

Read CONTRIBUTING.md before you open a pull request. The local checks are:

pnpm install
pnpm lint
pnpm test

License

Apache-2.0

About

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.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages