@antelopejs/interface-database-decorators
作为 TypeScript 类的数据库表格和数据模型, 在顶端 @antelopejs/interface-database。用装饰器宣布字段和索引,然后通过打入的模型读取并写入行.
部分 羚羊JS用于 羚羊JS 隐形物,用于您的 PostgreSQL 、 MongoDB 或 RethinkDB 数据库的开源后台.
它提供的东西
Table, (中文(简体) ),@RegisterTable, (中文(简体) ),@Field, (中文(简体) ),@Index财务报告和审定财务报表@Fixture声明表格、索引和种子行;RegisterSchema提供它们.BasicDataModel财务报告和审定财务报表GetModel给出每个表格键入的 CRUD 方法,并附带可选的验证.@Encrypted, (中文(简体) ),@Hashed, (中文(简体) ),@Localized, (中文(简体) ),@CreationTime财务报告和审定财务报表@UpdateTime转换写和读取的字段值.@Model将模型注入到@antelopejs/interface-api控制器。 控制器.
执行情况
软件包在您的模块中运行,没有自己的执行模块. 该项目需要一个模块来执行 @antelopejs/interface-database数字 :
| 模块 | 页:1 |
|---|---|
@antelopejs/mongodb | 蒙戈DB |
@antelopejs/rethinkdb | 反思DB |
安装
将软件包添加到宣布表格的模块中 :
pnpm add @antelopejs/interface-database-decorators
然后在项目中添加一个数据库模块:
ajs project modules add @antelopejs/mongodb
快开始
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 创建用于设置的每个表格,并插入其固定装置。 调用一次,在宣布表格的模块中.
文档
兼容性
软件包宣布这些 @antelopejs/* 相邻依赖性 :
| 软件包 | 支助 | 测试过 |
|---|---|---|
@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 |
捐款
读取 捐款额 在你打开拉动请求之前。 当地检查为:
pnpm install
pnpm lint
pnpm test