Helper that extracts the interface a given schema.
type User = InterfaceForSchema<typeof userCollection>;
const user: User = {
username: 'Connor'
};
Type describing the Cosmos DB QueryIterator. A mapped type here is used so that we can implement the interface with our custom mapped type.
Creates a class that represents the provided schema. You can use class standalone if you don't need any other methods:
const User = Model(userSchema);
const user = new User();
user.username = 'connor4312';
await user.save();
...or extend it to add custom functionality:
class User extends Model(userSchema) {
// e.g. overriding a lifecycle hook
beforePersist(password: string) {
if (this.isDirty('password')) {
this.password = hash(password);
}
}
}
The returned class extends the BaseModel and has the following static properties, which TypeDoc does not represent well:
Associates the database connection with all models.
Template literal tag function that produces a Cosmos DB query. For example:
User.query(sql`SELECT users.* FROM users WHERE users.username = ${username}`)
In this case, ${username}
is correctly extracted to a parameter. Useful
for making security auditors' hearts skip a beat.
Generated using TypeDoc
Helper type to get the data interface for a Model.