Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/1.introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from "@antelopejs/interface-data-api/metadata";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterTable,
Expand All @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions docs/10.joined.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions docs/11.computed.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions docs/2.data-controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "@antelopejs/interface-data-api/metadata";
import {
BasicDataModel,
Field,
Index,
Model,
RegisterTable,
Expand All @@ -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;
}

Expand Down
20 changes: 20 additions & 0 deletions docs/7.foreign-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 })
Comment thread
MrSociety404 marked this conversation as resolved.
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;
}

Expand Down
4 changes: 4 additions & 0 deletions docs/9.modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
} from "@antelopejs/interface-data-api/metadata";
import {
BasicDataModel,
Field,
Index,
Localized,
LocalizationModifier,
Expand All @@ -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;
}

Expand Down
Loading