@sqb/connect
Advanced tools
Comparing version 4.0.1-beta.33 to 4.0.1-beta.34
import { REPOSITORY_KEY } from './orm.const'; | ||
import { PickReadonly, PickWritable, Type } from '../types'; | ||
import { PickImmutable, PickMutable, Type } from '../types'; | ||
export declare abstract class BaseEntity { | ||
@@ -11,7 +11,7 @@ private [REPOSITORY_KEY]; | ||
export declare function getElementNames<T, K extends keyof T>(classRef: Type<T>): K[]; | ||
export declare function getColumnNames<T, K extends keyof PickWritable<T>>(classRef: Type<T>): K[]; | ||
export declare function getObjectElementNames<T, K extends keyof PickWritable<T>>(classRef: Type<T>): K[]; | ||
export declare function getAssociationElementNames<T, K extends keyof PickReadonly<T>>(classRef: Type<T>): K[]; | ||
export declare function getNonAssociationElementNames<T, K extends keyof PickWritable<T>>(classRef: Type<T>): K[]; | ||
export declare function getInsertColumnNames<T, K extends keyof PickWritable<T>>(classRef: Type<T>): K[]; | ||
export declare function getUpdateColumnNames<T, K extends keyof PickWritable<T>>(classRef: Type<T>): K[]; | ||
export declare function getColumnNames<T, K extends keyof PickMutable<T>>(classRef: Type<T>): K[]; | ||
export declare function getObjectElementNames<T, K extends keyof PickMutable<T>>(classRef: Type<T>): K[]; | ||
export declare function getAssociationElementNames<T, K extends keyof PickImmutable<T>>(classRef: Type<T>): K[]; | ||
export declare function getNonAssociationElementNames<T, K extends keyof PickMutable<T>>(classRef: Type<T>): K[]; | ||
export declare function getInsertColumnNames<T, K extends keyof PickMutable<T>>(classRef: Type<T>): K[]; | ||
export declare function getUpdateColumnNames<T, K extends keyof PickMutable<T>>(classRef: Type<T>): K[]; |
@@ -18,4 +18,4 @@ import type { EntityModel } from '../model/entity-model'; | ||
static execute(args: CreateCommandArgs): Promise<any>; | ||
protected static _prepareParams(ctx: CreateCommandContext, entity: EntityModel, values: any): Promise<void>; | ||
protected static _prepareParams(ctx: CreateCommandContext, entity: EntityModel, values: any, prefix?: string, suffix?: string): Promise<void>; | ||
} | ||
export {}; |
@@ -46,4 +46,6 @@ "use strict"; | ||
} | ||
static async _prepareParams(ctx, entity, values) { | ||
static async _prepareParams(ctx, entity, values, prefix, suffix) { | ||
let v; | ||
prefix = prefix || ''; | ||
suffix = suffix || ''; | ||
for (const col of entity.elements.values()) { | ||
@@ -66,4 +68,5 @@ v = values[col.name]; | ||
col.checkEnumValue(v); | ||
const k = '$input_' + col.fieldName; | ||
ctx.queryValues[col.fieldName] = builder_1.Param({ | ||
const fieldName = prefix + col.fieldName + suffix; | ||
const k = '$input_' + fieldName; | ||
ctx.queryValues[fieldName] = builder_1.Param({ | ||
name: k, | ||
@@ -78,3 +81,3 @@ dataType: col.dataType, | ||
const type = await col.resolveType(); | ||
await this._prepareParams(ctx, type, v); | ||
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix); | ||
} | ||
@@ -81,0 +84,0 @@ } |
@@ -20,4 +20,4 @@ import { EntityModel } from '../model/entity-model'; | ||
protected static _prepareFilter(ctx: UpdateCommandContext, filter: any): Promise<void>; | ||
protected static _prepareParams(ctx: UpdateCommandContext, entity: EntityModel, values: any): Promise<void>; | ||
protected static _prepareParams(ctx: UpdateCommandContext, entity: EntityModel, values: any, prefix?: string, suffix?: string): Promise<void>; | ||
} | ||
export {}; |
@@ -47,6 +47,10 @@ "use strict"; | ||
} | ||
static async _prepareParams(ctx, entity, values) { | ||
static async _prepareParams(ctx, entity, values, prefix, suffix) { | ||
let v; | ||
prefix = prefix || ''; | ||
suffix = suffix || ''; | ||
for (const col of entity.elements.values()) { | ||
v = values[col.name]; | ||
if (v === undefined) | ||
continue; | ||
if (orm_helper_1.isColumnElement(col)) { | ||
@@ -62,4 +66,5 @@ if (col.noUpdate) | ||
col.checkEnumValue(v); | ||
const k = '$input_' + col.fieldName; | ||
ctx.queryValues[col.fieldName] = builder_1.Param({ | ||
const fieldName = prefix + col.fieldName + suffix; | ||
const k = '$input_' + fieldName; | ||
ctx.queryValues[fieldName] = builder_1.Param({ | ||
name: k, | ||
@@ -74,3 +79,3 @@ dataType: col.dataType, | ||
const type = await col.resolveType(); | ||
await this._prepareParams(ctx, type, v); | ||
await this._prepareParams(ctx, type, v, col.fieldNamePrefix, col.fieldNameSuffix); | ||
} | ||
@@ -77,0 +82,0 @@ } |
@@ -6,3 +6,3 @@ import { AsyncEventEmitter } from 'strict-typed-events'; | ||
import { QueryRequest, TransactionFunction } from '../client/types'; | ||
import { Maybe, PartialWritable, Type } from '../types'; | ||
import { Maybe, InstanceValues, Type } from '../types'; | ||
import { FieldInfoMap } from '../client/FieldInfoMap'; | ||
@@ -73,4 +73,4 @@ export declare namespace Repository { | ||
get type(): Type<T>; | ||
create(values: PartialWritable<T>, options?: Repository.CreateOptions): Promise<T>; | ||
createOnly(values: PartialWritable<T>, options?: Repository.CreateOptions): Promise<void>; | ||
create(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<T>; | ||
createOnly(values: InstanceValues<T>, options?: Repository.CreateOptions): Promise<void>; | ||
exists(keyValue: any, options?: Repository.ExistsOptions): Promise<boolean>; | ||
@@ -83,10 +83,10 @@ count(options?: Repository.CountOptions): Promise<number>; | ||
destroyAll(options?: Repository.DestroyOptions): Promise<number>; | ||
update(keyValue: any, values: PartialWritable<T>, options?: Repository.UpdateOptions): Promise<T | undefined>; | ||
updateOnly(keyValue: any, values: PartialWritable<T>, options?: Repository.UpdateOptions): Promise<any>; | ||
updateAll(values: PartialWritable<T>, options?: Repository.UpdateAllOptions): Promise<number>; | ||
update(keyValue: any, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<T | undefined>; | ||
updateOnly(keyValue: any, values: InstanceValues<T>, options?: Repository.UpdateOptions): Promise<any>; | ||
updateAll(values: InstanceValues<T>, options?: Repository.UpdateAllOptions): Promise<number>; | ||
protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>; | ||
protected _create(values: PartialWritable<T>, options: Repository.CreateOptions & { | ||
protected _create(values: InstanceValues<T>, options: Repository.CreateOptions & { | ||
connection: SqbConnection; | ||
}): Promise<T>; | ||
protected _createOnly(values: PartialWritable<T>, options: Repository.CreateOptions & { | ||
protected _createOnly(values: InstanceValues<T>, options: Repository.CreateOptions & { | ||
connection: SqbConnection; | ||
@@ -115,6 +115,6 @@ }): Promise<void>; | ||
}): Promise<number>; | ||
protected _update(keyValue: any, values: PartialWritable<T>, options: Repository.UpdateOptions & { | ||
protected _update(keyValue: any, values: InstanceValues<T>, options: Repository.UpdateOptions & { | ||
connection: SqbConnection; | ||
}): Promise<any>; | ||
protected _updateAll(values: PartialWritable<T>, options: Repository.UpdateAllOptions & { | ||
protected _updateAll(values: InstanceValues<T>, options: Repository.UpdateAllOptions & { | ||
connection: SqbConnection; | ||
@@ -121,0 +121,0 @@ }): Promise<number>; |
export declare type Maybe<T> = T | undefined; | ||
export interface Type<T = any> extends Function { | ||
export interface Type<T = any> { | ||
new (...args: any[]): T; | ||
} | ||
export declare type Primitive = string | number | boolean | bigint | symbol | undefined | null; | ||
export declare type Builtin = Primitive | Function | Date | Error | RegExp; | ||
export declare type IsTuple<T> = T extends [infer A] ? T : T extends [infer A, infer B] ? T : T extends [infer A, infer B, infer C] ? T : T extends [infer A, infer B, infer C, infer D] ? T : T extends [infer A, infer B, infer C, infer D, infer E] ? T : never; | ||
declare type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B; | ||
@@ -9,9 +12,2 @@ export declare type NonFunctionKeys<T> = { | ||
}[keyof T]; | ||
export declare type NonReadonlyKeys<T> = { | ||
[P in keyof T]-?: IfEquals<{ | ||
[Q in P]: T[P]; | ||
}, { | ||
-readonly [Q in P]: T[P]; | ||
}, P>; | ||
}[keyof T]; | ||
export declare type ReadonlyKeys<T> = { | ||
@@ -24,6 +20,19 @@ [P in keyof T]-?: IfEquals<{ | ||
}[keyof T]; | ||
export declare type WritableKeys<T> = Exclude<NonFunctionKeys<T>, ReadonlyKeys<T>>; | ||
export declare type PickWritable<T> = Pick<T, WritableKeys<T>>; | ||
export declare type PickReadonly<T> = Pick<T, ReadonlyKeys<T>>; | ||
export declare type PartialWritable<T> = Partial<PickWritable<T>>; | ||
export declare type MutableKeys<T> = Exclude<NonFunctionKeys<T>, ReadonlyKeys<T>>; | ||
export declare type ImmutableKeys<T> = Extract<NonFunctionKeys<T>, ReadonlyKeys<T>>; | ||
export declare type PickMutable<T> = Pick<T, MutableKeys<T>>; | ||
export declare type PickImmutable<T> = Pick<T, ImmutableKeys<T>>; | ||
/** Like Partial but recursive */ | ||
export declare type DeepPartial<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepPartial<K>, DeepPartial<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer U> ? Set<DeepPartial<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPartial<U>> : T extends WeakSet<infer U> ? WeakSet<DeepPartial<U>> : T extends (infer U)[] ? T extends IsTuple<T> ? { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
} : (DeepPartial<U>)[] : T extends Promise<infer U> ? Promise<DeepPartial<U>> : T extends {} ? { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
} : Partial<T>; | ||
/** Like PickMutable but recursive */ | ||
export declare type DeepPickMutable<T> = T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepPickMutable<K>, DeepPickMutable<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepPickMutable<K>, DeepPickMutable<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepPickMutable<K>, DeepPickMutable<V>> : T extends Set<infer U> ? Set<DeepPickMutable<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepPickMutable<U>> : T extends WeakSet<infer U> ? WeakSet<DeepPickMutable<U>> : T extends (infer U)[] ? T extends IsTuple<T> ? { | ||
[K in keyof T]?: DeepPickMutable<T[K]>; | ||
} : (DeepPickMutable<U>)[] : T extends Promise<infer U> ? Promise<DeepPickMutable<U>> : T extends {} ? { | ||
[K in keyof T]?: DeepPickMutable<T[K]>; | ||
} : PickMutable<T>; | ||
export declare type InstanceValues<T> = DeepPartial<DeepPickMutable<T>>; | ||
export {}; |
{ | ||
"name": "@sqb/connect", | ||
"description": "Multi-dialect database connection framework written with TypeScript", | ||
"version": "4.0.1-beta.33", | ||
"version": "4.0.1-beta.34", | ||
"author": "Panates Ltd.", | ||
@@ -48,3 +48,3 @@ "contributors": [ | ||
"peerDependencies": { | ||
"@sqb/builder": "^4.0.1-beta.33" | ||
"@sqb/builder": "^4.0.1-beta.34" | ||
}, | ||
@@ -51,0 +51,0 @@ "main": "dist/index.js", |
183784
4571