d1-orm
Version:
A simple strictly typed ORM for Cloudflare's D1 product
68 lines • 2.95 kB
TypeScript
/**
* @enum {string} - The type of the query
*/
export declare enum QueryType {
SELECT = "SELECT",
INSERT = "INSERT",
INSERT_OR_REPLACE = "INSERT or REPLACE",
UPDATE = "UPDATE",
DELETE = "DELETE",
UPSERT = "UPSERT"
}
/**
* @param _
* **where** - The where clause for the query. This is an object with the column names as keys and the values as values.
*
* **limit** - The limit for the query. This is the maximum number of rows to return.
*
* **offset** - The offset for the query. This is the number of rows to skip before returning.
*
* **orderBy** - The order by clause for the query. See {@link OrderBy} for more information.
*
* **data** - The data to insert, or update with. This is an object with the column names as keys and the values as values. In the case of Upsert, `upsertOnlyUpdateData` is also required, and that will be the data to update with, if an `ON CONFLICT` clause is matched.
*
* **upsertOnlyUpdateData** - The data to update with, if an `ON CONFLICT` clause is matched. This is an object with the column names as keys and the values as values.
* @typeParam T - The type of the object to query. This is generally not needed to be specified, but can be useful if you're calling this yourself instead of through a {@link Model}.
*/
export type GenerateQueryOptions<T extends object> = {
where?: Partial<T>;
limit?: number;
offset?: number;
orderBy?: OrderBy<T> | OrderBy<T>[];
data?: Partial<T>;
upsertOnlyUpdateData?: Partial<T>;
};
/**
* @typeParam T - The type of the object to query. This is generally not needed to be specified, but can be useful if you're calling this yourself instead of through a {@link Model}.
* ```ts
* {
* // Any of these are valid
* orderBy: 'id',
* orderBy: ['id', 'name'],
* orderBy: { column: 'id', descending: true, nullLast: true },
* orderBy: [{ column: 'id', descending: true, nullLast: true }, { column: 'name', descending: false, nullLast: false }],
* }
* ```
*/
export type OrderBy<T extends object> = keyof T | {
column: keyof T;
descending: boolean;
nullLast?: boolean;
};
/**
* @param type - The type of query to generate, see {@link QueryType}
* @param tableName - The table to query
* @param options - The options for the query, see {@link GenerateQueryOptions}
* @typeParam T - The type of the object to query. This is generally not needed to be specified, but can be useful if you're calling this yourself instead of through a {@link Model}.
* @returns The query and bindings to be executed
*/
export declare function GenerateQuery<T extends object>(type: QueryType, tableName: string, options?: GenerateQueryOptions<T>, primaryKeys?: string | string[]): {
bindings: unknown[];
query: string;
};
/**
* @private
* @hidden
*/
export declare function transformOrderBy<T extends object>(orderBy: OrderBy<T> | OrderBy<T>[]): string;
//# sourceMappingURL=queryBuilder.d.ts.map