@ff00ff/mammoth
Advanced tools
Comparing version 1.0.0-rc.2 to 1.0.0-rc.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const to_snap_1 = require("./helpers/to-snap"); | ||
/** @dts-jest enable:test-type */ | ||
@@ -11,5 +12,2 @@ const foo = __1.defineTable(`foo`, { | ||
}); | ||
const toSnap = (query) => { | ||
return undefined; | ||
}; | ||
const db = __1.defineDb(() => Promise.resolve({ rows: [], affectedRowsCount: 0 })); | ||
@@ -19,8 +17,10 @@ // @dts-jest:group delete | ||
// @dts-jest:snap should delete and returning id | ||
toSnap(db.deleteFrom(foo).returning(`id`)); | ||
db.deleteFrom(foo).then(result => { | ||
to_snap_1.toSnap(db.deleteFrom(foo).returning(`id`)); | ||
db.deleteFrom(foo).then((result) => { | ||
// @dts-jest:snap should delete and await affected row count | ||
result; | ||
}); | ||
db.deleteFrom(foo).returning(`id`).then(result => { | ||
db.deleteFrom(foo) | ||
.returning(`id`) | ||
.then((result) => { | ||
// @dts-jest:snap should delete and await rows | ||
@@ -27,0 +27,0 @@ result; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const to_snap_1 = require("./helpers/to-snap"); | ||
/** @dts-jest enable:test-type */ | ||
@@ -11,10 +12,15 @@ const foo = __1.defineTable(`foo`, { | ||
}); | ||
const toSnap = (query) => { | ||
return undefined; | ||
}; | ||
const db = __1.defineDb(() => Promise.resolve({ rows: [], affectedRowsCount: 0 })); | ||
// @dts-jest:group update | ||
// @dts-jest:group insert | ||
{ | ||
// @dts-jest:snap should delete and returning id | ||
toSnap(db.insertInto(foo).values({ name: `Test` })); | ||
// @dts-jest:snap should insert and returning count | ||
to_snap_1.toSnap(db.insertInto(foo).values({ name: `Test` })); | ||
db.insertInto(foo).values({ name: `Test` }).then(result => { | ||
// @dts-jest:snap should insert and await affect count | ||
result; | ||
}); | ||
db.insertInto(foo).values({ name: `Test` }).returning(`name`).then(result => { | ||
// @dts-jest:snap should insert-returning and await rows | ||
result; | ||
}); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const to_snap_1 = require("./helpers/to-snap"); | ||
/** @dts-jest enable:test-type */ | ||
@@ -18,5 +19,2 @@ const foo = __1.defineTable(`foo`, { | ||
}); | ||
const toSnap = (query) => { | ||
return undefined; | ||
}; | ||
const db = __1.defineDb(() => Promise.resolve({ rows: [], affectedRowsCount: 0 })); | ||
@@ -26,22 +24,22 @@ // @dts-jest:group select | ||
// @dts-jest:snap should return null and not null properties | ||
toSnap(db.select(foo.id, foo.createDate, foo.value).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.id, foo.createDate, foo.value).from(foo)); | ||
// @dts-jest:snap should return nullable properties of left joined columns | ||
toSnap(db.select(foo.id, bar.endDate, bar.value).from(foo).leftJoin(bar)); | ||
to_snap_1.toSnap(db.select(foo.id, bar.endDate, bar.value).from(foo).leftJoin(bar)); | ||
// @dts-jest:snap should return nullable properties of left side properties when right joining | ||
toSnap(db.select(foo.name, bar.startDate, bar.value).from(foo).rightJoin(bar)); | ||
to_snap_1.toSnap(db.select(foo.name, bar.startDate, bar.value).from(foo).rightJoin(bar)); | ||
// @dts-jest:snap should return renamed properties because of alias | ||
toSnap(db.select(foo.name.as(`fooName`), foo.value.as(`fooValue`)).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.name.as(`fooName`), foo.value.as(`fooValue`)).from(foo)); | ||
// @dts-jest:snap should return nullable properties of all sides because of full join | ||
toSnap(db.select(foo.name, bar.startDate, bar.value).from(foo).fullJoin(bar)); | ||
to_snap_1.toSnap(db.select(foo.name, bar.startDate, bar.value).from(foo).fullJoin(bar)); | ||
// @dts-jest:snap should select expression | ||
toSnap(db.select(foo.value.plus(1)).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.value.plus(1)).from(foo)); | ||
// @dts-jest:snap should select named expression | ||
toSnap(db.select(foo.value.plus(1).as(`test`)).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.value.plus(1).as(`test`)).from(foo)); | ||
// @dts-jest:snap should select aggregate subquery | ||
toSnap(db.select(foo.id, db.select(__1.count()).from(foo)).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.id, db.select(__1.count()).from(foo)).from(foo)); | ||
// @dts-jest:snap should select null column in subquery | ||
toSnap(db.select(foo.id, db.select(foo.value).from(foo)).from(foo)); | ||
to_snap_1.toSnap(db.select(foo.id, db.select(foo.value).from(foo)).from(foo)); | ||
// @dts-jest:snap should select aggregate with alias | ||
toSnap(db.select(foo.id, __1.sum(foo.value).as(`total`)).from(foo)); | ||
db.select(foo.id).from(foo).then(result => { | ||
to_snap_1.toSnap(db.select(foo.id, __1.sum(foo.value).as(`total`)).from(foo)); | ||
db.select(foo.id, foo.value).from(foo).then(result => { | ||
// @dts-jest:snap should select and await result set | ||
@@ -48,0 +46,0 @@ result; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const __1 = require(".."); | ||
const to_snap_1 = require("./helpers/to-snap"); | ||
/** @dts-jest enable:test-type */ | ||
@@ -11,5 +12,2 @@ const foo = __1.defineTable(`foo`, { | ||
}); | ||
const toSnap = (query) => { | ||
return undefined; | ||
}; | ||
const db = __1.defineDb(() => Promise.resolve({ rows: [], affectedRowsCount: 0 })); | ||
@@ -19,11 +17,15 @@ // @dts-jest:group update | ||
// @dts-jest:snap should update and returning id | ||
toSnap(db.update(foo).set({ name: `Test`, value: 123 }).returning(`id`)); | ||
to_snap_1.toSnap(db.update(foo).set({ name: `Test`, value: 123 }).returning(`id`)); | ||
// @dts-jest:snap should update and returning two columns | ||
toSnap(db.update(foo).set({ name: `Test`, value: 123 }).returning(`id`, `name`)); | ||
to_snap_1.toSnap(db.update(foo).set({ name: `Test`, value: 123 }).returning(`id`, `name`)); | ||
// @dts-jest:snap should update without returning and return number | ||
toSnap(db.update(foo).set({ name: `Test`, value: 123 })); | ||
// @dts-jest:snap should insert into foo with a single required column | ||
db.insertInto(foo).values({ | ||
name: `Test`, | ||
to_snap_1.toSnap(db.update(foo).set({ name: `Test`, value: 123 })); | ||
db.update(foo).set({ name: `Test` }).then((result) => { | ||
// @dts-jest:snap should update and await affected count | ||
result; | ||
}); | ||
db.update(foo).set({ name: `Test` }).returning(`name`).then((result) => { | ||
// @dts-jest:snap should update-returning and await rows | ||
result; | ||
}); | ||
} |
import { Token } from './tokens'; | ||
import type { GetReturning, ResultSet, ResultType } from './types'; | ||
import type { GetReturning, ResultType } from './types'; | ||
import type { Condition } from './condition'; | ||
import { Query } from './query'; | ||
import type { QueryExecutorFn } from './db'; | ||
import type { ResultSet } from './result-set'; | ||
import type { Table } from './table'; | ||
export declare const makeDeleteFrom: (queryExecutor: QueryExecutorFn) => <T extends unknown>(table: T) => 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> { | ||
export declare class DeleteQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
private readonly queryExecutor; | ||
@@ -9,0 +11,0 @@ private readonly table; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const data_1 = require("./data"); | ||
const query_1 = require("./query"); | ||
exports.makeDeleteFrom = (queryExecutor) => (table) => { | ||
@@ -15,4 +16,5 @@ const tableData = data_1.getTableData(table); | ||
// https://www.postgresql.org/docs/12/sql-delete.html | ||
class DeleteQuery { | ||
class DeleteQuery extends query_1.Query { | ||
constructor(queryExecutor, table, resultType, tokens) { | ||
super(); | ||
this.queryExecutor = queryExecutor; | ||
@@ -27,3 +29,5 @@ this.table = table; | ||
.then((result) => onFulfilled | ||
? onFulfilled(this.resultType === `AFFECTED_COUNT` ? result.affectedRowsCount : result.rows) | ||
? onFulfilled(this.resultType === `AFFECTED_COUNT` | ||
? result.affectedRowsCount | ||
: result.rows) | ||
: result) | ||
@@ -30,0 +34,0 @@ .catch(onRejected); |
import { Token } from './tokens'; | ||
import { GetReturning, PickByValue, Query, ResultType } from './types'; | ||
import { GetReturning, PickByValue, ResultType } from './types'; | ||
import { SelectFn } from './select'; | ||
@@ -8,6 +8,8 @@ import { Column } from './column'; | ||
import { Expression } from './expression'; | ||
import { Query } from './query'; | ||
import { QueryExecutorFn } from './db'; | ||
import { ResultSet } from './result-set'; | ||
import { Table } from './table'; | ||
import { UpdateQuery } from './update'; | ||
export declare class InsertQuery<T extends Table<any, any>, Returning, TableColumns = T extends Table<any, infer Columns> ? Columns : never> { | ||
export declare class InsertQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
private readonly queryExecutor; | ||
@@ -19,6 +21,3 @@ private readonly table; | ||
constructor(queryExecutor: QueryExecutorFn, table: T, resultType: ResultType, tokens: Token[]); | ||
then<Result = Returning extends number ? Returning : Returning[]>(onFulfilled?: ((value: Result) => Result | PromiseLike<Result>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<void | { | ||
rows: any[]; | ||
affectedRowsCount: number; | ||
} | Result>; | ||
then(onFulfilled?: ((value: Returning extends number ? Returning : ResultSet<InsertQuery<T, Returning>, false>[]) => any | PromiseLike<any>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>; | ||
returning<C1 extends keyof TableColumns>(column1: C1): InsertQuery<T, GetReturning<TableColumns, C1>>; | ||
@@ -34,10 +33,10 @@ returning<C1 extends keyof TableColumns, C2 extends keyof TableColumns>(column1: C1, column2: C2): InsertQuery<T, GetReturning<TableColumns, C1> & GetReturning<TableColumns, C2>>; | ||
returning<C1 extends keyof TableColumns, C2 extends keyof TableColumns, C3 extends keyof TableColumns, C4 extends keyof TableColumns, C5 extends keyof TableColumns, C6 extends keyof TableColumns, C7 extends keyof TableColumns, C8 extends keyof TableColumns, C9 extends keyof TableColumns, C10 extends keyof TableColumns>(column1: C1, column2: C2, column3: C3, column4: C4, column5: C5, column6: C6, column7: C7, column8: C8, column9: C9, column10: C10): InsertQuery<T, GetReturning<TableColumns, C1> & GetReturning<TableColumns, C2> & GetReturning<TableColumns, C3> & GetReturning<TableColumns, C4> & GetReturning<TableColumns, C5> & GetReturning<TableColumns, C6> & GetReturning<TableColumns, C7> & GetReturning<TableColumns, C8> & GetReturning<TableColumns, C9> & GetReturning<TableColumns, C10>>; | ||
where(condition: Condition): InsertQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
where(condition: Condition): InsertQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
onConflictOnConstraint(constraintName: string): { | ||
doNothing(): InsertQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
doUpdateSet(values: T extends Table<any, infer Columns_1> ? { [K in keyof Columns_1]?: (Columns_1[K] extends Column<any, any, infer DataType, infer IsNotNull, any, any> ? IsNotNull extends true ? import("./select").SelectQuery<any> | DataType | Expression<DataType, IsNotNull> | UpdateQuery<any, any, any> | InsertQuery<any, any, any> | DeleteQuery<any, any, any> : import("./select").SelectQuery<any> | DataType | UpdateQuery<any, any, any> | InsertQuery<any, any, any> | DeleteQuery<any, any, any> | Expression<DataType, IsNotNull> | undefined : never) | undefined; } : never): InsertQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
doNothing(): InsertQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
doUpdateSet(values: T extends Table<any, infer Columns_1> ? { [K in keyof Columns_1]?: (Columns_1[K] extends Column<any, any, infer DataType, infer IsNotNull, any, any> ? IsNotNull extends true ? Query<any> | DataType | Expression<DataType, IsNotNull> : Query<any> | DataType | Expression<DataType, IsNotNull> | undefined : never) | undefined; } : never): InsertQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
}; | ||
onConflict<ColumnNames extends T extends Table<any, infer Columns> ? (keyof Columns)[] : never>(...columnNames: ColumnNames): { | ||
doNothing(): InsertQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
doUpdateSet(values: T extends Table<any, infer Columns_1> ? { [K in keyof Columns_1]?: (Columns_1[K] extends Column<any, any, infer DataType, infer IsNotNull, any, any> ? IsNotNull extends true ? import("./select").SelectQuery<any> | UpdateQuery<any, any, any> | InsertQuery<any, any, any> | DeleteQuery<any, any, any> | DataType | Expression<DataType, IsNotNull> : import("./select").SelectQuery<any> | UpdateQuery<any, any, any> | InsertQuery<any, any, any> | DeleteQuery<any, any, any> | DataType | Expression<DataType, IsNotNull> | undefined : never) | undefined; } : never): InsertQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
doNothing(): InsertQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
doUpdateSet(values: T extends Table<any, infer Columns_1> ? { [K in keyof Columns_1]?: (Columns_1[K] extends Column<any, any, infer DataType, infer IsNotNull, any, any> ? IsNotNull extends true ? Query<any> | DataType | Expression<DataType, IsNotNull> : Query<any> | DataType | Expression<DataType, IsNotNull> | undefined : never) | undefined; } : never): InsertQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
}; | ||
@@ -44,0 +43,0 @@ /** @internal */ |
@@ -8,6 +8,8 @@ "use strict"; | ||
const delete_1 = require("./delete"); | ||
const query_1 = require("./query"); | ||
const update_1 = require("./update"); | ||
// https://www.postgresql.org/docs/12/sql-insert.html | ||
class InsertQuery { | ||
class InsertQuery extends query_1.Query { | ||
constructor(queryExecutor, table, resultType, tokens) { | ||
super(); | ||
this.queryExecutor = queryExecutor; | ||
@@ -14,0 +16,0 @@ this.table = table; |
@@ -5,4 +5,5 @@ import { Token } from './tokens'; | ||
import { Condition } from './condition'; | ||
import { Query } from './query'; | ||
import { QueryExecutorFn } from './db'; | ||
import { ResultSet } from './types'; | ||
import { ResultSet } from './result-set'; | ||
import { Table } from './table'; | ||
@@ -26,3 +27,3 @@ 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; | ||
[column: string]: Selectable; | ||
}> { | ||
}> extends Query<Columns> { | ||
private readonly queryExecutor; | ||
@@ -32,3 +33,3 @@ private readonly tokens; | ||
constructor(queryExecutor: QueryExecutorFn, tokens: Token[]); | ||
then(onFulfilled?: ((value: ResultSet<SelectQuery<Columns>, false>) => any | PromiseLike<any>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>; | ||
then(onFulfilled?: ((value: ResultSet<SelectQuery<Columns>, false>[]) => any | PromiseLike<any>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>; | ||
from<T extends Table<any, any>>(fromItem: T): SelectQuery<Columns>; | ||
@@ -35,0 +36,0 @@ join(table: Table<any, any>): SelectQuery<Columns>; |
@@ -5,6 +5,8 @@ "use strict"; | ||
const tokens_1 = require("./tokens"); | ||
const query_1 = require("./query"); | ||
const data_1 = require("./data"); | ||
// https://www.postgresql.org/docs/12/sql-select.html | ||
class SelectQuery { | ||
class SelectQuery extends query_1.Query { | ||
constructor(queryExecutor, tokens) { | ||
super(); | ||
this.queryExecutor = queryExecutor; | ||
@@ -11,0 +13,0 @@ this.tokens = tokens; |
@@ -1,5 +0,1 @@ | ||
import type { DeleteQuery } from './delete'; | ||
import type { InsertQuery } from './insert'; | ||
import type { SelectQuery } from './select'; | ||
import type { UpdateQuery } from './update'; | ||
export declare type ResultType = 'ROWS' | 'AFFECTED_COUNT'; | ||
@@ -9,3 +5,2 @@ export declare type PickByValue<T, ValueType> = Pick<T, { | ||
}[keyof T]>; | ||
export declare type Query = SelectQuery<any> | UpdateQuery<any, any> | InsertQuery<any, any> | DeleteQuery<any, any>; | ||
export declare type GetReturning<TableColumns, ColumnName extends keyof TableColumns> = { | ||
@@ -17,16 +12,1 @@ [K in ColumnName]: TableColumns[K]; | ||
} | ||
export declare type ResultSetDataType<Type, IsNotNull> = IsNotNull extends true ? Type : Type | undefined; | ||
export declare type ResultSet<T extends Query, Test extends boolean> = T extends SelectQuery<infer Selectables> ? unknown : T extends UpdateQuery<any, infer Returning> ? { | ||
update: true; | ||
} : T extends InsertQuery<any, infer Returning> ? { | ||
insert: true; | ||
} : T extends DeleteQuery<any, infer Returning> ? { | ||
isDeleteQuery: true; | ||
} : { | ||
test: true; | ||
}; | ||
export declare type ResultSet2<T extends Query, Test extends boolean> = T extends SelectQuery<infer Selectables> ? { | ||
test: true; | ||
} : T extends DeleteQuery<any, infer Returning> ? { | ||
test: true; | ||
} : never; |
@@ -6,5 +6,7 @@ import { Token } from './tokens'; | ||
import { Expression } from './expression'; | ||
import { Query } from './query'; | ||
import { QueryExecutorFn } from './db'; | ||
import { ResultSet } from './result-set'; | ||
import { Table } from './table'; | ||
export declare class UpdateQuery<T extends Table<any, any>, Returning, TableColumns = T extends Table<any, infer Columns> ? Columns : never> { | ||
export declare class UpdateQuery<T extends Table<any, any>, Returning = number, TableColumns = T extends Table<any, infer Columns> ? Columns : never> extends Query<Returning> { | ||
private readonly queryExecutor; | ||
@@ -16,5 +18,5 @@ private readonly table; | ||
constructor(queryExecutor: QueryExecutorFn, table: T, resultType: ResultType, tokens: Token[]); | ||
then(onFulfilled?: ((value: Returning extends number ? Returning : Returning[]) => Returning extends number ? Returning : Returning[] | PromiseLike<Returning extends number ? Returning : Returning[]>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>; | ||
then(onFulfilled?: ((value: Returning extends number ? Returning : ResultSet<UpdateQuery<T, Returning>, false>[]) => any | PromiseLike<any>) | undefined | null, onRejected?: ((reason: any) => void | PromiseLike<void>) | undefined | null): Promise<any>; | ||
where(condition: Condition): UpdateQuery<T, Returning>; | ||
whereCurrentOf(cursorName: string): UpdateQuery<T, unknown, T extends Table<any, infer Columns> ? Columns : never>; | ||
whereCurrentOf(cursorName: string): UpdateQuery<T, number, T extends Table<any, infer Columns> ? Columns : never>; | ||
from(fromItem: Table<any, any>): UpdateQuery<T, Returning>; | ||
@@ -21,0 +23,0 @@ returning<C1 extends keyof TableColumns>(column1: C1): UpdateQuery<T, GetReturning<TableColumns, C1>>; |
@@ -6,5 +6,7 @@ "use strict"; | ||
const data_1 = require("./data"); | ||
const query_1 = require("./query"); | ||
// https://www.postgresql.org/docs/12/sql-update.html | ||
class UpdateQuery { | ||
class UpdateQuery extends query_1.Query { | ||
constructor(queryExecutor, table, resultType, tokens) { | ||
super(); | ||
this.queryExecutor = queryExecutor; | ||
@@ -11,0 +13,0 @@ this.table = table; |
{ | ||
"name": "@ff00ff/mammoth", | ||
"license": "MIT", | ||
"version": "1.0.0-rc.2", | ||
"version": "1.0.0-rc.3", | ||
"main": "./.build/index.js", | ||
@@ -6,0 +6,0 @@ "types": "./.build/index.d.ts", |
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
129321
81
2373