Collectionclass
new Collection<N, I, T>(name: N, id: Schema<I>, data: Schemas<T> | DataSchema<T>)
| Param | Type | |
|---|---|---|
name | N | Collection name used as the table/collection key. required |
id | Schema<I> | Schema for the identifier type. required |
data | Schemas<T>DataSchema<T> | Data schema, or the Schemas props used to construct one. required |
| Return | |
|---|---|
Collection<N, I, T> | Declarative definition of a database collection/table. |
| Property | Type | |
|---|---|---|
.name | N | Collection name (used as the table/collection key). required readonly |
.id | Schema<I> | Schema for the identifier type. required readonly |
.item | DataSchema<Item<I, T>> | Schema for a complete item (id + data). required readonly |
Declarative definition of a database collection/table.
- Pairs a collection name with an identifier schema and a data schema, so providers can validate and address items.
- Extends
DataSchema<T>, so the collection itself validates an item's data, while.itemvalidates the completeid + dataitem.
Examples
const users = new Collection("users", ID, { name: STRING, age: NUMBER });
users.validate({ name: "Dave", age: 40 }); // Validates item data.