@contember/database
Advanced tools
Comparing version 0.10.2 to 0.11.0-alpha.0
@@ -19,2 +19,3 @@ import { SelectBuilder } from './SelectBuilder'; | ||
private compileJoin; | ||
private compileDistinctStatement; | ||
private compileSelectStatement; | ||
@@ -21,0 +22,0 @@ private compileFromStatement; |
@@ -14,2 +14,3 @@ "use strict"; | ||
.appendString(' select') | ||
.append(this.compileDistinctStatement(options.distinct)) | ||
.append(this.compileSelectStatement(options.select)) | ||
@@ -140,2 +141,8 @@ .append(this.compileFromStatement(options.from, namespaceContextFinal)) | ||
} | ||
compileDistinctStatement(distinct) { | ||
if (distinct === undefined) { | ||
return Literal_1.Literal.empty; | ||
} | ||
return new Literal_1.Literal(' distinct').appendAll(distinct, ', ', [' on (', ')']); | ||
} | ||
compileSelectStatement(select) { | ||
@@ -142,0 +149,0 @@ if (select.length > 0) { |
@@ -20,2 +20,3 @@ import { With } from './internal/With'; | ||
from(tableName: string | Literal, alias?: string): SelectBuilder<Result>; | ||
distinct(...on: (QueryBuilder.ColumnIdentifier | QueryBuilder.ColumnExpression)[]): SelectBuilder<Result>; | ||
select(columnName: QueryBuilder.ColumnIdentifier, alias?: string): SelectBuilder<Result>; | ||
@@ -42,2 +43,3 @@ select(callback: QueryBuilder.ColumnExpression, alias?: string): SelectBuilder<Result>; | ||
type Options = Readonly<With.Options & Where.Options & { | ||
distinct?: Literal[]; | ||
select: Literal[]; | ||
@@ -44,0 +46,0 @@ limit: [number | undefined, number | undefined]; |
@@ -53,2 +53,6 @@ "use strict"; | ||
} | ||
distinct(...on) { | ||
const onLiterals = on.map(utils_2.columnExpressionToLiteral).filter((it) => it !== undefined); | ||
return this.withOption('distinct', onLiterals); | ||
} | ||
select(expr, alias) { | ||
@@ -55,0 +59,0 @@ let raw = utils_2.columnExpressionToLiteral(expr); |
@@ -11,2 +11,5 @@ "use strict"; | ||
append(literal) { | ||
if (literal === Literal.empty) { | ||
return this; | ||
} | ||
return new Literal(this.sql.trimLeft() + ' ' + literal.sql, [...this.parameters, ...literal.parameters]); | ||
@@ -13,0 +16,0 @@ } |
{ | ||
"name": "@contember/database", | ||
"version": "0.10.2", | ||
"version": "0.11.0-alpha.0", | ||
"license": "Apache-2.0", | ||
@@ -11,6 +11,6 @@ "main": "dist/src/index.js", | ||
"dependencies": { | ||
"@contember/queryable": "^0.10.2" | ||
"@contember/queryable": "^0.11.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@contember/database-tester": "^0.10.2", | ||
"@contember/database-tester": "^0.11.0-alpha.0", | ||
"@types/node": "^14.6.4", | ||
@@ -17,0 +17,0 @@ "pg": "^8.5.0", |
@@ -18,2 +18,3 @@ import { assertNever, aliasLiteral, prependSchema, wrapIdentifier } from '../utils' | ||
.appendString(' select') | ||
.append(this.compileDistinctStatement(options.distinct)) | ||
.append(this.compileSelectStatement(options.select)) | ||
@@ -174,2 +175,9 @@ .append(this.compileFromStatement(options.from, namespaceContextFinal)) | ||
private compileDistinctStatement(distinct: SelectBuilder.Options['distinct']): Literal { | ||
if (distinct === undefined) { | ||
return Literal.empty | ||
} | ||
return new Literal(' distinct').appendAll(distinct, ', ', [' on (', ')']) | ||
} | ||
private compileSelectStatement(select: SelectBuilder.Options['select']): Literal { | ||
@@ -176,0 +184,0 @@ if (select.length > 0) { |
@@ -65,2 +65,7 @@ import { With } from './internal/With' | ||
public distinct(...on: (QueryBuilder.ColumnIdentifier | QueryBuilder.ColumnExpression)[]): SelectBuilder<Result> { | ||
const onLiterals = on.map(columnExpressionToLiteral).filter((it): it is Literal => it !== undefined) | ||
return this.withOption('distinct', onLiterals) | ||
} | ||
public select(columnName: QueryBuilder.ColumnIdentifier, alias?: string): SelectBuilder<Result> | ||
@@ -179,2 +184,3 @@ public select(callback: QueryBuilder.ColumnExpression, alias?: string): SelectBuilder<Result> | ||
Where.Options & { | ||
distinct?: Literal[] | ||
select: Literal[] | ||
@@ -181,0 +187,0 @@ limit: [number | undefined, number | undefined] |
@@ -11,2 +11,5 @@ export class Literal { | ||
public append(literal: Literal) { | ||
if (literal === Literal.empty) { | ||
return this | ||
} | ||
return new Literal(this.sql.trimLeft() + ' ' + literal.sql, [...this.parameters, ...literal.parameters]) | ||
@@ -13,0 +16,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
775960
5126
+ Added@contember/queryable@0.11.5(transitive)
- Removed@contember/queryable@0.10.3(transitive)