kysely-mapper
Version:
Flexible Kysely-based utility for mapping between tables and objects
74 lines • 4.32 kB
TypeScript
import { Kysely, InsertQueryBuilder, InsertResult, Insertable } from 'kysely';
import { SelectionColumn } from '../lib/type-utils.js';
import { InsertTransforms } from '../mappers/table-mapper-transforms.js';
/**
* Mapping query for inserting rows into a database table.
*/
export declare class MappingInsertQuery<DB, TB extends keyof DB & string, QB extends InsertQueryBuilder<DB, TB, InsertResult>, InsertedObject, InsertReturnColumns extends Readonly<SelectionColumn<DB, TB>[]> | ['*'], InsertReturn> {
#private;
protected readonly db: Kysely<DB>;
protected readonly qb: QB;
protected readonly transforms: Readonly<InsertTransforms<DB, TB, InsertedObject, InsertReturnColumns, InsertReturn>>;
protected readonly returnColumns: Readonly<InsertReturnColumns>;
constructor(db: Kysely<DB>, qb: QB, transforms: Readonly<InsertTransforms<DB, TB, InsertedObject, InsertReturnColumns, InsertReturn>>, returnColumns: Readonly<InsertReturnColumns>);
/**
* Modifies the underlying Kysely query builder.
* @param factory A function that takes the current query builder and
* returns a new query builder.
*/
modify<NextQB extends InsertQueryBuilder<DB, TB, any>>(factory: (qb: QB) => NextQB): MappingInsertQuery<DB, TB, NextQB, InsertedObject, InsertReturnColumns, InsertReturn>;
/**
* Inserts the provided objects into the table as rows, first transforming
* them into rows via `insertTransform` (if defined). For each row inserted,
* retrieves the columns specified in `returnColumns`, returning them to
* the caller as `InsertReturn`, after transformation by
* `insertReturnTransform`. If `returnColumns` is empty, returns `undefined`.
* @returns If `returnColumns` is not empty, returns an array containing one
* object for each inserted object; otherwise returns `undefined`.
*/
returnAll(objs: InsertedObject[]): Promise<InsertReturnColumns extends [] ? void : InsertReturn[]>;
/**
* Inserts the provided object into the table as a row, first transforming
* it into a row via `insertTransform` (if defined). Also retrieves the
* columns specified in `returnColumns`, returning them to the caller as
* `InsertReturn`, after transformation by `insertReturnTransform`.
* If `returnColumns` is empty, returns `undefined`.
* @returns If `returnColumns` is not empty, returns an object;
* otherwise returns `undefined`.
*/
returnOne(obj: InsertedObject): Promise<InsertReturnColumns extends [] ? void : InsertReturn>;
/**
* Runs the query, inserting rows into the table without returning any columns.
* @param objOrObjs The object or objects to be inserted.
* @returns Returns `true`; throws an exception on error.
*/
run(objOrObjs: InsertedObject | InsertedObject[]): Promise<boolean>;
/**
* Returns an array of the columns to be inserted, with
* `['*']` indicating that all columns will be inserted.
* @returns An array of the columns to be inserted.
*/
protected getInsertColumns(): Readonly<(keyof Insertable<DB[TB]> & string)[]> | ['*'];
/**
* Returns a query builder for inserting rows into the table and
* returning values, caching the query builder for future use.
* @returns A query builder for inserting rows into the table and
* returning values.
*/
protected getReturningQB(): InsertQueryBuilder<DB, TB, any>;
/**
* Loads the objects to be inserted into the query builder.
* @param qb The query builder to load the objects into.
* @param objOrObjs The object or objects to be inserted.
* @returns The query builder with the objects loaded.
*/
protected loadInsertedObjects(qb: InsertQueryBuilder<DB, TB, InsertResult>, objOrObjs: InsertedObject | InsertedObject[]): InsertQueryBuilder<DB, TB, InsertResult>;
/**
* Sets the values of the inserted columns.
* @param qb The query builder to set the values into.
* @param objOrObjs The object or objects of column-value pairs
* to be inserted.
*/
protected setColumnValues(qb: InsertQueryBuilder<DB, TB, InsertResult>, objOrObjs: Insertable<DB[TB]> | Insertable<DB[TB]>[]): InsertQueryBuilder<DB, TB, InsertResult>;
}
//# sourceMappingURL=insert-query.d.ts.map