Cloesce - v0.1.5
    Preparing search index...

    Interface DataSource<T>

    Defines a Data Source for a Model, which can include KV, R2, 1:1, 1:M and M:M relationships as specified by the include tree.

    interface DataSource<T> {
        get?: (joined: (from?: string) => string) => string;
        includeTree?: IncludeTree<T>;
        list?: (joined: (from?: string) => string) => string;
        listParams?: CrudListParam[];
    }

    Type Parameters

    • T
    Index

    Properties

    get?: (joined: (from?: string) => string) => string

    A custom function called when using orm.get. Defaults to:

    `${Orm.select(ctor, { include: includeTree })} WHERE ${pkName1} = ? AND ${pkName2} = ? ...`
    

    Parameters for each primary key column are always bound to the query when executed by D1, in primary key column order. Reference them in the query using ?, ?1, ?2, etc.

    Type Declaration

      • (joined: (from?: string) => string): string
      • Parameters

        • joined: (from?: string) => string

          A helper function to generate a SELECT query for the model with the same include tree as the data source.

        Returns string

        A SQL query string to retrieve a single instance of the model from D1.

    includeTree?: IncludeTree<T>

    The include tree specifying which relationships to include in the data source.

    list?: (joined: (from?: string) => string) => string

    A custom function called when using orm.list. Defaults to a seek pagination query:

    `${Orm.select(ctor, { include: includeTree })} WHERE ("${model.name}"."${pk1}", ...) > (?, ...) ORDER BY "${model.name}"."${pk1}" ASC, ... LIMIT ?`
    

    Use DataSource.listParams to specify which parameters to bind when calling orm.list. If a custom implementation is given, no parameters are bound by default, and it's the responsibility of the user to specify and bind any parameters needed for the query.

    Type Declaration

      • (joined: (from?: string) => string): string
      • Parameters

        • joined: (from?: string) => string

          A helper function to generate a SELECT query for the model with the same include tree as the data source.

        Returns string

        A SQL query string to retrieve multiple instances of the model from D1.

    listParams?: CrudListParam[]

    The parameters to bind when calling DataSource.list. Defaults to empty.