model<S extends Record> function

Model model<S extends Record>(
  1. String table,
  2. S fields, {
  3. Object primaryKey(
    1. S
    )?,
  4. List<Object> uniqueKeys(
    1. S
    )?,
  5. List<IndexDefinition> indexes(
    1. S
    )?,
  6. Record relations(
    1. S
    )?,
  7. List<CheckDefinition>? checks,
})

Defines a model using named column declarations and local constraints.

Declare a public final employee = model('employees', (...)). The named Record's shape supplies the types in local key, index and relation selectors. Add an explicit Model type to break self-reference or mutual-reference inference cycles; selector field types are preserved in either form.

Select keys with a direct column or an ordered positional Record of columns. Selectors must be arrow expressions. relations returns a named Record of references/referencedBy declarations; other collections are literal lists. Every field of fields must be a column declaration, checked by generation. Callbacks are not executed and do not register mutable runtime metadata. Generate and import the client to query typed rows.

Implementation

Model model<S extends Record>(
  String table,
  S fields, {
  Object Function(S)? primaryKey,
  List<Object> Function(S)? uniqueKeys,
  List<IndexDefinition> Function(S)? indexes,
  Record Function(S)? relations,
  List<CheckDefinition>? checks,
}) => Model._(table, fields);