diff --git a/docs/1.introduction.md b/docs/1.introduction.md index 72211bf..4505cd1 100644 --- a/docs/1.introduction.md +++ b/docs/1.introduction.md @@ -45,6 +45,7 @@ import { } from "@antelopejs/interface-data-api/metadata"; import { BasicDataModel, + Field, Index, Model, RegisterTable, @@ -55,12 +56,17 @@ import { @RegisterTable("users") class User extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; @Index() + @Field("string") declare email: string; + @Field("string") declare name: string; + + @Field("string") declare password: string; } diff --git a/docs/10.joined.md b/docs/10.joined.md index 49a513b..d7b5071 100644 --- a/docs/10.joined.md +++ b/docs/10.joined.md @@ -13,25 +13,34 @@ Apply `@Joined` to a field that should be populated from a remote table. The loc ```typescript import { Joined } from "@antelopejs/interface-data-api/metadata"; import { + Field, Index, RegisterTable, + Relation, Table, } from "@antelopejs/interface-database-decorators"; @RegisterTable("users") class User extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") declare name: string; } @RegisterTable("orders") class Order extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") + @Relation({ to: () => User }) declare userId: string; + + @Field("number") declare total: number; } diff --git a/docs/11.computed.md b/docs/11.computed.md index 61b06bf..9ff7242 100644 --- a/docs/11.computed.md +++ b/docs/11.computed.md @@ -15,15 +15,21 @@ import { Computed } from "@antelopejs/interface-data-api/metadata"; @RegisterTable("groups") class Group extends Table { + @Field("string") declare _id: string; + + @Field("string") declare name: string; } @RegisterTable("devices") class Device extends Table { + @Field("string") declare _id: string; @Index() + @Field("string") + @Relation({ to: () => Group }) declare group_id: string; } diff --git a/docs/2.data-controllers.md b/docs/2.data-controllers.md index 2626c90..fd54e72 100644 --- a/docs/2.data-controllers.md +++ b/docs/2.data-controllers.md @@ -23,6 +23,7 @@ import { } from "@antelopejs/interface-data-api/metadata"; import { BasicDataModel, + Field, Index, Model, RegisterTable, @@ -33,9 +34,13 @@ import { @RegisterTable("users") class User extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") declare email: string; + + @Field("number") declare age: number; } diff --git a/docs/7.foreign-keys.md b/docs/7.foreign-keys.md index 29d1c7c..245b1ed 100644 --- a/docs/7.foreign-keys.md +++ b/docs/7.foreign-keys.md @@ -11,26 +11,37 @@ Apply `@Foreign` to a field that stores a foreign key value. The decorator repla ```typescript import { Foreign } from "@antelopejs/interface-data-api/metadata"; import { + Field, Index, RegisterTable, + Relation, Table, } from "@antelopejs/interface-database-decorators"; @RegisterTable("users") class User extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") declare name: string; + + @Field("string") declare email: string; } @RegisterTable("orders") class Order extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") + @Relation({ to: () => User }) declare userId: string; + + @Field("number") declare total: number; } @@ -111,21 +122,30 @@ declare userId: User; When a field stores an array of foreign key IDs, set the `multi` parameter to `true`. The API resolves each ID and returns an array of full records. +The table-level `@Relation({ many: true })` is declarative metadata recording that the field holds multiple target keys; API-side resolution is controlled solely by the `multi` parameter of `@Foreign`. + ```typescript @RegisterTable("carts") class Cart extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field(["string"]) + @Relation({ to: () => CartItem, many: true }) declare items: string[]; // Array of CartItem IDs } @RegisterTable("cart_items") class CartItem extends Table { @Index({ primary: true }) + @Field("string") declare _id: string; + @Field("string") declare name: string; + + @Field("number") declare price: number; } diff --git a/docs/9.modifiers.md b/docs/9.modifiers.md index 7011753..06c69d5 100644 --- a/docs/9.modifiers.md +++ b/docs/9.modifiers.md @@ -44,6 +44,7 @@ import { } from "@antelopejs/interface-data-api/metadata"; import { BasicDataModel, + Field, Index, Localized, LocalizationModifier, @@ -55,12 +56,15 @@ import { @RegisterTable("content") class Content extends Table.with(LocalizationModifier) { @Index({ primary: true }) + @Field("string") declare _id: string; @Localized() + @Field("string") declare title: string; @Localized() + @Field("string") declare description: string; }