Toshihiko
    Preparing search index...

    Interface Yukari<Name, Schema, AdapterInstance>

    One mutable row belonging to a Model.

    Schema fields are exposed as enumerable properties on the instance. Use Model.build to create a new row, or obtain a queried row from Query.find, Query.findOne, or Query.findById.

    A built row can be inserted. A queried row can be updated or deleted. The original values used to locate and compare a queried row are kept privately.

    interface Yukari<
        Name extends string,
        Schema extends SchemaDefinition,
        AdapterInstance extends AdapterLike = Adapter,
    > {
        delete(
            connection?: AdapterConnection<AdapterInstance> | null,
        ): Promise<true>;
        insert(
            connection?:
                | Exclude<Parameters<AdapterInstance["insert"]>[1], null>
                | null,
        ): Promise<Yukari<Name, Schema, AdapterInstance>>;
        save(
            connection?:
                | Exclude<Parameters<AdapterInstance["insert"]>[1], null>
                | null,
        ): Promise<Yukari<Name, Schema, AdapterInstance>>;
        toJSON(useOriginalData?: boolean): Partial<JsonRowFromSchema<Schema>>;
        update(
            connection?:
                | Exclude<Parameters<AdapterInstance["insert"]>[1], null>
                | null,
        ): Promise<Yukari<Name, Schema, AdapterInstance>>;
        validateAll(): Promise<void>;
        validateOne<Field extends string>(
            name: Field,
            value: RowFromSchema<Schema>[Field],
        ): Promise<void>;
    }

    Type Parameters

    Index
    • Deletes a row loaded from the database.

      The delete condition uses original primary-key values. If the Model has no primary key, all original fields form the locator. At most one row is requested from the Adapter.

      Parameters

      Returns Promise<true>

      true after the Adapter reports a successful deletion.

      When called on a newly built row or when the Adapter returns a falsy result.

    • Validates and inserts a row created by Model.build.

      Values returned by the Adapter, such as an auto-incremented primary key, are copied onto this same Yukari instance.

      Parameters

      • connection: Exclude<Parameters<AdapterInstance["insert"]>[1], null> | null = null

        Optional Adapter transaction connection.

      Returns Promise<Yukari<Name, Schema, AdapterInstance>>

      This Yukari instance after the write completes.

      When called on a row loaded from the database, or validation or Adapter execution fails.

    • Serializes mapped fields with each Field Type's toJSON() implementation.

      Parameters

      • useOriginalData: boolean = false

        Serialize the original database snapshot instead of the current enumerable properties.

      Returns Partial<JsonRowFromSchema<Schema>>

      A plain object keyed by logical schema field names.

      const current = user.toJSON();
      const beforeChanges = user.toJSON(true);
    • Updates a row loaded from the database.

      Changed fields are detected against the private original-value snapshot. The original primary-key values locate the row, so changing a primary-key property does not lose the original locator. When no value changed, the complete mapped row is sent for v1-compatible behavior.

      Parameters

      • connection: Exclude<Parameters<AdapterInstance["insert"]>[1], null> | null = null

        Optional Adapter transaction connection.

      Returns Promise<Yukari<Name, Schema, AdapterInstance>>

      This Yukari instance with its original snapshot refreshed.

      When called on a newly built row, or validation or Adapter execution fails.

    • Validates every enumerable property mapped to a schema field.

      Functions, compatibility properties whose names start with $, and properties absent from the schema are ignored. At most ten fields are validated concurrently.

      Returns Promise<void>

      The first validation error produced by validateOne.

    • Runs the validators for one schema field.

      Nullable fields accept null without running custom validators. Each validator runs with this bound to the row's Model.

      Type Parameters

      • Field extends string

      Parameters

      Returns Promise<void>

      When the field does not exist, a non-nullable field receives null, or a validator returns a non-empty error message.