kysely-mapper
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -60,5 +60,12 @@ "use strict"; | ||
applyInsertTransform(obj) { | ||
return this.transforms.insertTransform === undefined | ||
const values = this.transforms.insertTransform === undefined | ||
? obj | ||
: this.transforms.insertTransform(obj, this.columnsToInsert); | ||
// ensure the output of insertTransform works for the present query | ||
this.columnsToInsert.forEach((column) => { | ||
if (values[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from inserting object (compiled)`); | ||
} | ||
}); | ||
return values; | ||
} | ||
@@ -65,0 +72,0 @@ } |
@@ -89,5 +89,12 @@ "use strict"; | ||
applyUpdateTransform(obj) { | ||
return this.transforms.updateTransform === undefined | ||
const values = this.transforms.updateTransform === undefined | ||
? obj | ||
: this.transforms.updateTransform(obj, this.columnsToUpdate); | ||
// ensure the output of updateTransform works for the present query | ||
this.columnsToUpdate.forEach((column) => { | ||
if (values[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from updating object (compiled)`); | ||
} | ||
}); | ||
return values; | ||
} | ||
@@ -94,0 +101,0 @@ applyUpdateReturnTransform(source, returns) { |
@@ -37,4 +37,5 @@ "use strict"; | ||
toInsertableObject(obj) { | ||
// ensure the output of insertTransform works for the present query | ||
this.columnsToInsert.forEach((column) => { | ||
if (!(column in obj)) { | ||
if (obj[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from inserted object`); | ||
@@ -41,0 +42,0 @@ } |
@@ -34,4 +34,5 @@ "use strict"; | ||
toUpdateableObject(obj) { | ||
// ensure the output of updateTransform works for the present query | ||
this.columnsToUpdate.forEach((column) => { | ||
if (!(column in obj)) { | ||
if (obj[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from updating object`); | ||
@@ -38,0 +39,0 @@ } |
@@ -137,3 +137,10 @@ "use strict"; | ||
})); | ||
it('requires all indicated columns to be inserted', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const compilation = userMapperReturningAll | ||
.insert() | ||
.columns(['name', 'handle', 'email']) | ||
.compile(); | ||
expect(() => compilation.returnOne({ name: 'John Doe', handle: 'johndoe' })).rejects.toThrow(`column 'email' missing`); | ||
})); | ||
}); | ||
//# sourceMappingURL=insert-compile.test.js.map |
@@ -36,3 +36,3 @@ "use strict"; | ||
.update({ id: 1 }) | ||
.columns(['handle', 'name', 'email']) | ||
.columns(['email']) | ||
.compile(); | ||
@@ -416,3 +416,10 @@ const success2 = yield compilation.run({}, updateValues); | ||
})); | ||
it('requires all indicated columns to be updated', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const compilation = userMapperReturningID | ||
.update() | ||
.columns(['name', 'handle', 'email']) | ||
.compile(); | ||
expect(() => compilation.returnOne({}, { name: 'John Doe', handle: 'johndoe' })).rejects.toThrow(`column 'email' missing`); | ||
})); | ||
}); | ||
//# sourceMappingURL=update-compile.test.js.map |
@@ -57,7 +57,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
applyInsertTransform(obj) { | ||
return this.transforms.insertTransform === undefined | ||
const values = this.transforms.insertTransform === undefined | ||
? obj | ||
: this.transforms.insertTransform(obj, this.columnsToInsert); | ||
// ensure the output of insertTransform works for the present query | ||
this.columnsToInsert.forEach((column) => { | ||
if (values[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from inserting object (compiled)`); | ||
} | ||
}); | ||
return values; | ||
} | ||
} | ||
//# sourceMappingURL=compiling-insert-query.js.map |
@@ -86,5 +86,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
applyUpdateTransform(obj) { | ||
return this.transforms.updateTransform === undefined | ||
const values = this.transforms.updateTransform === undefined | ||
? obj | ||
: this.transforms.updateTransform(obj, this.columnsToUpdate); | ||
// ensure the output of updateTransform works for the present query | ||
this.columnsToUpdate.forEach((column) => { | ||
if (values[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from updating object (compiled)`); | ||
} | ||
}); | ||
return values; | ||
} | ||
@@ -91,0 +98,0 @@ applyUpdateReturnTransform(source, returns) { |
@@ -34,4 +34,5 @@ import { MappingInsertQuery } from './insert-query'; | ||
toInsertableObject(obj) { | ||
// ensure the output of insertTransform works for the present query | ||
this.columnsToInsert.forEach((column) => { | ||
if (!(column in obj)) { | ||
if (obj[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from inserted object`); | ||
@@ -38,0 +39,0 @@ } |
@@ -31,4 +31,5 @@ import { MappingUpdateQuery } from './update-query'; | ||
toUpdateableObject(obj) { | ||
// ensure the output of updateTransform works for the present query | ||
this.columnsToUpdate.forEach((column) => { | ||
if (!(column in obj)) { | ||
if (obj[column] === undefined) { | ||
throw Error(`Specified column '${column}' missing from updating object`); | ||
@@ -35,0 +36,0 @@ } |
@@ -135,3 +135,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
})); | ||
it('requires all indicated columns to be inserted', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const compilation = userMapperReturningAll | ||
.insert() | ||
.columns(['name', 'handle', 'email']) | ||
.compile(); | ||
expect(() => compilation.returnOne({ name: 'John Doe', handle: 'johndoe' })).rejects.toThrow(`column 'email' missing`); | ||
})); | ||
}); | ||
//# sourceMappingURL=insert-compile.test.js.map |
@@ -34,3 +34,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
.update({ id: 1 }) | ||
.columns(['handle', 'name', 'email']) | ||
.columns(['email']) | ||
.compile(); | ||
@@ -414,3 +414,10 @@ const success2 = yield compilation.run({}, updateValues); | ||
})); | ||
it('requires all indicated columns to be updated', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const compilation = userMapperReturningID | ||
.update() | ||
.columns(['name', 'handle', 'email']) | ||
.compile(); | ||
expect(() => compilation.returnOne({}, { name: 'John Doe', handle: 'johndoe' })).rejects.toThrow(`column 'email' missing`); | ||
})); | ||
}); | ||
//# sourceMappingURL=update-compile.test.js.map |
{ | ||
"name": "kysely-mapper", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"author": "Joseph T. Lapp <arachnojoe@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -394,8 +394,9 @@ # kysely-mapper | ||
```ts | ||
updateTransform: (source: User, columns) => ({ | ||
name: columns.includes('name') | ||
? `${source.firstName} ${source.lastName}` | ||
: undefined, | ||
birth_year: source.birthYear, | ||
}); | ||
updateTransform: (source: User, columns) => ({ | ||
name: | ||
columns[0] == '*' || columns.includes('name') | ||
? `${source.firstName} ${source.lastName}` | ||
: undefined, | ||
birth_year: source.birthYear, | ||
}), | ||
``` | ||
@@ -406,9 +407,9 @@ | ||
```ts | ||
updateTransform: (source: User | Updateable<Database['users']>) => | ||
source instanceof User | ||
? { | ||
name: `${source.firstName} ${source.lastName}`, | ||
birth_year: source.birthYear, | ||
} | ||
: source; | ||
updateTransform: (source: User | Updateable<Database['users']>) => | ||
source instanceof User | ||
? { | ||
name: `${source.firstName} ${source.lastName}`, | ||
birth_year: source.birthYear, | ||
} | ||
: source, | ||
``` | ||
@@ -415,0 +416,0 @@ |
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
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
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
1052724
11316
720