@antelopejs/interface-database
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
Schemadeclares tables, fields and indexes. Each schema can hold several isolated instances.Table,SelectionandSingleSelectioninsert, read, update and delete documents.Streamfilters, maps, joins, groups and aggregates.ValueProxybuilds the expressions inside them.changes()streams inserts, updates and deletions as they happen.- Queries are lazy. Nothing runs until you
awaita 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.2.4 |
Contributing
Read CONTRIBUTING.md before you open a pull request. The local checks are:
pnpm install
pnpm lint
pnpm test