Skip to content

Commit

Permalink
rename MutationObject to UpdateObject
Browse files Browse the repository at this point in the history
  • Loading branch information
koskimas committed Dec 29, 2022
1 parent b009480 commit d57ead2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export {
JoinCallbackExpression,
} from './parser/join-parser.js'
export { InsertObject } from './parser/insert-values-parser.js'
export { MutationObject } from './parser/update-set-parser.js'
export { UpdateObject } from './parser/update-set-parser.js'
export {
OrderByExpression,
OrderByDirectionExpression,
Expand Down
12 changes: 6 additions & 6 deletions src/parser/update-set-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { ColumnUpdateNode } from '../operation-node/column-update-node.js'
import { UpdateKeys, UpdateType } from '../util/column-type.js'
import { parseValueExpression, ValueExpression } from './value-parser.js'

export type MutationObject<DB, TB extends keyof DB, TM extends keyof DB> = {
[C in UpdateKeys<DB[TM]>]?:
| ValueExpression<DB, TB, UpdateType<DB[TM][C]>>
export type UpdateObject<DB, TB extends keyof DB, UT extends keyof DB> = {
[C in UpdateKeys<DB[UT]>]?:
| ValueExpression<DB, TB, UpdateType<DB[UT][C]>>
| undefined
}

export function parseUpdateObject(
row: MutationObject<any, any, any>
update: UpdateObject<any, any, any>
): ReadonlyArray<ColumnUpdateNode> {
return Object.entries(row)
return Object.entries(update)
.filter(([_, value]) => value !== undefined)
.map(([key, value]) => {
return ColumnUpdateNode.create(
ColumnNode.create(key),
parseValueExpression(value!)
parseValueExpression(value)
)
})
}
4 changes: 2 additions & 2 deletions src/query-builder/insert-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { InsertQueryNode } from '../operation-node/insert-query-node.js'
import { QueryNode } from '../operation-node/query-node.js'
import { MergePartial, SingleResultType } from '../util/type-utils.js'
import {
MutationObject,
UpdateObject,
parseUpdateObject,
} from '../parser/update-set-parser.js'
import { preventAwait } from '../util/prevent-await.js'
Expand Down Expand Up @@ -483,7 +483,7 @@ export class InsertQueryBuilder<DB, TB extends keyof DB, O>
* ```
*/
onDuplicateKeyUpdate(
updates: MutationObject<DB, TB, TB>
updates: UpdateObject<DB, TB, TB>
): InsertQueryBuilder<DB, TB, O> {
return new InsertQueryBuilder({
...this.#props,
Expand Down
4 changes: 2 additions & 2 deletions src/query-builder/on-conflict-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
parseNotExists,
} from '../parser/unary-operation-parser.js'
import {
MutationObject,
UpdateObject,
parseUpdateObject,
} from '../parser/update-set-parser.js'
import { freeze } from '../util/object-utils.js'
Expand Down Expand Up @@ -325,7 +325,7 @@ export class OnConflictBuilder<DB, TB extends keyof DB>
* ```
*/
doUpdateSet(
updates: MutationObject<
updates: UpdateObject<
OnConflictDatabase<DB, TB>,
OnConflictTables<TB>,
OnConflictTables<TB>
Expand Down
7 changes: 2 additions & 5 deletions src/query-builder/update-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import { ReferenceExpression } from '../parser/reference-parser.js'
import { QueryNode } from '../operation-node/query-node.js'
import { MergePartial, Nullable, SingleResultType } from '../util/type-utils.js'
import { UpdateQueryNode } from '../operation-node/update-query-node.js'
import {
MutationObject,
parseUpdateObject,
} from '../parser/update-set-parser.js'
import { UpdateObject, parseUpdateObject } from '../parser/update-set-parser.js'
import { preventAwait } from '../util/prevent-await.js'
import { Compilable } from '../util/compilable.js'
import { QueryExecutor } from '../query-executor/query-executor.js'
Expand Down Expand Up @@ -540,7 +537,7 @@ export class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O>
* where "id" = $4
* ```
*/
set(row: MutationObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O> {
set(row: UpdateObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O> {
return new UpdateQueryBuilder({
...this.#props,
queryNode: UpdateQueryNode.cloneWithUpdates(
Expand Down

0 comments on commit d57ead2

Please sign in to comment.