kysely-mapper
Advanced tools
Comparing version 0.4.15 to 0.4.16
@@ -43,4 +43,7 @@ import { Kysely, Insertable, ReferenceExpression, Selectable, InsertQueryBuilder, InsertResult, SelectQueryBuilder, Selection, DeleteQueryBuilder, DeleteResult, UpdateResult, UpdateQueryBuilder, ComparisonOperatorExpression, OperandValueExpressionOrList, Updateable } from 'kysely'; | ||
#private; | ||
/** The Kysely instance, either a database or a transaction. */ | ||
readonly db: Kysely<DB>; | ||
/** The name of the table. */ | ||
readonly tableName: TB; | ||
/** Settings governing mapper behavior. */ | ||
readonly settings: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>; | ||
@@ -59,8 +62,9 @@ /** Columns that compose the table's primary key. */ | ||
* Constructs a new abstract table mapper. | ||
* @param db The Kysely database. | ||
* @param db The Kysely instance, either a database or a transaction. | ||
* @param tableName The name of the table. | ||
* @param options Options governing mapper behavior. Default to selecting | ||
* @param settings Settings governing mapper behavior. Default to selecting | ||
* all columns and to returning no columns on insert or update. | ||
*/ | ||
constructor(db: Kysely<DB>, tableName: TB, settings?: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>); | ||
constructor(db: Kysely<DB>, mapper: AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>); | ||
/** | ||
@@ -67,0 +71,0 @@ * Returns a mapping query for deleting the rows of the table that match |
@@ -48,14 +48,4 @@ "use strict"; | ||
class AbstractTableMapper { | ||
/** | ||
* Constructs a new abstract table mapper. | ||
* @param db The Kysely database. | ||
* @param tableName The name of the table. | ||
* @param options Options governing mapper behavior. Default to selecting | ||
* all columns and to returning no columns on insert or update. | ||
*/ | ||
constructor(db, tableName, settings = {}) { | ||
constructor(db, tableNameOrMapper, settings = {}) { | ||
var _a, _b, _c, _d; | ||
this.db = db; | ||
this.tableName = tableName; | ||
this.settings = settings; | ||
_AbstractTableMapper_baseDeleteQB.set(this, null); | ||
@@ -65,14 +55,21 @@ _AbstractTableMapper_baseInsertQB.set(this, null); | ||
_AbstractTableMapper_baseUpdateQB.set(this, null); | ||
/** Query input and output value transforms. */ | ||
this.transforms = {}; | ||
this.keyColumns = (_a = settings.keyColumns) !== null && _a !== void 0 ? _a : []; | ||
this.selectedColumns = | ||
settings.selectedColumns === undefined | ||
? [] | ||
: settings.selectedColumns[0] === '*' | ||
if (tableNameOrMapper instanceof AbstractTableMapper) { | ||
Object.assign(this, tableNameOrMapper); | ||
} | ||
else { | ||
this.tableName = tableNameOrMapper; | ||
this.settings = settings; | ||
this.keyColumns = (_a = settings.keyColumns) !== null && _a !== void 0 ? _a : []; | ||
this.selectedColumns = | ||
settings.selectedColumns === undefined | ||
? [] | ||
: settings.selectedColumns; | ||
this.insertReturnColumns = | ||
(_c = (_b = settings.insertReturnColumns) !== null && _b !== void 0 ? _b : this.keyColumns) !== null && _c !== void 0 ? _c : []; | ||
this.updateReturnColumns = (_d = settings.updateReturnColumns) !== null && _d !== void 0 ? _d : []; | ||
: settings.selectedColumns[0] === '*' | ||
? [] | ||
: settings.selectedColumns; | ||
this.insertReturnColumns = | ||
(_c = (_b = settings.insertReturnColumns) !== null && _b !== void 0 ? _b : this.keyColumns) !== null && _c !== void 0 ? _c : []; | ||
this.updateReturnColumns = (_d = settings.updateReturnColumns) !== null && _d !== void 0 ? _d : []; | ||
this.transforms = {}; | ||
} | ||
this.db = db; | ||
} | ||
@@ -79,0 +76,0 @@ delete(filterOrLHS, op, rhs) { |
@@ -1,2 +0,2 @@ | ||
import { Insertable, Selectable, Selection, Updateable } from 'kysely'; | ||
import { Insertable, Selectable, Selection, Transaction, Updateable } from 'kysely'; | ||
import { SelectableColumnTuple, SelectedRow, SelectionColumn } from '../lib/type-utils.js'; | ||
@@ -37,3 +37,11 @@ import { TableMapperTransforms } from './table-mapper-transforms.js'; | ||
withTransforms<SelectedObject = SelectedRow<DB, TB, SelectedColumns extends ['*'] ? never : SelectedColumns[number], SelectedColumns>, InsertedObject = Insertable<DB[TB]>, UpdatingObject = Updateable<DB[TB]>, ReturnCount = bigint, InsertReturn = InsertReturnColumns extends ['*'] ? Selectable<DB[TB]> : Selection<DB, TB, InsertReturnColumns[number]>, UpdateReturn = UpdateReturnColumns extends ['*'] ? Selectable<DB[TB]> : Selection<DB, TB, UpdateReturnColumns[number]>>(transforms: Readonly<TableMapperTransforms<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>>): TableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>; | ||
/** | ||
* Returns a new table mapper that issues queries in the provided | ||
* transaction, using the present table mapper's configuration. | ||
* @param transaction The transaction to use. | ||
* @returns A new table mapper that issues queries in the provided | ||
* transaction. | ||
*/ | ||
forTransaction(trx: Transaction<DB>): TableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>; | ||
} | ||
//# sourceMappingURL=table-mapper.d.ts.map |
@@ -41,4 +41,14 @@ "use strict"; | ||
} | ||
/** | ||
* Returns a new table mapper that issues queries in the provided | ||
* transaction, using the present table mapper's configuration. | ||
* @param transaction The transaction to use. | ||
* @returns A new table mapper that issues queries in the provided | ||
* transaction. | ||
*/ | ||
forTransaction(trx) { | ||
return new TableMapper(trx, this); | ||
} | ||
} | ||
exports.TableMapper = TableMapper; | ||
//# sourceMappingURL=table-mapper.js.map |
@@ -43,4 +43,7 @@ import { Kysely, Insertable, ReferenceExpression, Selectable, InsertQueryBuilder, InsertResult, SelectQueryBuilder, Selection, DeleteQueryBuilder, DeleteResult, UpdateResult, UpdateQueryBuilder, ComparisonOperatorExpression, OperandValueExpressionOrList, Updateable } from 'kysely'; | ||
#private; | ||
/** The Kysely instance, either a database or a transaction. */ | ||
readonly db: Kysely<DB>; | ||
/** The name of the table. */ | ||
readonly tableName: TB; | ||
/** Settings governing mapper behavior. */ | ||
readonly settings: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>; | ||
@@ -59,8 +62,9 @@ /** Columns that compose the table's primary key. */ | ||
* Constructs a new abstract table mapper. | ||
* @param db The Kysely database. | ||
* @param db The Kysely instance, either a database or a transaction. | ||
* @param tableName The name of the table. | ||
* @param options Options governing mapper behavior. Default to selecting | ||
* @param settings Settings governing mapper behavior. Default to selecting | ||
* all columns and to returning no columns on insert or update. | ||
*/ | ||
constructor(db: Kysely<DB>, tableName: TB, settings?: Readonly<TableMapperSettings<DB, TB, KeyColumns, SelectedColumns, InsertReturnColumns, UpdateReturnColumns>>); | ||
constructor(db: Kysely<DB>, mapper: AbstractTableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>); | ||
/** | ||
@@ -67,0 +71,0 @@ * Returns a mapping query for deleting the rows of the table that match |
@@ -45,14 +45,4 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
export class AbstractTableMapper { | ||
/** | ||
* Constructs a new abstract table mapper. | ||
* @param db The Kysely database. | ||
* @param tableName The name of the table. | ||
* @param options Options governing mapper behavior. Default to selecting | ||
* all columns and to returning no columns on insert or update. | ||
*/ | ||
constructor(db, tableName, settings = {}) { | ||
constructor(db, tableNameOrMapper, settings = {}) { | ||
var _a, _b, _c, _d; | ||
this.db = db; | ||
this.tableName = tableName; | ||
this.settings = settings; | ||
_AbstractTableMapper_baseDeleteQB.set(this, null); | ||
@@ -62,14 +52,21 @@ _AbstractTableMapper_baseInsertQB.set(this, null); | ||
_AbstractTableMapper_baseUpdateQB.set(this, null); | ||
/** Query input and output value transforms. */ | ||
this.transforms = {}; | ||
this.keyColumns = (_a = settings.keyColumns) !== null && _a !== void 0 ? _a : []; | ||
this.selectedColumns = | ||
settings.selectedColumns === undefined | ||
? [] | ||
: settings.selectedColumns[0] === '*' | ||
if (tableNameOrMapper instanceof AbstractTableMapper) { | ||
Object.assign(this, tableNameOrMapper); | ||
} | ||
else { | ||
this.tableName = tableNameOrMapper; | ||
this.settings = settings; | ||
this.keyColumns = (_a = settings.keyColumns) !== null && _a !== void 0 ? _a : []; | ||
this.selectedColumns = | ||
settings.selectedColumns === undefined | ||
? [] | ||
: settings.selectedColumns; | ||
this.insertReturnColumns = | ||
(_c = (_b = settings.insertReturnColumns) !== null && _b !== void 0 ? _b : this.keyColumns) !== null && _c !== void 0 ? _c : []; | ||
this.updateReturnColumns = (_d = settings.updateReturnColumns) !== null && _d !== void 0 ? _d : []; | ||
: settings.selectedColumns[0] === '*' | ||
? [] | ||
: settings.selectedColumns; | ||
this.insertReturnColumns = | ||
(_c = (_b = settings.insertReturnColumns) !== null && _b !== void 0 ? _b : this.keyColumns) !== null && _c !== void 0 ? _c : []; | ||
this.updateReturnColumns = (_d = settings.updateReturnColumns) !== null && _d !== void 0 ? _d : []; | ||
this.transforms = {}; | ||
} | ||
this.db = db; | ||
} | ||
@@ -76,0 +73,0 @@ delete(filterOrLHS, op, rhs) { |
@@ -1,2 +0,2 @@ | ||
import { Insertable, Selectable, Selection, Updateable } from 'kysely'; | ||
import { Insertable, Selectable, Selection, Transaction, Updateable } from 'kysely'; | ||
import { SelectableColumnTuple, SelectedRow, SelectionColumn } from '../lib/type-utils.js'; | ||
@@ -37,3 +37,11 @@ import { TableMapperTransforms } from './table-mapper-transforms.js'; | ||
withTransforms<SelectedObject = SelectedRow<DB, TB, SelectedColumns extends ['*'] ? never : SelectedColumns[number], SelectedColumns>, InsertedObject = Insertable<DB[TB]>, UpdatingObject = Updateable<DB[TB]>, ReturnCount = bigint, InsertReturn = InsertReturnColumns extends ['*'] ? Selectable<DB[TB]> : Selection<DB, TB, InsertReturnColumns[number]>, UpdateReturn = UpdateReturnColumns extends ['*'] ? Selectable<DB[TB]> : Selection<DB, TB, UpdateReturnColumns[number]>>(transforms: Readonly<TableMapperTransforms<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>>): TableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>; | ||
/** | ||
* Returns a new table mapper that issues queries in the provided | ||
* transaction, using the present table mapper's configuration. | ||
* @param transaction The transaction to use. | ||
* @returns A new table mapper that issues queries in the provided | ||
* transaction. | ||
*/ | ||
forTransaction(trx: Transaction<DB>): TableMapper<DB, TB, KeyColumns, SelectedColumns, SelectedObject, InsertedObject, UpdatingObject, ReturnCount, InsertReturnColumns, UpdateReturnColumns, InsertReturn, UpdateReturn>; | ||
} | ||
//# sourceMappingURL=table-mapper.d.ts.map |
@@ -38,3 +38,13 @@ import { AbstractTableMapper } from './abstract-table-mapper.js'; | ||
} | ||
/** | ||
* Returns a new table mapper that issues queries in the provided | ||
* transaction, using the present table mapper's configuration. | ||
* @param transaction The transaction to use. | ||
* @returns A new table mapper that issues queries in the provided | ||
* transaction. | ||
*/ | ||
forTransaction(trx) { | ||
return new TableMapper(trx, this); | ||
} | ||
} | ||
//# sourceMappingURL=table-mapper.js.map |
{ | ||
"name": "kysely-mapper", | ||
"version": "0.4.15", | ||
"version": "0.4.16", | ||
"author": "Joseph T. Lapp <arachnojoe@gmail.com>", | ||
@@ -38,3 +38,3 @@ "license": "MIT", | ||
"write-packages": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json", | ||
"build-docs": "typedoc --options ./typedoc.js ./src/index.ts", | ||
"build-docs": "typedoc --options ./typedoc.cjs ./src/index.ts", | ||
"build-all": "pnpm build && pnpm build-docs", | ||
@@ -41,0 +41,0 @@ "test": "vitest --run" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1079079
389
11570