@ff00ff/mammoth
Advanced tools
Comparing version 2.0.0-beta.3 to 2.0.0-beta.4
/// <reference types="node" /> | ||
import { ColumnDefinition } from './column'; | ||
export declare type NullType = undefined | null; | ||
export declare type DbDataType = keyof DbDataTypes; | ||
export interface DbDataTypes { | ||
Int4: any; | ||
Int8: any; | ||
Float4: any; | ||
Float8: any; | ||
Numeric: any; | ||
} | ||
export declare type Int4 = 'Int4'; | ||
export declare type Int8 = 'Int8'; | ||
export declare type Float4 = 'Float4'; | ||
export declare type Float8 = 'Float8'; | ||
export declare type Numeric = 'Numeric'; | ||
export declare type Int4 = number; | ||
export declare type Int8 = string; | ||
export declare type Float4 = number; | ||
export declare type Float8 = number; | ||
export declare type Numeric = string; | ||
export declare type AnyNumber = Int4 | Int8 | Float4 | Float8 | Numeric; | ||
@@ -18,0 +9,0 @@ export declare function dataType<T>(dataType: string): ColumnDefinition<T, false, false>; |
@@ -9,77 +9,2 @@ import * as sqlFunctions from './sql-functions'; | ||
import { Table } from './TableType'; | ||
import { DbDataTypes, NullType } from './data-types'; | ||
export interface DbConfiguration { | ||
NullType: NullType; | ||
DataTypes: DbDataTypes; | ||
} | ||
export interface DefaultDbConfiguration extends DbConfiguration { | ||
NullType: null; | ||
DataTypes: { | ||
Int4: number; | ||
Int8: number; | ||
Float4: number; | ||
Float8: number; | ||
Text: string; | ||
Numeric: number; | ||
}; | ||
} | ||
export declare const setup: <Config extends DbConfiguration>() => { | ||
defineDb: <TableDefinitions extends { | ||
[key: string]: TableDefinition<any>; | ||
}>(tableDefinitions: TableDefinitions, queryExecutor: QueryExecutorFn) => { | ||
raw<DataType, IsNotNull extends boolean = false, Name extends string = "?column?">(strings: TemplateStringsArray, ...parameters: any[]): import("./expression").Expression<DataType, IsNotNull, Name>; | ||
star(): sqlFunctions.Star; | ||
star<T extends unknown>(table: T): T extends Table<any, infer Columns> ? import("./column").ColumnSet<Columns> : never; | ||
toSql(query: import("./query").Query<any>): { | ||
text: string; | ||
parameters: any[]; | ||
}; | ||
Star: typeof sqlFunctions.Star; | ||
stringAgg: (expression: import("./expression").Expression<string, boolean, any>, delimiter: string, ...orderBy: import("./expression").Expression<any, any, any>[]) => import("./expression").Expression<string, false, "stringAgg">; | ||
bitAnd: <T_1 extends import("./data-types").AnyNumber>(expression: import("./expression").Expression<T_1, boolean, any>) => import("./expression").Expression<T_1, false, "bitAnd">; | ||
bitOr: <T_2 extends import("./data-types").AnyNumber>(expression: import("./expression").Expression<T_2, boolean, any>) => import("./expression").Expression<T_2, false, "bitOr">; | ||
boolAnd: (expression: import("./expression").Expression<boolean, boolean, any>) => import("./expression").Expression<number, false, "boolAnd">; | ||
boolOr: (expression: import("./expression").Expression<boolean, boolean, any>) => import("./expression").Expression<number, false, "boolOr">; | ||
every: (expression: import("./expression").Expression<boolean, boolean, any>) => import("./expression").Expression<number, false, "every">; | ||
arrayAgg: <DataType_1>(expression: import("./expression").Expression<DataType_1, boolean, any>) => import("./expression").Expression<DataType_1[], false, "arrayAgg">; | ||
count: (expression?: import("./expression").Expression<any, any, any> | undefined) => import("./expression").Expression<"Int8", true, "count">; | ||
min: <DataType_2>(expression: import("./expression").Expression<DataType_2, boolean, any>) => import("./expression").Expression<DataType_2, false, "min">; | ||
max: <DataType_3>(expression: import("./expression").Expression<DataType_3, boolean, any>) => import("./expression").Expression<DataType_3, false, "max">; | ||
avg: <T_3 extends import("./data-types").AnyNumber>(expression: import("./expression").Expression<T_3, boolean, any>) => import("./expression").Expression<T_3, false, "avg">; | ||
sum: <T_4 extends import("./data-types").AnyNumber>(expression: import("./expression").Expression<T_4, boolean, any>) => import("./expression").Expression<T_4, false, "sum">; | ||
xmlagg: <DataType_4>(expression: import("./expression").Expression<DataType_4, boolean, any>) => import("./expression").Expression<number, false, "xmlagg">; | ||
not: (expression: import("./expression").Expression<boolean, boolean, string>) => import("./expression").DefaultExpression<boolean, true>; | ||
and: (expression: import("./expression").Expression<boolean, boolean, string>) => import("./expression").DefaultExpression<boolean, true>; | ||
or: (expression: import("./expression").Expression<boolean, boolean, string>) => import("./expression").DefaultExpression<boolean, true>; | ||
group: (expression: import("./expression").Expression<boolean, boolean, string>) => import("./expression").DefaultExpression<boolean, true>; | ||
any: <T_5>(array: T_5[]) => import("./expression").Expression<T_5, true, "?column?">; | ||
now: () => import("./expression").Expression<Date, true, "now">; | ||
exists: (expression: import("./expression").Expression<any, any, any> | import("./query").Query<any>) => import("./expression").DefaultExpression<boolean, true>; | ||
andNotExists: (expression: import("./expression").Expression<any, any, any> | import("./query").Query<any>) => import("./expression").DefaultExpression<boolean, true>; | ||
andExists: (expression: import("./expression").Expression<any, any, any> | import("./query").Query<any>) => import("./expression").DefaultExpression<boolean, true>; | ||
notExists: (expression: import("./expression").Expression<any, any, any> | import("./query").Query<any>) => import("./expression").DefaultExpression<boolean, true>; | ||
coalesce: <DataType_5>(...expressions: (DataType_5 | import("./expression").Expression<DataType_5, boolean, any>)[]) => import("./expression").Expression<DataType_5, true, "coalesce">; | ||
/** @internal */ | ||
getTableDefinitions(): { | ||
name: string; | ||
originalDefinition: any; | ||
columns: (ColumnDefinitionFormat & { | ||
name: string; | ||
})[]; | ||
}[]; | ||
select: SelectFn<Config>; | ||
insertInto: <T_6 extends unknown>(table: T_6, columnNames?: (T_6 extends Table<any, infer Columns_1> ? (keyof Columns_1)[] : never) | undefined) => T_6 extends TableDefinition<any> ? never : InsertIntoResult<Config, T_6, T_6 extends Table<any, infer Columns_2> ? { [K_1 in keyof import("./types").PickByValue<{ [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull_1, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull_1 : never; }, true>]: Columns_2[K_1] extends Column<any, any, infer DataType_6, boolean, any, any> ? DataType_6 | import("./expression").Expression<DataType_6, boolean, string> | import("./query").Query<{ | ||
[key: string]: DataType_6 | import("./expression").Expression<DataType_6, boolean, string>; | ||
}> : never; } & { [K_3 in keyof import("./types").PickByValue<{ [K_2 in keyof Columns_2]: Columns_2[K_2] extends Column<any, any, any, infer IsNotNull_2, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : IsNotNull_2 : never; }, false>]?: (Columns_2[K_3] extends Column<any, any, infer DataType_7, boolean, any, any> ? DataType_7 | import("./expression").Expression<DataType_7, boolean, string> | import("./query").Query<{ | ||
[key: string]: DataType_7 | import("./expression").Expression<DataType_7, boolean, string>; | ||
}> | undefined : never) | undefined; } : never>; | ||
deleteFrom: <T_7 extends unknown>(table: T_7) => T_7 extends TableDefinition<any> ? never : import("./delete").DeleteQuery<T_7, number, T_7 extends Table<any, infer Columns_3> ? Columns_3 : never>; | ||
update: <T_8 extends unknown>(table: T_8) => { | ||
set(values: T_8 extends Table<any, infer Columns_4> ? { [K_4 in keyof Columns_4]?: (Columns_4[K_4] extends Column<any, any, infer DataType_8, infer IsNotNull_3, any, any> ? IsNotNull_3 extends true ? DataType_8 | import("./expression").Expression<DataType_8, boolean, any> : DataType_8 | import("./expression").Expression<DataType_8 | undefined, boolean, any> | undefined : never) | undefined; } : never): import("./update").UpdateQuery<T_8, number, T_8 extends Table<any, infer Columns_5> ? Columns_5 : never>; | ||
}; | ||
with: import("./with").WithFn; | ||
truncate: <T_9 extends unknown>(table: T_9) => T_9 extends TableDefinition<any> ? never : import("./truncate").TruncateQuery<T_9, number, T_9 extends Table<any, infer Columns_6> ? Columns_6 : never>; | ||
case: () => CaseStatement<never>; | ||
} & { [TableName in keyof TableDefinitions]: TableDefinitions[TableName] extends TableDefinition<infer ColumnDefinitions> ? Table<TableName, { [K_5 in keyof ColumnDefinitions]: K_5 extends string ? Column<K_5, TableName, ColumnDefinitions[K_5] extends ColumnDefinition<infer DataType_9, any, any> ? DataType_9 : never, ColumnDefinitions[K_5] extends ColumnDefinition<any, infer IsNotNull_4, any> ? IsNotNull_4 : never, ColumnDefinitions[K_5] extends ColumnDefinition<any, any, infer HasDefault_2> ? HasDefault_2 : never, undefined> : never; }> : never; }; | ||
}; | ||
export declare const defineDb: <TableDefinitions extends { | ||
@@ -103,3 +28,3 @@ [key: string]: TableDefinition<any>; | ||
arrayAgg: <DataType_1>(expression: import("./expression").Expression<DataType_1, boolean, any>) => import("./expression").Expression<DataType_1[], false, "arrayAgg">; | ||
count: (expression?: import("./expression").Expression<any, any, any> | undefined) => import("./expression").Expression<"Int8", true, "count">; | ||
count: (expression?: import("./expression").Expression<any, any, any> | undefined) => import("./expression").Expression<string, true, "count">; | ||
min: <DataType_2>(expression: import("./expression").Expression<DataType_2, boolean, any>) => import("./expression").Expression<DataType_2, false, "min">; | ||
@@ -129,4 +54,4 @@ max: <DataType_3>(expression: import("./expression").Expression<DataType_3, boolean, any>) => import("./expression").Expression<DataType_3, false, "max">; | ||
}[]; | ||
select: SelectFn<DefaultDbConfiguration>; | ||
insertInto: <T_6 extends unknown>(table: T_6, columnNames?: (T_6 extends Table<any, infer Columns_1> ? (keyof Columns_1)[] : never) | undefined) => T_6 extends TableDefinition<any> ? never : InsertIntoResult<DefaultDbConfiguration, T_6, T_6 extends Table<any, infer Columns_2> ? { [K_1 in keyof import("./types").PickByValue<{ [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull_1, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull_1 : never; }, true>]: Columns_2[K_1] extends Column<any, any, infer DataType_6, boolean, any, any> ? DataType_6 | import("./expression").Expression<DataType_6, boolean, string> | import("./query").Query<{ | ||
select: SelectFn; | ||
insertInto: <T_6 extends unknown>(table: T_6, columnNames?: (T_6 extends Table<any, infer Columns_1> ? (keyof Columns_1)[] : never) | undefined) => T_6 extends TableDefinition<any> ? never : InsertIntoResult<T_6, T_6 extends Table<any, infer Columns_2> ? { [K_1 in keyof import("./types").PickByValue<{ [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull_1, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull_1 : never; }, true>]: Columns_2[K_1] extends Column<any, any, infer DataType_6, boolean, any, any> ? DataType_6 | import("./expression").Expression<DataType_6, boolean, string> | import("./query").Query<{ | ||
[key: string]: DataType_6 | import("./expression").Expression<DataType_6, boolean, string>; | ||
@@ -133,0 +58,0 @@ }> : never; } & { [K_3 in keyof import("./types").PickByValue<{ [K_2 in keyof Columns_2]: Columns_2[K_2] extends Column<any, any, any, infer IsNotNull_2, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : IsNotNull_2 : never; }, false>]?: (Columns_2[K_3] extends Column<any, any, infer DataType_7, boolean, any, any> ? DataType_7 | import("./expression").Expression<DataType_7, boolean, string> | import("./query").Query<{ |
@@ -22,3 +22,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defineDb = exports.setup = void 0; | ||
exports.defineDb = void 0; | ||
const sqlFunctions = __importStar(require("./sql-functions")); | ||
@@ -41,10 +41,4 @@ const insert_1 = require("./insert"); | ||
}; | ||
const setup = () => { | ||
const defineDb = (tableDefinitions, queryExecutor) => { | ||
return { | ||
defineDb: makeDefineDb(), | ||
}; | ||
}; | ||
exports.setup = setup; | ||
const makeDefineDb = () => (tableDefinitions, queryExecutor) => { | ||
return { | ||
/** @internal */ | ||
@@ -77,2 +71,2 @@ getTableDefinitions() { | ||
}; | ||
exports.defineDb = makeDefineDb(); | ||
exports.defineDb = defineDb; |
@@ -8,4 +8,3 @@ import { Token } from './tokens'; | ||
import type { TableDefinition } from './table'; | ||
import type { DbConfiguration } from './db'; | ||
export declare const makeDeleteFrom: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => T extends TableDefinition<any> ? never : DeleteQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
export declare const makeDeleteFrom: (queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => T extends TableDefinition<any> ? never : DeleteQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
export declare class DeleteQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
@@ -12,0 +11,0 @@ private readonly queryExecutor; |
@@ -5,1 +5,2 @@ export * from './data-types'; | ||
export { defineTable, TableRow } from './table'; | ||
export * from './config'; |
@@ -19,1 +19,2 @@ "use strict"; | ||
Object.defineProperty(exports, "defineTable", { enumerable: true, get: function () { return table_1.defineTable; } }); | ||
__exportStar(require("./config"), exports); |
@@ -12,3 +12,2 @@ import { Token } from './tokens'; | ||
import { UpdateQuery } from './update'; | ||
import type { DbConfiguration } from './db'; | ||
export declare class InsertQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
@@ -44,3 +43,3 @@ private readonly queryExecutor; | ||
} | ||
export interface InsertIntoResult<Config extends DbConfiguration, T extends Table<any, any>, Row = T extends Table<any, infer Columns> ? { | ||
export interface InsertIntoResult<T extends Table<any, any>, Row = T extends Table<any, infer Columns> ? { | ||
[K in keyof PickByValue<{ | ||
@@ -58,3 +57,3 @@ [K in keyof Columns]: Columns[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; | ||
} : never> { | ||
select: SelectFn<Config>; | ||
select: SelectFn; | ||
deleteFrom<DeleteTable extends Table<any, any>>(deleteTable: DeleteTable): DeleteQuery<DeleteTable, number>; | ||
@@ -69,3 +68,3 @@ update<UpdateTable extends Table<any, any>>(updateTable: UpdateTable): { | ||
} | ||
export declare const makeInsertInto: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T, columnNames?: (T extends Table<any, infer Columns> ? (keyof Columns)[] : never) | undefined) => T extends TableDefinition<any> ? never : InsertIntoResult<Config, T, T extends Table<any, infer Columns_1> ? { [K_1 in keyof PickByValue<{ [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }, true>]: Columns_1[K_1] extends Column<any, any, infer DataType, boolean, any, any> ? DataType | Expression<DataType, boolean, string> | Query<{ | ||
export declare const makeInsertInto: (queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T, columnNames?: (T extends Table<any, infer Columns> ? (keyof Columns)[] : never) | undefined) => T extends TableDefinition<any> ? never : InsertIntoResult<T, T extends Table<any, infer Columns_1> ? { [K_1 in keyof PickByValue<{ [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }, true>]: Columns_1[K_1] extends Column<any, any, infer DataType, boolean, any, any> ? DataType | Expression<DataType, boolean, string> | Query<{ | ||
[key: string]: DataType | Expression<DataType, boolean, string>; | ||
@@ -72,0 +71,0 @@ }> : never; } & { [K_3 in keyof PickByValue<{ [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, infer IsNotNull_1, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : IsNotNull_1 : never; }, false>]?: (Columns_1[K_3] extends Column<any, any, infer DataType_1, boolean, any, any> ? DataType_1 | Expression<DataType_1, boolean, string> | Query<{ |
import type { Column } from './column'; | ||
import { DefaultDbConfig } from './config'; | ||
import { DeleteQuery } from './delete'; | ||
@@ -9,15 +10,11 @@ import type { Expression } from './expression'; | ||
import { UpdateQuery } from './update'; | ||
import type { DbConfiguration, DefaultDbConfiguration } from './db'; | ||
import { DbDataType } from './data-types'; | ||
declare type GetType<Config extends DbConfiguration, T> = T extends DbDataType ? Config['DataTypes'][T] : T; | ||
export declare type ResultSetDataType<Config extends DbConfiguration, Type, IsNotNull> = IsNotNull extends true ? GetType<Config, Type> : Config['NullType'] extends 'NULL' ? GetType<Config, Type> | null : GetType<Config, Type> | undefined; | ||
export declare type ResultSet<T extends Query<any>, Test extends boolean> = T extends SelectQuery<infer Config, infer Returning> ? { | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<Config, D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<Config, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<Config, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<Config, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<Config, D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<Config, D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
export declare type ResultSetDataType<Type, IsNotNull> = IsNotNull extends true ? Type : Type | DefaultDbConfig['NullType']; | ||
export declare type ResultSet<T extends Query<any>, Test extends boolean> = T extends SelectQuery<infer Returning> ? { | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
} : T extends DeleteQuery<any, infer Returning> ? { | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<DefaultDbConfiguration, D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<DefaultDbConfiguration, D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
} : T extends UpdateQuery<any, infer Returning> ? { | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<DefaultDbConfiguration, D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<DefaultDbConfiguration, D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
} : T extends InsertQuery<any, infer Returning> ? { | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<DefaultDbConfiguration, D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<DefaultDbConfiguration, D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<DefaultDbConfiguration, D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
[K in keyof Returning]: Returning[K] extends Column<any, any, infer D, infer N, any, infer JoinType> ? Extract<JoinType, 'left-join'> extends never ? Extract<JoinType, 'left-side-of-right-join'> extends never ? Extract<JoinType, 'full-join'> extends never ? N extends true ? Test extends true ? GetDataType<D, true> : ResultSetDataType<D, true> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Test extends true ? GetDataType<D, false> : ResultSetDataType<D, false> : Returning[K] extends Expression<infer D, infer IsNotNull, any> ? Test extends true ? GetDataType<D, IsNotNull> : ResultSetDataType<D, IsNotNull> : Returning[K] extends Query<{}> ? ResultSet<Returning[K], Test>[keyof ResultSet<Returning[K], Test>] : never; | ||
} : never; | ||
export {}; |
@@ -11,3 +11,2 @@ import { Token } from './tokens'; | ||
import { TableDefinition } from './table'; | ||
import type { DbConfiguration } from './db'; | ||
export { SelectFn }; | ||
@@ -26,10 +25,10 @@ declare type JoinType = 'left-join' | 'left-side-of-right-join' | 'full-join'; | ||
}; | ||
declare type Join<Query extends SelectQuery<DbConfiguration, any, boolean>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer Config, infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<Config, ExistingColumns & Omit<GetColumns<JoinTable>, keyof ExistingColumns>, true> : SelectQuery<Config, ExistingColumns, false> : never; | ||
declare type Join<Query extends SelectQuery<any, boolean>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<ExistingColumns & Omit<GetColumns<JoinTable>, keyof ExistingColumns>, true> : SelectQuery<ExistingColumns, false> : never; | ||
declare type GetColumns<From extends Table<any, any> | FromItem<any>> = From extends Table<any, infer Columns> ? Columns : From extends FromItem<infer Q> ? Q extends Query<infer Returning> ? Returning : never : never; | ||
declare type LeftJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer Config, infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<Config, ExistingColumns & AddJoinType<GetColumns<JoinTable>, 'left-join'>> : SelectQuery<Config, AddLeftJoin<ExistingColumns, JoinTable>> : never; | ||
declare type RightJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer Config, infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<Config, AddJoinType<ExistingColumns, 'left-side-of-right-join'> & GetColumns<JoinTable>> : SelectQuery<Config, AddRightJoin<ExistingColumns, JoinTable>> : never; | ||
declare type FullJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer Config, infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<Config, AddJoinType<ExistingColumns & GetColumns<JoinTable>, 'full-join'>> : SelectQuery<Config, AddJoinType<ExistingColumns, 'full-join'>> : never; | ||
export declare class SelectQuery<Config extends DbConfiguration, Columns extends { | ||
declare type LeftJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<ExistingColumns & AddJoinType<GetColumns<JoinTable>, 'left-join'>> : SelectQuery<AddLeftJoin<ExistingColumns, JoinTable>> : never; | ||
declare type RightJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<AddJoinType<ExistingColumns, 'left-side-of-right-join'> & GetColumns<JoinTable>> : SelectQuery<AddRightJoin<ExistingColumns, JoinTable>> : never; | ||
declare type FullJoin<Query extends SelectQuery<any>, JoinTable extends Table<any, any> | FromItem<any>> = Query extends SelectQuery<infer ExistingColumns, infer IncludesStar> ? IncludesStar extends true ? SelectQuery<AddJoinType<ExistingColumns & GetColumns<JoinTable>, 'full-join'>> : SelectQuery<AddJoinType<ExistingColumns, 'full-join'>> : never; | ||
export declare class SelectQuery<Columns extends { | ||
[column: string]: any; | ||
} = {}, IncludesStar = false> extends Query<Columns> { | ||
}, IncludesStar = false> extends Query<Columns> { | ||
private readonly queryExecutor; | ||
@@ -41,32 +40,32 @@ private readonly returningKeys; | ||
constructor(queryExecutor: QueryExecutorFn, returningKeys: string[], includesStar: boolean, tokens: Token[]); | ||
then<Result1, Result2 = never>(onFulfilled?: ((value: ResultSet<SelectQuery<Config, Columns>, false>[]) => Result1 | PromiseLike<Result1>) | undefined | null, onRejected?: ((reason: any) => Result2 | PromiseLike<Result2>) | undefined | null): Promise<Result1 | Result2>; | ||
then<Result1, Result2 = never>(onFulfilled?: ((value: ResultSet<SelectQuery<Columns>, false>[]) => Result1 | PromiseLike<Result1>) | undefined | null, onRejected?: ((reason: any) => Result2 | PromiseLike<Result2>) | undefined | null): Promise<Result1 | Result2>; | ||
private newSelectQuery; | ||
from<T extends Table<any, any>>(fromItem: T): T extends TableDefinition<any> ? never : Join<SelectQuery<Config, Columns, IncludesStar>, T>; | ||
join<T extends Table<any, any>>(table: T): Join<SelectQuery<Config, Columns, IncludesStar>, T>; | ||
innerJoin<JoinTable extends Table<string, any>>(table: JoinTable): Join<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
leftOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): LeftJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
leftJoin<JoinTable extends Table<any, any>>(table: JoinTable): LeftJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
rightOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): RightJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
rightJoin<JoinTable extends Table<any, any>>(table: JoinTable): RightJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
fullOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): FullJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
fullJoin<JoinTable extends Table<any, any>>(table: JoinTable): FullJoin<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
crossJoin<JoinTable extends Table<any, any>>(table: Table<any, any>): Join<SelectQuery<Config, Columns, IncludesStar>, JoinTable>; | ||
forUpdate(): SelectQuery<Config, Columns>; | ||
forNoKeyUpdate(): SelectQuery<Config, Columns>; | ||
forShare(): SelectQuery<Config, Columns>; | ||
forKeyShare(): SelectQuery<Config, Columns>; | ||
on(joinCondition: Expression<boolean, boolean, string>): SelectQuery<Config, Columns, IncludesStar>; | ||
using(...columns: Column<any, any, any, any, any, any>[]): SelectQuery<Config, Columns>; | ||
where(condition: Expression<boolean, boolean, string>): SelectQuery<Config, Columns>; | ||
groupBy(...expressions: Expression<any, any, any>[]): SelectQuery<Config, Columns>; | ||
having(...conditions: Expression<boolean, boolean, string>[]): SelectQuery<Config, Columns>; | ||
window(): SelectQuery<Config, Columns>; | ||
orderBy(...expressions: Expression<any, any, any>[]): SelectQuery<Config, Columns>; | ||
limit(limit: number | 'ALL'): SelectQuery<Config, Columns>; | ||
offset(start: number): SelectQuery<Config, Columns>; | ||
fetch(count: number): SelectQuery<Config, Columns>; | ||
of(table: Table<any, any>): SelectQuery<Config, Columns>; | ||
nowait(): SelectQuery<Config, Columns>; | ||
skipLocked(): SelectQuery<Config, Columns>; | ||
from<T extends Table<any, any>>(fromItem: T): T extends TableDefinition<any> ? never : Join<SelectQuery<Columns, IncludesStar>, T>; | ||
join<T extends Table<any, any>>(table: T): Join<SelectQuery<Columns, IncludesStar>, T>; | ||
innerJoin<JoinTable extends Table<string, any>>(table: JoinTable): Join<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
leftOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): LeftJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
leftJoin<JoinTable extends Table<any, any>>(table: JoinTable): LeftJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
rightOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): RightJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
rightJoin<JoinTable extends Table<any, any>>(table: JoinTable): RightJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
fullOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): FullJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
fullJoin<JoinTable extends Table<any, any>>(table: JoinTable): FullJoin<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
crossJoin<JoinTable extends Table<any, any>>(table: Table<any, any>): Join<SelectQuery<Columns, IncludesStar>, JoinTable>; | ||
forUpdate(): SelectQuery<Columns>; | ||
forNoKeyUpdate(): SelectQuery<Columns>; | ||
forShare(): SelectQuery<Columns>; | ||
forKeyShare(): SelectQuery<Columns>; | ||
on(joinCondition: Expression<boolean, boolean, string>): SelectQuery<Columns, IncludesStar>; | ||
using(...columns: Column<any, any, any, any, any, any>[]): SelectQuery<Columns>; | ||
where(condition: Expression<boolean, boolean, string>): SelectQuery<Columns>; | ||
groupBy(...expressions: Expression<any, any, any>[]): SelectQuery<Columns>; | ||
having(...conditions: Expression<boolean, boolean, string>[]): SelectQuery<Columns>; | ||
window(): SelectQuery<Columns>; | ||
orderBy(...expressions: Expression<any, any, any>[]): SelectQuery<Columns>; | ||
limit(limit: number | 'ALL'): SelectQuery<Columns>; | ||
offset(start: number): SelectQuery<Columns>; | ||
fetch(count: number): SelectQuery<Columns>; | ||
of(table: Table<any, any>): SelectQuery<Columns>; | ||
nowait(): SelectQuery<Columns>; | ||
skipLocked(): SelectQuery<Columns>; | ||
} | ||
export declare const makeSelect: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn, initialTokens?: Token[] | undefined) => SelectFn<Config>; | ||
export declare const makeSelect: (queryExecutor: QueryExecutorFn, initialTokens?: Token[] | undefined) => SelectFn; |
import { Column, ColumnSet } from './column'; | ||
import { DbConfiguration } from './db'; | ||
import { Expression } from './expression'; | ||
import { SelectQuery } from './select'; | ||
import { Star } from './sql-functions'; | ||
export declare type GetSelectableName<S> = S extends Column<infer A2, string, any, boolean, boolean, any> ? A2 : S extends Expression<any, boolean, infer A1> ? A1 : S extends SelectQuery<any, infer Columns> ? keyof Columns : never; | ||
export declare type GetSelectableName<S> = S extends Column<infer A2, string, any, boolean, boolean, any> ? A2 : S extends Expression<any, boolean, infer A1> ? A1 : S extends SelectQuery<infer Columns> ? keyof Columns : never; | ||
export declare type GetSelectable<C extends Selectable> = C extends ColumnSet<infer Columns> ? Columns : { | ||
[K in GetSelectableName<C>]: C; | ||
}; | ||
export declare type Selectable = Expression<any, any, any> | SelectQuery<any, any> | Column<any, any, any, boolean, boolean, any> | ColumnSet<any> | Star; | ||
export declare type Selectable = Expression<any, any, any> | SelectQuery<any> | Column<any, any, any, boolean, boolean, any> | ColumnSet<any> | Star; | ||
declare type ContainsStar<Selectables> = Extract<Star, Selectables> extends never ? false : true; | ||
@@ -26,5 +25,5 @@ declare type GetSelectables<Columns extends Array<any>> = { | ||
} ? T : never; | ||
export interface SelectFn<Config extends DbConfiguration> { | ||
<Columns extends Array<Selectable>>(...columns: [...Columns]): SelectQuery<Config, ToColumns<TupleToIntersection<GetSelectables<Columns>>>, ContainsStar<Columns[number]>>; | ||
export interface SelectFn { | ||
<Columns extends Array<Selectable>>(...columns: [...Columns]): SelectQuery<ToColumns<TupleToIntersection<GetSelectables<Columns>>>, ContainsStar<Columns[number]>>; | ||
} | ||
export {}; |
@@ -6,4 +6,3 @@ import { QueryExecutorFn, ResultType } from './types'; | ||
import { TableDefinition } from './table'; | ||
import type { DbConfiguration } from './db'; | ||
export declare const makeTruncate: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => T extends TableDefinition<any> ? never : TruncateQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
export declare const makeTruncate: (queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => T extends TableDefinition<any> ? never : TruncateQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
export declare class TruncateQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
@@ -10,0 +9,0 @@ private readonly queryExecutor; |
@@ -8,3 +8,2 @@ import { Token } from './tokens'; | ||
import { Table } from './TableType'; | ||
import type { DbConfiguration } from './db'; | ||
export declare class UpdateQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
@@ -33,4 +32,4 @@ private readonly queryExecutor; | ||
} | ||
export declare const makeUpdate: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => { | ||
export declare const makeUpdate: (queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => { | ||
set(values: T extends Table<any, infer Columns> ? { [K in keyof Columns]?: (Columns[K] extends Column<any, any, infer DataType, infer IsNotNull, any, any> ? IsNotNull extends true ? DataType | Expression<DataType, boolean, any> : DataType | Expression<DataType | undefined, boolean, any> | undefined : never) | undefined; } : never): UpdateQuery<T, number, T extends Table<any, infer Columns_1> ? Columns_1 : never>; | ||
}; |
@@ -5,3 +5,2 @@ import { GetDataType, QueryExecutorFn } from './types'; | ||
import { ResultSet } from './result-set'; | ||
import type { DbConfiguration } from './db'; | ||
export declare type FromItem<Q> = Q extends Query<any> ? FromItemQuery<Q> : Q extends (args: any) => infer R ? R extends Query<any> ? FromItemQuery<R> : never : never; | ||
@@ -464,3 +463,3 @@ declare type FromItemQuery<Q, Result = Q extends Query<any> ? ResultSet<Q, true> : never> = { | ||
} | ||
export declare const makeWith: <Config extends DbConfiguration>(queryExecutor: QueryExecutorFn) => WithFn; | ||
export declare const makeWith: (queryExecutor: QueryExecutorFn) => WithFn; | ||
export {}; |
{ | ||
"name": "@ff00ff/mammoth", | ||
"license": "MIT", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-beta.4", | ||
"main": "./.build/index.js", | ||
@@ -22,3 +22,3 @@ "types": "./.build/index.d.ts", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.3.3", | ||
"@types/node": "^16.4.4", | ||
"dts-jest": "^23.3.0", | ||
@@ -34,3 +34,3 @@ "jest": "^26.6.3", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
"_prepublishOnly": "npm run build && npm test" | ||
}, | ||
@@ -37,0 +37,0 @@ "jest": { |
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
71
186846
4208