Skip to content

Latest commit

 

History

History
129 lines (88 loc) · 10.5 KB

README.md

File metadata and controls

129 lines (88 loc) · 10.5 KB

INTERFACE · DATABASE: part of AntelopeJS, hexagonal architecture beyond your own code. A glowing button reads Star AntelopeJS.

@antelopejs/interface-database

npm License Discord Docs Star AntelopeJS

AQL, the AntelopeJS database query builder. Write a typed query once and run it on the database module your project loads.

Documentation · Implementations · All interfaces and providers

AQL (Antelope Query Language) is the database-agnostic query builder of AntelopeJS. You write a chainable, typed query once, and any database module that implements the interface runs it.

What it offers

  • Schema declares tables, fields and indexes. Each schema can hold several isolated instances.
  • Table, Selection and SingleSelection insert, read, update and delete documents.
  • Stream filters, maps, joins, groups and aggregates. ValueProxy builds the expressions inside them.
  • changes() streams inserts, updates and deletions as they happen.
  • Queries are lazy. Nothing runs until you await a query, call .run() or iterate it.

Implementations

Module Notes
@antelopejs/mongodb MongoDB. Also implements @antelopejs/interface-mongodb.
@antelopejs/rethinkdb RethinkDB. Also implements @antelopejs/interface-rethinkdb.

Install

Add the interface to the module that runs queries:

pnpm add @antelopejs/interface-database

Then add an implementation to the project:

ajs project modules add @antelopejs/mongodb

Quick start

import { Schema } from "@antelopejs/interface-database";

interface Novel {
  _id?: string;
  title: string;
  pageCount: number;
}

const schema = new Schema<{ novels: Novel }>("library", {
  novels: {
    fields: { title: "string", pageCount: "number" },
    indexes: { pageCount: {} },
  },
});

const novels = schema.instance().table("novels");

export async function addNovel(title: string, pageCount: number) {
  return await novels.insert({ title, pageCount });
}

export async function listLongNovels() {
  return await novels
    .filter((novel) => novel.key("pageCount").ge(300))
    .orderBy("pageCount", "desc");
}

Callbacks such as the filter above receive a ValueProxy, not a document. The callback runs once, when the query is built, and the query records only the ValueProxy calls it makes.

Documentation

Compatibility

The package declares this @antelopejs/* peer dependency:

Package Supported Tested with
@antelopejs/interface-core >=0.2.4 <1.0.0 0.4.0

Contributing

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

pnpm install
pnpm lint
pnpm test

Part of AntelopeJS

AntelopeJS 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
Email 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

License

Apache-2.0