@ff00ff/mammoth
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -12,2 +12,3 @@ import { Expression } from './expression'; | ||
referencesColumn?: string; | ||
enumValues?: string[]; | ||
} | ||
@@ -22,3 +23,3 @@ export interface ColumnDefinition<DataType, IsNotNull extends boolean = false, HasDefault extends boolean = false> { | ||
} | ||
export declare const makeColumnDefinition: <DataType, IsNotNull extends boolean = false, HasDefault extends boolean = false>(dataType: string) => ColumnDefinition<DataType, IsNotNull, HasDefault>; | ||
export declare const makeColumnDefinition: <DataType, IsNotNull extends boolean = false, HasDefault extends boolean = false>(dataType: string, enumValues?: string[] | undefined) => ColumnDefinition<DataType, IsNotNull, HasDefault>; | ||
export declare class Column<Name extends string, TableName, DataType, IsNotNull extends boolean, HasDefault extends boolean, JoinType> extends Expression<DataType, IsNotNull, Name> { | ||
@@ -25,0 +26,0 @@ private readonly columnName; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const expression_1 = require("./expression"); | ||
exports.makeColumnDefinition = (dataType) => { | ||
exports.makeColumnDefinition = (dataType, enumValues) => { | ||
let isNotNull = false; | ||
@@ -27,2 +27,3 @@ let isPrimaryKey = false; | ||
referencesColumn, | ||
enumValues, | ||
}; | ||
@@ -29,0 +30,0 @@ }, |
@@ -141,1 +141,2 @@ /// <reference types="node" /> | ||
export declare function xml<T>(): ColumnDefinition<T>; | ||
export declare function enumType<EnumValue>(name: string, values: readonly EnumValue[]): ColumnDefinition<EnumValue>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.xml = exports.uuid = exports.txidSnapshot = exports.tsvector = exports.tsquery = exports.timestampWithTimeZone = exports.timestampWithoutTimeZone = exports.timestamptz = exports.timestamp = exports.timeWithTimeZone = exports.timeWithoutTimeZone = exports.time = exports.text = exports.serial2 = exports.smallserial = exports.serial4 = exports.serial = exports.int2 = exports.smallint = exports.float4 = exports.real = exports.polygon = exports.pgLsn = exports.path = exports.point = exports.numeric = exports.money = exports.macaddr8 = exports.macaddr = exports.lseg = exports.line = exports.jsonb = exports.json = exports.interval = exports.int4 = exports.int = exports.integer = exports.decimal = exports.inet = exports.float8 = exports.doublePrecision = exports.date = exports.citext = exports.caseInsensitiveText = exports.cidr = exports.circle = exports.varchar = exports.characterVarying = exports.char = exports.character = exports.bytea = exports.box = exports.bool = exports.boolean = exports.varbit = exports.bitVarying = exports.bit = exports.serial8 = exports.bigserial = exports.bigint = exports.int8 = exports.dataType = void 0; | ||
exports.enumType = exports.xml = exports.uuid = exports.txidSnapshot = exports.tsvector = exports.tsquery = exports.timestampWithTimeZone = exports.timestampWithoutTimeZone = exports.timestamptz = exports.timestamp = exports.timeWithTimeZone = exports.timeWithoutTimeZone = exports.time = exports.text = exports.serial2 = exports.smallserial = exports.serial4 = exports.serial = exports.int2 = exports.smallint = exports.float4 = exports.real = exports.polygon = exports.pgLsn = exports.path = exports.point = exports.numeric = exports.money = exports.macaddr8 = exports.macaddr = exports.lseg = exports.line = exports.jsonb = exports.json = exports.interval = exports.int4 = exports.int = exports.integer = exports.decimal = exports.inet = exports.float8 = exports.doublePrecision = exports.date = exports.citext = exports.caseInsensitiveText = exports.cidr = exports.circle = exports.varchar = exports.characterVarying = exports.char = exports.character = exports.bytea = exports.box = exports.bool = exports.boolean = exports.varbit = exports.bitVarying = exports.bit = exports.serial8 = exports.bigserial = exports.bigint = exports.int8 = exports.dataType = void 0; | ||
const column_1 = require("./column"); | ||
@@ -255,1 +255,6 @@ const variableLength = (string, ...n) => n.length > 0 ? `${string}(${n.join(`, `)})` : string; | ||
exports.xml = xml; | ||
// enum is a reserved keyword unfortunately | ||
function enumType(name, values) { | ||
return makeDataType(name, values); | ||
} | ||
exports.enumType = enumType; |
@@ -43,9 +43,9 @@ import { Column, ColumnDefinition, ColumnDefinitionFormat } from './column'; | ||
select: SelectFn; | ||
insertInto: <T_1 extends unknown>(table: T_1, columnNames?: (T_1 extends Table<any, infer Columns> ? (keyof Columns)[] : never) | undefined) => T_1 extends TableDefinition<any> ? never : InsertIntoResult<T_1>; | ||
deleteFrom: <T_2 extends unknown>(table: T_2) => T_2 extends TableDefinition<any> ? never : import("./delete").DeleteQuery<T_2, number, T_2 extends Table<any, infer Columns_1> ? Columns_1 : never>; | ||
insertInto: <T_1 extends unknown>(table: T_1, columnNames?: (T_1 extends Table<any, infer Columns> ? (keyof Columns)[] : never) | undefined) => T_1 extends TableDefinition<any> ? never : InsertIntoResult<T_1, T_1 extends Table<any, infer Columns_1> ? { [K_1 in keyof Pick<{ [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }, { [Key in keyof { [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }]-?: { [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }[Key] extends true ? Key : never; }[keyof Columns_1]>]: Columns_1[K_1] extends Column<any, any, infer DataType_5, any, any, any> ? DataType_5 : never; } & { [K_3 in keyof Pick<{ [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }, { [Key_1 in keyof { [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }]-?: { [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }[Key_1] extends false ? Key_1 : never; }[keyof Columns_1]>]?: (Columns_1[K_3] extends Column<any, any, infer DataType_6, any, any, any> ? DataType_6 | undefined : never) | undefined; } : never>; | ||
deleteFrom: <T_2 extends unknown>(table: T_2) => T_2 extends TableDefinition<any> ? never : import("./delete").DeleteQuery<T_2, number, T_2 extends Table<any, infer Columns_2> ? Columns_2 : never>; | ||
update: <T_3 extends unknown>(table: T_3) => { | ||
set(values: T_3 extends Table<any, infer Columns_2> ? { [K in keyof Columns_2]?: (Columns_2[K] extends Column<any, any, infer DataType_5, infer IsNotNull, any, any> ? IsNotNull extends true ? DataType_5 | import("./expression").Expression<DataType_5, boolean, any> : DataType_5 | import("./expression").Expression<DataType_5 | undefined, boolean, any> | undefined : never) | undefined; } : never): import("./update").UpdateQuery<T_3, number, T_3 extends Table<any, infer Columns_3> ? Columns_3 : never>; | ||
set(values: T_3 extends Table<any, infer Columns_3> ? { [K_4 in keyof Columns_3]?: (Columns_3[K_4] extends Column<any, any, infer DataType_7, infer IsNotNull_1, any, any> ? IsNotNull_1 extends true ? DataType_7 | import("./expression").Expression<DataType_7, boolean, any> : DataType_7 | import("./expression").Expression<DataType_7 | undefined, boolean, any> | undefined : never) | undefined; } : never): import("./update").UpdateQuery<T_3, number, T_3 extends Table<any, infer Columns_4> ? Columns_4 : never>; | ||
}; | ||
with: import("./with").WithFn; | ||
case: () => CaseStatement<never>; | ||
} & { [TableName in keyof TableDefinitions]: TableDefinitions[TableName] extends TableDefinition<infer ColumnDefinitions> ? Table<TableName, { [K_1 in keyof ColumnDefinitions]: K_1 extends string ? Column<K_1, TableName, ColumnDefinitions[K_1] extends ColumnDefinition<infer DataType_6, any, any> ? DataType_6 : never, ColumnDefinitions[K_1] extends ColumnDefinition<any, infer IsNotNull_1, any> ? IsNotNull_1 : never, ColumnDefinitions[K_1] extends ColumnDefinition<any, any, infer HasDefault> ? HasDefault : never, undefined> : never; }> : 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_8, any, any> ? DataType_8 : never, ColumnDefinitions[K_5] extends ColumnDefinition<any, infer IsNotNull_2, any> ? IsNotNull_2 : never, ColumnDefinitions[K_5] extends ColumnDefinition<any, any, infer HasDefault_2> ? HasDefault_2 : never, undefined> : never; }> : never; }; |
@@ -40,3 +40,11 @@ import { Token } from './tokens'; | ||
} | ||
export interface InsertIntoResult<T extends Table<any, any>> { | ||
export interface InsertIntoResult<T extends Table<any, any>, Row = T extends Table<any, infer Columns> ? { | ||
[K in keyof PickByValue<{ | ||
[K in keyof Columns]: Columns[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; | ||
}, true>]: Columns[K] extends Column<any, any, infer DataType, any, any, any> ? DataType : never; | ||
} & { | ||
[K in keyof PickByValue<{ | ||
[K in keyof Columns]: Columns[K] extends Column<any, any, any, boolean, infer HasDefault, any> ? HasDefault extends true ? false : false : never; | ||
}, false>]?: Columns[K] extends Column<any, any, infer DataType, any, any, any> ? DataType | undefined : never; | ||
} : never> { | ||
select: SelectFn; | ||
@@ -50,12 +58,4 @@ deleteFrom<DeleteTable extends Table<any, any>>(deleteTable: DeleteTable): DeleteQuery<DeleteTable, number>; | ||
defaultValues(): InsertQuery<T, number>; | ||
values(values: T extends Table<any, infer Columns> ? { | ||
[K in keyof PickByValue<{ | ||
[K in keyof Columns]: Columns[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; | ||
}, true>]: Columns[K] extends Column<any, any, infer DataType, any, any, any> ? DataType : never; | ||
} & { | ||
[K in keyof PickByValue<{ | ||
[K in keyof Columns]: Columns[K] extends Column<any, any, any, boolean, infer HasDefault, any> ? HasDefault extends true ? false : false : never; | ||
}, false>]?: Columns[K] extends Column<any, any, infer DataType, any, any, any> ? DataType | undefined : never; | ||
} : never): InsertQuery<T, number>; | ||
values(values: Row | Row[]): InsertQuery<T, number>; | ||
} | ||
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>; | ||
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 Pick<{ [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }, { [Key in keyof { [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }]-?: { [K in keyof Columns_1]: Columns_1[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }[Key] extends true ? Key : never; }[keyof Columns_1]>]: Columns_1[K_1] extends Column<any, any, infer DataType, any, any, any> ? DataType : never; } & { [K_3 in keyof Pick<{ [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }, { [Key_1 in keyof { [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }]-?: { [K_2 in keyof Columns_1]: Columns_1[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }[Key_1] extends false ? Key_1 : never; }[keyof Columns_1]>]?: (Columns_1[K_3] extends Column<any, any, infer DataType_1, any, any, any> ? DataType_1 | undefined : never) | undefined; } : never>; |
@@ -223,3 +223,5 @@ "use strict"; | ||
// a row. | ||
values(values) { | ||
values(listOrItem) { | ||
const list = Array.isArray(listOrItem) ? listOrItem : [listOrItem]; | ||
const [firstItem] = list; | ||
return new InsertQuery(queryExecutor, [], table, 'AFFECTED_COUNT', [ | ||
@@ -229,3 +231,3 @@ new tokens_1.StringToken(`INSERT INTO`), | ||
new tokens_1.GroupToken([ | ||
new tokens_1.SeparatorToken(`,`, Object.keys(values).map((columnName) => { | ||
new tokens_1.SeparatorToken(`,`, Object.keys(firstItem).map((columnName) => { | ||
const column = table[columnName]; | ||
@@ -236,16 +238,18 @@ return new tokens_1.StringToken(column.getSnakeCaseName()); | ||
new tokens_1.StringToken(`VALUES`), | ||
new tokens_1.GroupToken([ | ||
new tokens_1.SeparatorToken(`,`, Object.keys(values).map((columnName) => { | ||
const value = values[columnName]; | ||
if (value && | ||
typeof value === `object` && | ||
'toTokens' in value && | ||
typeof value.toTokens === `function`) { | ||
return new tokens_1.CollectionToken(value.toTokens()); | ||
} | ||
else { | ||
return new tokens_1.ParameterToken(value); | ||
} | ||
})), | ||
]), | ||
new tokens_1.SeparatorToken(',', list.map((values) => { | ||
return new tokens_1.GroupToken([ | ||
new tokens_1.SeparatorToken(`,`, Object.keys(values).map((columnName) => { | ||
const value = values[columnName]; | ||
if (value && | ||
typeof value === `object` && | ||
'toTokens' in value && | ||
typeof value.toTokens === `function`) { | ||
return new tokens_1.CollectionToken(value.toTokens()); | ||
} | ||
else { | ||
return new tokens_1.ParameterToken(value); | ||
} | ||
})), | ||
]); | ||
})), | ||
]); | ||
@@ -252,0 +256,0 @@ }, |
{ | ||
"name": "@ff00ff/mammoth", | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "./.build/index.js", | ||
@@ -22,8 +22,8 @@ "types": "./.build/index.d.ts", | ||
"@types/jest": "^26.0.15", | ||
"@types/node": "^14.14.2", | ||
"@types/node": "^14.14.8", | ||
"dts-jest": "^23.3.0", | ||
"jest": "^26.6.1", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.1.2", | ||
"ts-jest": "^26.4.2", | ||
"typescript": "^4.0.3" | ||
"ts-jest": "^26.4.4", | ||
"typescript": "^4.0.5" | ||
}, | ||
@@ -30,0 +30,0 @@ "scripts": { |
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
295898
3001