Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ff00ff/mammoth

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ff00ff/mammoth - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

.build/naming/index.d.ts

3

.build/column.d.ts

@@ -23,2 +23,5 @@ import { Expression } from './expression';

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 ColumnSet<Columns> {
private _columnSetBrand;
}
export declare class Column<Name extends string, TableName, DataType, IsNotNull extends boolean, HasDefault extends boolean, JoinType> extends Expression<DataType, IsNotNull, Name> {

@@ -25,0 +28,0 @@ private readonly columnName;

50

.build/column.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Column = exports.makeColumnDefinition = void 0;
exports.Column = exports.ColumnSet = exports.makeColumnDefinition = void 0;
const tokens_1 = require("./tokens");
const snake_case_1 = require("./naming/snake-case");
const naming_1 = require("./naming");
const expression_1 = require("./expression");
exports.makeColumnDefinition = (dataType, enumValues) => {
const makeColumnDefinition = (dataType, enumValues) => {
let isNotNull = false;

@@ -56,7 +56,20 @@ let isPrimaryKey = false;

};
exports.makeColumnDefinition = makeColumnDefinition;
// This is only used as a nominal type, not actually as an instance.
class ColumnSet {
/** @internal */
toTokens() {
return [];
}
}
exports.ColumnSet = ColumnSet;
class Column extends expression_1.Expression {
constructor(columnName, tableName, originalColumnName) {
super(originalColumnName
? [new tokens_1.StringToken(`${tableName}.${snake_case_1.toSnakeCase(originalColumnName)}`)]
: [new tokens_1.StringToken(`${tableName}.${snake_case_1.toSnakeCase(columnName)}`)], columnName);
? [
new tokens_1.StringToken(`${naming_1.wrapQuotes(tableName)}.${naming_1.wrapQuotes(naming_1.toSnakeCase(originalColumnName))}`),
]
: [
new tokens_1.StringToken(`${naming_1.wrapQuotes(tableName)}.${naming_1.wrapQuotes(naming_1.toSnakeCase(columnName))}`),
], columnName);
this.columnName = columnName;

@@ -68,3 +81,3 @@ this.tableName = tableName;

getSnakeCaseName() {
return snake_case_1.toSnakeCase(this.columnName);
return naming_1.toSnakeCase(this.columnName);
}

@@ -80,21 +93,22 @@ /** @internal */

toTokens(includeAlias) {
const snakeCaseColumnName = snake_case_1.toSnakeCase(this.columnName);
const snakeCaseColumnName = naming_1.toSnakeCase(this.columnName);
const toStringTokens = (tableName, columnName, alias) => {
const initialToken = new tokens_1.StringToken(`${naming_1.wrapQuotes(tableName)}.${naming_1.wrapQuotes(columnName)}`);
if (!alias) {
return [initialToken];
}
return [initialToken, new tokens_1.StringToken(naming_1.wrapQuotes(alias))];
};
if (includeAlias) {
return this.originalColumnName
? [
new tokens_1.StringToken(`${this.tableName}.${snake_case_1.toSnakeCase(this.originalColumnName)}`),
new tokens_1.StringToken(snake_case_1.wrapQuotes(this.columnName)),
]
? toStringTokens(this.tableName, naming_1.toSnakeCase(this.originalColumnName), this.columnName)
: snakeCaseColumnName === this.columnName
? [new tokens_1.StringToken(`${this.tableName}.${snakeCaseColumnName}`)]
: [
new tokens_1.StringToken(`${this.tableName}.${snakeCaseColumnName}`),
new tokens_1.StringToken(snake_case_1.wrapQuotes(this.columnName)),
];
? toStringTokens(this.tableName, snakeCaseColumnName)
: toStringTokens(this.tableName, snakeCaseColumnName, this.columnName);
}
return this.originalColumnName
? [new tokens_1.StringToken(`${this.tableName}.${snake_case_1.toSnakeCase(this.originalColumnName)}`)]
: [new tokens_1.StringToken(`${this.tableName}.${snakeCaseColumnName}`)];
? toStringTokens(this.tableName, naming_1.toSnakeCase(this.originalColumnName))
: toStringTokens(this.tableName, snakeCaseColumnName);
}
}
exports.Column = Column;

@@ -8,6 +8,6 @@ /// <reference types="node" />

export declare function bigint<T>(): ColumnDefinition<T>;
export declare function bigserial(): ColumnDefinition<string>;
export declare function bigserial<T>(): ColumnDefinition<T>;
export declare function serial8(): ColumnDefinition<string>;
export declare function serial8<T>(): ColumnDefinition<T>;
export declare function bigserial(): ColumnDefinition<string, false, true>;
export declare function bigserial<T>(): ColumnDefinition<T, false, true>;
export declare function serial8(): ColumnDefinition<string, false, true>;
export declare function serial8<T>(): ColumnDefinition<T, false, true>;
export declare function bit(n?: number): ColumnDefinition<string>;

@@ -108,10 +108,10 @@ export declare function bit<T>(n?: number): ColumnDefinition<T>;

export declare function int2<T>(): ColumnDefinition<T>;
export declare function serial(): ColumnDefinition<number>;
export declare function serial<T>(): ColumnDefinition<T>;
export declare function serial4(): ColumnDefinition<number>;
export declare function serial4<T>(): ColumnDefinition<T>;
export declare function smallserial(): ColumnDefinition<number>;
export declare function smallserial<T>(): ColumnDefinition<T>;
export declare function serial2(): ColumnDefinition<number>;
export declare function serial2<T>(): ColumnDefinition<T>;
export declare function serial(): ColumnDefinition<number, false, true>;
export declare function serial<T>(): ColumnDefinition<T, false, true>;
export declare function serial4(): ColumnDefinition<number, false, true>;
export declare function serial4<T>(): ColumnDefinition<T, false, true>;
export declare function smallserial(): ColumnDefinition<number, false, true>;
export declare function smallserial<T>(): ColumnDefinition<T, false, true>;
export declare function serial2(): ColumnDefinition<number, false, true>;
export declare function serial2<T>(): ColumnDefinition<T, false, true>;
export declare function text(): ColumnDefinition<string>;

@@ -118,0 +118,0 @@ export declare function text<T>(): ColumnDefinition<T>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
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 = void 0;
const column_1 = require("./column");

@@ -5,0 +6,0 @@ const variableLength = (string, ...n) => n.length > 0 ? `${string}(${n.join(`, `)})` : string;

@@ -0,10 +1,15 @@

import * as sqlFunctions from './sql-functions';
import { Column, ColumnDefinition, ColumnDefinitionFormat } from './column';
import { InsertIntoResult } from './insert';
import { SelectFn } from './select';
import { Table, TableDefinition } from './table';
import { TableDefinition } from './table';
import { CaseStatement } from './case';
import { QueryExecutorFn } from './types';
import { Table } from './TableType';
export declare const defineDb: <TableDefinitions extends {
[key: string]: TableDefinition<any>;
}>(tableDefinitions: TableDefinitions, queryExecutor: QueryExecutorFn) => {
star(): sqlFunctions.Star;
star<T extends unknown>(table: T): T extends Table<any, infer Columns> ? import("./column").ColumnSet<Columns> : never;
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">;

@@ -27,3 +32,3 @@ bitAnd: (expression: import("./expression").Expression<number, boolean, any>) => import("./expression").Expression<number, false, "bitAnd">;

group: (expression: import("./expression").Expression<boolean, boolean, string>) => import("./expression").DefaultExpression<boolean, true>;
any: <T>(array: T[]) => import("./expression").Expression<T, true, "?column?">;
any: <T_1>(array: T_1[]) => import("./expression").Expression<T_1, true, "?column?">;
now: () => import("./expression").Expression<Date, true, "now">;

@@ -44,9 +49,10 @@ exists: (expression: import("./query").Query<any> | import("./expression").Expression<any, any, any>) => import("./expression").DefaultExpression<boolean, true>;

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, 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_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>;
insertInto: <T_2 extends unknown>(table: T_2, columnNames?: (T_2 extends Table<any, infer Columns_1> ? (keyof Columns_1)[] : never) | undefined) => T_2 extends TableDefinition<any> ? never : InsertIntoResult<T_2, T_2 extends Table<any, infer Columns_2> ? { [K_1 in keyof Pick<{ [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }, { [Key in keyof { [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }]-?: { [K in keyof Columns_2]: Columns_2[K] extends Column<any, any, any, infer IsNotNull, infer HasDefault, any> ? HasDefault extends true ? false : IsNotNull : never; }[Key] extends true ? Key : never; }[keyof Columns_2]>]: Columns_2[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_2]: Columns_2[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_2]: Columns_2[K_2] extends Column<any, any, any, boolean, infer HasDefault_1, any> ? HasDefault_1 extends true ? false : false : never; }]-?: { [K_2 in keyof Columns_2]: Columns_2[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_2]>]?: (Columns_2[K_3] extends Column<any, any, infer DataType_6, any, any, any> ? DataType_6 | undefined : never) | undefined; } : never>;
deleteFrom: <T_3 extends unknown>(table: T_3) => T_3 extends TableDefinition<any> ? never : import("./delete").DeleteQuery<T_3, number, T_3 extends Table<any, infer Columns_3> ? Columns_3 : never>;
update: <T_4 extends unknown>(table: T_4) => {
set(values: T_4 extends Table<any, infer Columns_4> ? { [K_4 in keyof Columns_4]?: (Columns_4[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_4, number, T_4 extends Table<any, infer Columns_5> ? Columns_5 : never>;
};
with: import("./with").WithFn;
truncate: <T_5 extends unknown>(table: T_5) => T_5 extends TableDefinition<any> ? never : import("./truncate").TruncateQuery<T_5, number, T_5 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_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; };

@@ -29,13 +29,14 @@ "use strict";

const delete_1 = require("./delete");
const truncate_1 = require("./truncate");
const update_1 = require("./update");
const with_1 = require("./with");
const snake_case_1 = require("./naming/snake-case");
const naming_1 = require("./naming");
const createTables = (tableDefinitions) => {
return Object.keys(tableDefinitions).reduce((tables, key) => {
const tableDefinition = tableDefinitions[key];
tables[key] = table_1.makeTable(snake_case_1.toSnakeCase(key), undefined, tableDefinition);
tables[key] = table_1.makeTable(naming_1.toSnakeCase(key), undefined, tableDefinition);
return tables;
}, {});
};
exports.defineDb = (tableDefinitions, queryExecutor) => {
const defineDb = (tableDefinitions, queryExecutor) => {
return {

@@ -63,2 +64,3 @@ /** @internal */

with: with_1.makeWith(queryExecutor),
truncate: truncate_1.makeTruncate(queryExecutor),
case: () => new case_1.CaseStatement([]),

@@ -69,1 +71,2 @@ ...sqlFunctions,

};
exports.defineDb = defineDb;
import { Token } from './tokens';
import type { GetReturning, QueryExecutorFn, ResultType } from './types';
import type { Table, TableDefinition } from './table';
import { Expression } from './expression';
import { Query } from './query';
import type { ResultSet } from './result-set';
import type { Table } from './TableType';
import type { TableDefinition } from './table';
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>;

@@ -8,0 +9,0 @@ export declare class DeleteQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> {

@@ -6,3 +6,4 @@ "use strict";

const query_1 = require("./query");
exports.makeDeleteFrom = (queryExecutor) => (table) => {
const naming_1 = require("./naming");
const makeDeleteFrom = (queryExecutor) => (table) => {
return new DeleteQuery(queryExecutor, [], table, 'AFFECTED_COUNT', [

@@ -13,2 +14,3 @@ new tokens_1.StringToken(`DELETE FROM`),

};
exports.makeDeleteFrom = makeDeleteFrom;
// https://www.postgresql.org/docs/12/sql-delete.html

@@ -66,6 +68,6 @@ class DeleteQuery extends query_1.Query {

if (alias !== column.getSnakeCaseName()) {
return new tokens_1.StringToken(`${column.getSnakeCaseName()} "${alias}"`);
return new tokens_1.StringToken(`${naming_1.wrapQuotes(column.getSnakeCaseName())} ${naming_1.wrapQuotes(alias)}`);
}
else {
return new tokens_1.StringToken(column.getSnakeCaseName());
return new tokens_1.StringToken(naming_1.wrapQuotes(column.getSnakeCaseName()));
}

@@ -72,0 +74,0 @@ })),

@@ -6,2 +6,3 @@ "use strict";

const tokens_1 = require("./tokens");
const naming_1 = require("./naming");
class Expression {

@@ -277,3 +278,3 @@ constructor(tokens, name, nameIsAlias = false) {

// convert these to camelCase equivalents e.g. stringAgg.
return [...this.tokens, new tokens_1.StringToken(`"${this.name}"`)];
return [...this.tokens, new tokens_1.StringToken(`${naming_1.wrapQuotes(this.name)}`)];
}

@@ -280,0 +281,0 @@ return this.tokens;

export * from './data-types';
export * from './db';
export * from './sql-functions';
export { defineTable } from './table';
export { defineTable, TableRow } from './table';
import { Token } from './tokens';
import { GetReturning, PickByValue, QueryExecutorFn, ResultType } from './types';
import { SelectFn } from './select';
import { Table, TableDefinition } from './table';
import { Column } from './column';

@@ -10,2 +9,4 @@ import { DeleteQuery } from './delete';

import { ResultSet } from './result-set';
import { Table } from './TableType';
import { TableDefinition } from './table';
import { UpdateQuery } from './update';

@@ -12,0 +13,0 @@ export declare class InsertQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> {

@@ -9,2 +9,3 @@ "use strict";

const update_1 = require("./update");
const naming_1 = require("./naming");
// https://www.postgresql.org/docs/12/sql-insert.html

@@ -39,3 +40,3 @@ class InsertQuery extends query_1.Query {

if (alias !== column.getSnakeCaseName()) {
return new tokens_1.StringToken(`${column.getSnakeCaseName()} "${alias}"`);
return new tokens_1.StringToken(`${column.getSnakeCaseName()} ${naming_1.wrapQuotes(alias)}`);
}

@@ -157,3 +158,3 @@ else {

exports.InsertQuery = InsertQuery;
exports.makeInsertInto = (queryExecutor) => (table, columnNames) => {
const makeInsertInto = (queryExecutor) => (table, columnNames) => {
return {

@@ -259,1 +260,2 @@ select: select_1.makeSelect(queryExecutor, [

};
exports.makeInsertInto = makeInsertInto;
import { Token } from './tokens';
import { Table, TableDefinition } from './table';
import { SelectFn } from './SelectFn';
import { Column } from './column';
import { Expression } from './expression';
import { FromItem } from './with';
import { Query } from './query';
import { QueryExecutorFn } from './types';
import { ResultSet } from './result-set';
import { SelectFn } from './SelectFn';
import { Table } from './TableType';
import { TableDefinition } from './table';
export { SelectFn };
declare type ToJoinType<JoinType, NewJoinType extends 'left-join' | 'left-side-of-right-join' | 'full-join'> = Extract<JoinType, 'left-side-of-right-join'> extends never ? NewJoinType : JoinType;
declare type JoinType = 'left-join' | 'left-side-of-right-join' | 'full-join';
declare type ToJoinType<OldType, NewType extends JoinType> = Extract<OldType, 'left-side-of-right-join'> extends never ? NewType : OldType;
declare type GetTableName<T extends Table<any, any>> = T extends Table<infer A, object> ? A : never;

@@ -18,25 +21,32 @@ declare type AddLeftJoin<Columns, JoinTable> = {

};
declare type AddFullJoin<Columns> = {
[K in keyof Columns]: Columns[K] extends Column<infer Name, infer TableName, infer DataType, infer IsNotNull, infer HasDefault, infer JoinType> ? Column<Name, TableName, DataType, IsNotNull, HasDefault, ToJoinType<JoinType, 'full-join'>> : never;
declare type AddJoinType<Columns, NewJoinType extends JoinType> = {
[K in keyof Columns]: Columns[K] extends Column<infer Name, infer TableName, infer DataType, infer IsNotNull, infer HasDefault, infer OldJoinType> ? Column<Name, TableName, DataType, IsNotNull, HasDefault, ToJoinType<OldJoinType, NewJoinType>> : never;
};
declare type Join<Query extends SelectQuery<any>, 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 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;
}> extends Query<Columns> {
}, IncludesStar = false> extends Query<Columns> {
private readonly queryExecutor;
private readonly returningKeys;
private readonly includesStar;
private readonly tokens;
private _selectQueryBrand;
constructor(queryExecutor: QueryExecutorFn, returningKeys: string[], tokens: Token[]);
constructor(queryExecutor: QueryExecutorFn, returningKeys: string[], includesStar: boolean, tokens: Token[]);
then(onFulfilled?: ((value: ResultSet<SelectQuery<Columns>, false>[]) => any | PromiseLike<any>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>;
private newSelectQuery;
from<T extends Table<any, any>>(fromItem: T): T extends TableDefinition<any> ? never : SelectQuery<Columns>;
join(table: Table<any, any>): SelectQuery<Columns>;
innerJoin(table: Table<any, any>): SelectQuery<Columns>;
leftOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddLeftJoin<Columns, JoinTable>>;
leftJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddLeftJoin<Columns, JoinTable>>;
rightOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddRightJoin<Columns, JoinTable>>;
rightJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddRightJoin<Columns, JoinTable>>;
fullOuterJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddFullJoin<Columns>>;
fullJoin<JoinTable extends Table<any, any>>(table: JoinTable): SelectQuery<AddFullJoin<Columns>>;
crossJoin(table: Table<any, any>): SelectQuery<Columns>;
from<T extends Table<any, any>>(fromItem: T): T extends TableDefinition<any> ? never : Join<SelectQuery<Columns, IncludesStar>, T>;
private getTableStringToken;
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>;

@@ -46,3 +56,3 @@ forNoKeyUpdate(): SelectQuery<Columns>;

forKeyShare(): SelectQuery<Columns>;
on(joinCondition: Expression<boolean, boolean, string>): SelectQuery<Columns>;
on(joinCondition: Expression<boolean, boolean, string>): SelectQuery<Columns, IncludesStar>;
using(...columns: Column<any, any, any, any, any, any>[]): SelectQuery<Columns>;

@@ -49,0 +59,0 @@ where(condition: Expression<boolean, boolean, string>): SelectQuery<Columns>;

@@ -6,8 +6,11 @@ "use strict";

const query_1 = require("./query");
const sql_functions_1 = require("./sql-functions");
const naming_1 = require("./naming");
// https://www.postgresql.org/docs/12/sql-select.html
class SelectQuery extends query_1.Query {
constructor(queryExecutor, returningKeys, tokens) {
constructor(queryExecutor, returningKeys, includesStar, tokens) {
super();
this.queryExecutor = queryExecutor;
this.returningKeys = returningKeys;
this.includesStar = includesStar;
this.tokens = tokens;

@@ -25,4 +28,10 @@ }

}
newSelectQuery(tokens) {
return new SelectQuery(this.queryExecutor, this.returningKeys, tokens);
newSelectQuery(tokens, table) {
const returningKeys = this.includesStar && table
? [
...this.returningKeys,
...Object.keys(table).filter((name) => ![`as`, `getName`, `getOriginalName`].includes(name)),
]
: this.returningKeys;
return new SelectQuery(this.queryExecutor, returningKeys, this.includesStar, tokens);
}

@@ -32,73 +41,37 @@ // [ FROM from_item [, ...] ]

const table = fromItem;
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`FROM`),
table.getOriginalName()
? new tokens_1.StringToken(`${table.getOriginalName()} "${table.getName()}"`)
: new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`FROM`), this.getTableStringToken(table)], table);
}
getTableStringToken(table) {
if (table.getOriginalName()) {
return new tokens_1.StringToken(`${naming_1.wrapQuotes(table.getOriginalName())} ${naming_1.wrapQuotes(table.getName())}`);
}
return new tokens_1.StringToken(naming_1.wrapQuotes(table.getName()));
}
join(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`JOIN`), this.getTableStringToken(table)], table);
}
innerJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`INNER JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`INNER JOIN`), this.getTableStringToken(table)], table);
}
leftOuterJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`LEFT OUTER JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`LEFT OUTER JOIN`), this.getTableStringToken(table)], table);
}
leftJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`INNER JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`INNER JOIN`), this.getTableStringToken(table)], table);
}
rightOuterJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`RIGHT OUTER JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`RIGHT OUTER JOIN`), this.getTableStringToken(table)], table);
}
rightJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`RIGHT JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`RIGHT JOIN`), this.getTableStringToken(table)], table);
}
fullOuterJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`FULL OUTER JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`FULL OUTER JOIN`), this.getTableStringToken(table)], table);
}
fullJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`FULL JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`FULL JOIN`), this.getTableStringToken(table)], table);
}
// This doesn't go with an ON or USING afterwards
crossJoin(table) {
return this.newSelectQuery([
...this.tokens,
new tokens_1.StringToken(`CROSS JOIN`),
new tokens_1.StringToken(table.getName()),
]);
return this.newSelectQuery([...this.tokens, new tokens_1.StringToken(`CROSS JOIN`), this.getTableStringToken(table)], table);
}

@@ -220,3 +193,4 @@ forUpdate() {

exports.SelectQuery = SelectQuery;
exports.makeSelect = (queryExecutor, initialTokens) => (...columns) => {
const makeSelect = (queryExecutor, initialTokens) => (...columns) => {
const includesStar = !!columns.find((column) => column instanceof sql_functions_1.Star);
const returningKeys = columns.map((column) => {

@@ -226,5 +200,8 @@ if (column instanceof query_1.Query) {

}
if (!column) {
throw new Error(`No column ${columns}`);
}
return column.getName();
});
return new SelectQuery(queryExecutor, returningKeys, [
return new SelectQuery(queryExecutor, returningKeys, includesStar, [
...(initialTokens || []),

@@ -241,1 +218,2 @@ new tokens_1.StringToken(`SELECT`),

};
exports.makeSelect = makeSelect;

@@ -0,3 +1,13 @@

import { StringToken } from './tokens';
import { DefaultExpression, Expression } from './expression';
import { ColumnSet } from './column';
import { Query } from './query';
import { Table } from './TableType';
export declare class Star {
private _starBrand;
toTokens(): StringToken[];
getName(): string;
}
export declare function star(): Star;
export declare function star<T extends Table<any, any>>(table: T): T extends Table<any, infer Columns> ? ColumnSet<Columns> : never;
export declare const stringAgg: (expression: Expression<string, boolean, any>, delimiter: string, ...orderBy: Expression<any, any, any>[]) => Expression<string, false, 'stringAgg'>;

@@ -4,0 +14,0 @@ export declare const bitAnd: (expression: Expression<number, boolean, any>) => Expression<number, false, "bitAnd">;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.coalesce = exports.notExists = exports.andExists = exports.andNotExists = exports.exists = exports.now = exports.any = exports.group = exports.or = exports.and = exports.not = exports.xmlagg = exports.sum = exports.avg = exports.max = exports.min = exports.count = exports.arrayAgg = exports.every = exports.boolOr = exports.boolAnd = exports.bitOr = exports.bitAnd = exports.stringAgg = void 0;
exports.coalesce = exports.notExists = exports.andExists = exports.andNotExists = exports.exists = exports.now = exports.any = exports.group = exports.or = exports.and = exports.not = exports.xmlagg = exports.sum = exports.avg = exports.max = exports.min = exports.count = exports.arrayAgg = exports.every = exports.boolOr = exports.boolAnd = exports.bitOr = exports.bitAnd = exports.stringAgg = exports.star = exports.Star = void 0;
const tokens_1 = require("./tokens");
const expression_1 = require("./expression");
exports.stringAgg = (expression, delimiter, ...orderBy) => {
const naming_1 = require("./naming");
class Star {
toTokens() {
return [new tokens_1.StringToken(`*`)];
}
getName() {
return `*`;
}
}
exports.Star = Star;
function star(table) {
if (table) {
return new expression_1.Expression([new tokens_1.StringToken(`${naming_1.wrapQuotes(table.getName())}.*`)], '');
}
return new Star();
}
exports.star = star;
const stringAgg = (expression, delimiter, ...orderBy) => {
return new expression_1.Expression([

@@ -25,9 +42,16 @@ new tokens_1.StringToken(`string_agg`),

};
exports.bitAnd = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bit_and`), new tokens_1.GroupToken(expression.toTokens(false))], 'bitAnd');
exports.bitOr = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bit_or`), new tokens_1.GroupToken(expression.toTokens(false))], 'bitOr');
exports.boolAnd = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bool_and`), new tokens_1.GroupToken(expression.toTokens(false))], 'boolAnd');
exports.boolOr = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bool_or`), new tokens_1.GroupToken(expression.toTokens(false))], 'boolOr');
exports.every = (expression) => new expression_1.Expression([new tokens_1.StringToken(`every`), new tokens_1.GroupToken(expression.toTokens(false))], 'every');
exports.arrayAgg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`array_agg`), new tokens_1.GroupToken(expression.toTokens(false))], 'arrayAgg');
exports.count = (expression) => {
exports.stringAgg = stringAgg;
const bitAnd = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bit_and`), new tokens_1.GroupToken(expression.toTokens(false))], 'bitAnd');
exports.bitAnd = bitAnd;
const bitOr = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bit_or`), new tokens_1.GroupToken(expression.toTokens(false))], 'bitOr');
exports.bitOr = bitOr;
const boolAnd = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bool_and`), new tokens_1.GroupToken(expression.toTokens(false))], 'boolAnd');
exports.boolAnd = boolAnd;
const boolOr = (expression) => new expression_1.Expression([new tokens_1.StringToken(`bool_or`), new tokens_1.GroupToken(expression.toTokens(false))], 'boolOr');
exports.boolOr = boolOr;
const every = (expression) => new expression_1.Expression([new tokens_1.StringToken(`every`), new tokens_1.GroupToken(expression.toTokens(false))], 'every');
exports.every = every;
const arrayAgg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`array_agg`), new tokens_1.GroupToken(expression.toTokens(false))], 'arrayAgg');
exports.arrayAgg = arrayAgg;
const count = (expression) => {
if (!expression) {

@@ -39,18 +63,34 @@ return new expression_1.Expression([new tokens_1.StringToken(`COUNT(*)`)], 'count');

};
exports.min = (expression) => new expression_1.Expression([new tokens_1.StringToken(`MIN`), new tokens_1.GroupToken(expression.toTokens())], 'min');
exports.max = (expression) => new expression_1.Expression([new tokens_1.StringToken(`MAX`), new tokens_1.GroupToken(expression.toTokens())], 'max');
exports.avg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`AVG`), new tokens_1.GroupToken(expression.toTokens())], 'avg');
exports.sum = (expression) => new expression_1.Expression([new tokens_1.StringToken(`SUM`), new tokens_1.GroupToken(expression.toTokens())], 'sum');
exports.xmlagg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`xmlagg`), new tokens_1.GroupToken(expression.toTokens())], 'xmlagg');
exports.not = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`NOT`), new tokens_1.GroupToken(expression.toTokens())]);
exports.and = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND`), new tokens_1.GroupToken(expression.toTokens())]);
exports.or = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`OR`), new tokens_1.GroupToken(expression.toTokens())]);
exports.group = (expression) => new expression_1.DefaultExpression([new tokens_1.GroupToken(expression.toTokens())]);
exports.any = (array) => new expression_1.Expression([new tokens_1.StringToken(`ANY`), new tokens_1.GroupToken([new tokens_1.ParameterToken(array)])], '?column?');
exports.now = () => new expression_1.Expression([new tokens_1.StringToken(`NOW()`)], 'now');
exports.exists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.andNotExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND NOT EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.andExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.notExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`NOT EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.coalesce = (...expressions) => {
exports.count = count;
const min = (expression) => new expression_1.Expression([new tokens_1.StringToken(`MIN`), new tokens_1.GroupToken(expression.toTokens())], 'min');
exports.min = min;
const max = (expression) => new expression_1.Expression([new tokens_1.StringToken(`MAX`), new tokens_1.GroupToken(expression.toTokens())], 'max');
exports.max = max;
const avg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`AVG`), new tokens_1.GroupToken(expression.toTokens())], 'avg');
exports.avg = avg;
const sum = (expression) => new expression_1.Expression([new tokens_1.StringToken(`SUM`), new tokens_1.GroupToken(expression.toTokens())], 'sum');
exports.sum = sum;
const xmlagg = (expression) => new expression_1.Expression([new tokens_1.StringToken(`xmlagg`), new tokens_1.GroupToken(expression.toTokens())], 'xmlagg');
exports.xmlagg = xmlagg;
const not = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`NOT`), new tokens_1.GroupToken(expression.toTokens())]);
exports.not = not;
const and = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND`), new tokens_1.GroupToken(expression.toTokens())]);
exports.and = and;
const or = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`OR`), new tokens_1.GroupToken(expression.toTokens())]);
exports.or = or;
const group = (expression) => new expression_1.DefaultExpression([new tokens_1.GroupToken(expression.toTokens())]);
exports.group = group;
const any = (array) => new expression_1.Expression([new tokens_1.StringToken(`ANY`), new tokens_1.GroupToken([new tokens_1.ParameterToken(array)])], '?column?');
exports.any = any;
const now = () => new expression_1.Expression([new tokens_1.StringToken(`NOW()`)], 'now');
exports.now = now;
const exists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.exists = exists;
const andNotExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND NOT EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.andNotExists = andNotExists;
const andExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`AND EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.andExists = andExists;
const notExists = (expression) => new expression_1.DefaultExpression([new tokens_1.StringToken(`NOT EXISTS`), new tokens_1.GroupToken(expression.toTokens())]);
exports.notExists = notExists;
const coalesce = (...expressions) => {
return new expression_1.Expression([

@@ -65,1 +105,2 @@ new tokens_1.StringToken(`coalesce`),

};
exports.coalesce = coalesce;
import { Column, ColumnDefinition } from './column';
export declare type TableRow<T> = T extends TableDefinition<infer Columns> ? {
[K in keyof Columns]: Columns[K] extends ColumnDefinition<infer DataType, infer IsNotNull, boolean> ? IsNotNull extends true ? DataType : DataType | undefined : never;
} : never;
export declare class TableDefinition<Columns> {
private _tableDefinitionBrand;
}
export declare type Table<TableName, Columns> = Columns & InternalTable<TableName, Columns>;
interface InternalTable<TableName, Columns> {
as<T>(alias: T): Table<T, {
[K in keyof Columns]: Columns[K] extends Column<infer Name, string, infer DataType, infer IsNotNull, infer HasDefault, infer JoinType> ? Column<Name, T, DataType, IsNotNull, HasDefault, JoinType> : never;
}>;
}
export declare const makeTable: <TableName extends string, TableDefinition_1 extends {

@@ -17,2 +14,3 @@ [column: string]: ColumnDefinition<any, any, any>;

getOriginalName(): string | undefined;
_tableBrand: any;
};

@@ -22,2 +20,1 @@ export declare const defineTable: <Columns extends {

}>(tableDefinition: Columns) => TableDefinition<Columns>;
export {};

@@ -5,10 +5,9 @@ "use strict";

const column_1 = require("./column");
const snake_case_1 = require("./naming/snake-case");
class TableDefinition {
}
exports.TableDefinition = TableDefinition;
exports.makeTable = (tableName, originalTableName, tableDefinition) => {
const makeTable = (tableName, originalTableName, tableDefinition) => {
const columnNames = Object.keys(tableDefinition);
const columns = columnNames.reduce((map, columnName) => {
const column = new column_1.Column(columnName, snake_case_1.wrapQuotes(tableName), undefined);
const column = new column_1.Column(columnName, tableName, undefined);
map[columnName] = column;

@@ -31,4 +30,6 @@ return map;

};
exports.defineTable = (tableDefinition) => {
exports.makeTable = makeTable;
const defineTable = (tableDefinition) => {
return tableDefinition;
};
exports.defineTable = defineTable;

@@ -7,3 +7,3 @@ "use strict";

exports.Token = Token;
exports.createQueryState = (tokens, currentParameterIndex = 0) => {
const createQueryState = (tokens, currentParameterIndex = 0) => {
const initialState = {

@@ -15,1 +15,2 @@ text: [],

};
exports.createQueryState = createQueryState;

@@ -7,3 +7,3 @@ import { Token } from './tokens';

import { ResultSet } from './result-set';
import { Table } from './table';
import { Table } from './TableType';
export declare class UpdateQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> {

@@ -10,0 +10,0 @@ private readonly queryExecutor;

@@ -6,2 +6,3 @@ "use strict";

const query_1 = require("./query");
const naming_1 = require("./naming");
// https://www.postgresql.org/docs/12/sql-update.html

@@ -47,3 +48,5 @@ class UpdateQuery extends query_1.Query {

new tokens_1.StringToken(`FROM`),
new tokens_1.StringToken(fromItem.getName()),
fromItem.getOriginalName()
? new tokens_1.StringToken(`${naming_1.wrapQuotes(fromItem.getOriginalName())} ${naming_1.wrapQuotes(fromItem.getName())}`)
: new tokens_1.StringToken(naming_1.wrapQuotes(fromItem.getName())),
]);

@@ -58,6 +61,6 @@ }

if (alias !== column.getSnakeCaseName()) {
return new tokens_1.StringToken(`${column.getSnakeCaseName()} "${alias}"`);
return new tokens_1.StringToken(`${naming_1.wrapQuotes(column.getSnakeCaseName())} ${naming_1.wrapQuotes(alias)}`);
}
else {
return new tokens_1.StringToken(column.getSnakeCaseName());
return new tokens_1.StringToken(naming_1.wrapQuotes(column.getSnakeCaseName()));
}

@@ -73,4 +76,9 @@ })),

exports.UpdateQuery = UpdateQuery;
exports.makeUpdate = (queryExecutor) => (table) => {
//
const makeUpdate = (queryExecutor) => (table) => {
const getTableStringToken = (table) => {
if (table.getOriginalName()) {
return new tokens_1.StringToken(`${naming_1.wrapQuotes(table.getOriginalName())} ${naming_1.wrapQuotes(table.getName())}`);
}
return new tokens_1.StringToken(naming_1.wrapQuotes(table.getName()));
};
return {

@@ -81,3 +89,3 @@ set(values) {

new tokens_1.StringToken(`UPDATE`),
new tokens_1.StringToken(table.getName()),
getTableStringToken(table),
new tokens_1.StringToken(`SET`),

@@ -88,3 +96,3 @@ new tokens_1.SeparatorToken(`,`, keys.map((key) => {

return new tokens_1.CollectionToken([
new tokens_1.StringToken(column.getSnakeCaseName()),
new tokens_1.StringToken(naming_1.wrapQuotes(column.getSnakeCaseName())),
new tokens_1.StringToken(`=`),

@@ -100,1 +108,2 @@ value && typeof value === `object` && 'toTokens' in value

};
exports.makeUpdate = makeUpdate;

@@ -11,2 +11,5 @@ import { GetDataType, QueryExecutorFn } from './types';

export interface WithFn {
<N1 extends string, W1 extends QueryFn<never>, Q extends Query<any>>(name1: N1, with1: W1, callback: (args: {
[K in N1]: FromItem<W1>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{

@@ -19,4 +22,444 @@ [K in N1]: FromItem<W1>;

}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, N6 extends string, W6 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, name6: N6, with6: W6, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, N6 extends string, W6 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}>, N7 extends string, W7 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, name6: N6, with6: W6, name7: N7, with7: W7, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, N6 extends string, W6 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}>, N7 extends string, W7 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
}>, N8 extends string, W8 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, name6: N6, with6: W6, name7: N7, with7: W7, name8: N8, with8: W8, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, N6 extends string, W6 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}>, N7 extends string, W7 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
}>, N8 extends string, W8 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
}>, N9 extends string, W9 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, name6: N6, with6: W6, name7: N7, with7: W7, name8: N8, with8: W8, name9: N9, with9: W9, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
} & {
[K in N9]: FromItem<W9>;
}) => Q): Q;
<N1 extends string, W1 extends QueryFn<never>, N2 extends string, W2 extends QueryFn<{
[K in N1]: FromItem<W1>;
}>, N3 extends string, W3 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
}>, N4 extends string, W4 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
}>, N5 extends string, W5 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
}>, N6 extends string, W6 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
}>, N7 extends string, W7 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
}>, N8 extends string, W8 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
}>, N9 extends string, W9 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
}>, N10 extends string, W10 extends QueryFn<{
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
} & {
[K in N9]: FromItem<W9>;
}>, Q extends Query<any>>(name1: N1, with1: W1, name2: N2, with2: W2, name3: N3, with3: W3, name4: N4, with4: W4, name5: N5, with5: W5, name6: N6, with6: W6, name7: N7, with7: W7, name8: N8, with8: W8, name9: N9, with9: W9, name10: N10, with10: W10, callback: (args: {
[K in N1]: FromItem<W1>;
} & {
[K in N2]: FromItem<W2>;
} & {
[K in N3]: FromItem<W3>;
} & {
[K in N4]: FromItem<W4>;
} & {
[K in N5]: FromItem<W5>;
} & {
[K in N6]: FromItem<W6>;
} & {
[K in N7]: FromItem<W7>;
} & {
[K in N8]: FromItem<W8>;
} & {
[K in N9]: FromItem<W9>;
} & {
[K in N10]: FromItem<W10>;
}) => Q): Q;
}
export declare const makeWith: (queryExecutor: QueryExecutorFn) => WithFn;
export {};

@@ -8,4 +8,4 @@ "use strict";

const select_1 = require("./select");
const snake_case_1 = require("./naming/snake-case");
exports.makeWith = (queryExecutor) => (...args) => {
const naming_1 = require("./naming");
const makeWith = (queryExecutor) => (...args) => {
const queries = {};

@@ -21,7 +21,7 @@ const createWith = (withFn) => {

...query.getReturningKeys().reduce((fromItem, key) => {
fromItem[key] = new expression_1.Expression([new tokens_1.StringToken(`${snake_case_1.wrapQuotes(name)}.${snake_case_1.wrapQuotes(key)}`)], key);
fromItem[key] = new expression_1.Expression([new tokens_1.StringToken(`${naming_1.wrapQuotes(name)}.${naming_1.wrapQuotes(key)}`)], key);
return fromItem;
}, {}),
getName() {
return snake_case_1.wrapQuotes(name);
return name;
},

@@ -39,3 +39,3 @@ getOriginalName() {

tokens.push(new tokens_1.CollectionToken([
new tokens_1.StringToken(snake_case_1.wrapQuotes(name)),
new tokens_1.StringToken(naming_1.wrapQuotes(name)),
new tokens_1.StringToken(`AS`),

@@ -48,3 +48,8 @@ new tokens_1.GroupToken(withQuery.toTokens()),

const query = callback(queries);
return new select_1.SelectQuery(queryExecutor, [], [new tokens_1.StringToken(`WITH`), new tokens_1.SeparatorToken(`,`, tokens), ...query.toTokens()]);
return new select_1.SelectQuery(queryExecutor, [], false, [
new tokens_1.StringToken(`WITH`),
new tokens_1.SeparatorToken(`,`, tokens),
...query.toTokens(),
]);
};
exports.makeWith = makeWith;
{
"name": "@ff00ff/mammoth",
"license": "MIT",
"version": "1.1.0",
"version": "1.2.0",
"main": "./.build/index.js",

@@ -21,9 +21,9 @@ "types": "./.build/index.d.ts",

"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^14.14.8",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.16",
"dts-jest": "^23.3.0",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.0.5"
"typescript": "^4.1.3"
},

@@ -30,0 +30,0 @@ "scripts": {

@@ -19,3 +19,3 @@ ![Mammoth](https://s3-eu-west-1.amazonaws.com/mammoth-static.ff00ff.nl/mammoth-logo.png)

const rows = await db
.select(db.foo.id, db.bar.name)
.select(star())
.from(db.foo)

@@ -31,4 +31,3 @@ .leftJoin(db.bar)

SELECT
foo.id,
bar.name
*
FROM foo

@@ -40,3 +39,3 @@ LEFT JOIN bar ON (foo.bar_id = bar.id)

More importantly, the resulting type of rows is `{ id: string; name: string | undefined }[]`. Notice how the name is automatically nullable because of the left join.
More importantly, the resulting type of rows is `{ id: string; barId: string; name: string | undefined }[]`. Notice how the name is automatically nullable because of the left join.

@@ -273,2 +272,9 @@ ### Query examples

<details>
<summary>Truncate</summary>
- RESTART IDENTITY
- CASCADE
</details>
## Versioning

@@ -275,0 +281,0 @@

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc