Socket
Socket
Sign inDemoInstall

sql-select-ts

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 1.0.0

es6/classes/common-table-expression.d.ts

6

es6/classes/joined.d.ts

@@ -23,7 +23,7 @@ import { SafeString } from "../safe-string";

*/
on: (on: (fields: Record<Scope, SafeString>) => SafeString | SafeString[]) => Joined<Selection, Scope, Aliases, Ambiguous>;
on: (on: (fields: Record<Scope, SafeString>) => SafeString | ReadonlyArray<SafeString>) => Joined<Selection, Scope, Aliases, Ambiguous>;
/**
* @since 0.0.0
*/
using: (keys: UsingPossibleKeys[]) => Joined<Selection, Scope, Aliases, Ambiguous>;
using: (keys: ReadonlyArray<UsingPossibleKeys>) => Joined<Selection, Scope, Aliases, Ambiguous>;
}

@@ -50,3 +50,3 @@ /**

*/
selectStarOfAliases: <TheAliases extends Aliases>(aliases: TheAliases[]) => SelectStatement<Selection | Scope, RemoveAliasFromSelection<TheAliases, Selection> | RemoveAliasFromSelection<TheAliases, Scope>>;
selectStarOfAliases: <TheAliases extends Aliases>(aliases: readonly TheAliases[]) => SelectStatement<Selection | Scope, RemoveAliasFromSelection<TheAliases, Selection> | RemoveAliasFromSelection<TheAliases, Scope>>;
/**

@@ -53,0 +53,0 @@ * @since 0.0.0

@@ -7,6 +7,3 @@ import { SafeString } from "../safe-string";

import { Table } from "./table";
declare type ReplaceT<Selection extends string> = readonly (readonly [
Selection,
SafeString | number
])[];
declare type ReplaceT<Selection extends string> = ReadonlyArray<readonly [Selection, SafeString | number]>;
/**

@@ -30,2 +27,3 @@ *

private setClickhouseWith;
private setCtes;
private setPrewhere;

@@ -47,3 +45,3 @@ private setHaving;

*/
prewhere: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
prewhere: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -73,7 +71,7 @@ * @since 0.0.0

*/
where: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
where: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**
* @since 0.0.0
*/
having: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
having: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -86,7 +84,7 @@ * @since 0.0.0

*/
orderBy: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
orderBy: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**
* @since 0.0.0
*/
groupBy: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
groupBy: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -93,0 +91,0 @@ * @since 0.0.0

@@ -82,2 +82,10 @@ var __assign = (this && this.__assign) || function () {

};
this.setCtes = function (ctes) {
_this.__props = __assign(__assign({}, _this.__props), { ctes: ctes });
return _this;
};
/**
* @internal
*/
this.__setCtes = this.setCtes;
this.setPrewhere = function (prewhere) {

@@ -320,2 +328,3 @@ _this.__props = __assign(__assign({}, _this.__props), { prewhere: prewhere });

clickhouseWith: [],
ctes: [],
});

@@ -341,2 +350,3 @@ };

clickhouseWith: [],
ctes: [],
});

@@ -343,0 +353,0 @@ };

@@ -11,6 +11,6 @@ import { SafeString } from "./safe-string";

_tag: typeof StarOfAliasSymbolURI;
aliases: string[];
aliases: ReadonlyArray<string>;
};
export declare const isStarOfAliasSymbol: (it: any) => it is StarOfAliasSymbol;
export declare const StarOfAliasesSymbol: (aliases: string[]) => StarOfAliasSymbol;
export declare const StarOfAliasesSymbol: (aliases: ReadonlyArray<string>) => StarOfAliasSymbol;
declare const AliasedRowsURI: "AliasedRows";

@@ -17,0 +17,0 @@ export declare type AliasedRows<Selection extends string> = {

@@ -7,6 +7,8 @@ /**

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { CommonTableExpressionFactory } from "./classes/common-table-expression";
import { SelectStatement } from "./classes/select-statement";
import { Table } from "./classes/table";
import { StringifiedSelectStatement } from "./classes/stringified-select-statement";
import { SafeString } from "./safe-string";
import { NoSelectFieldsCompileError, TableOrSubquery } from "./types";
/**

@@ -25,3 +27,3 @@ *

*/
export declare const fromStringifiedSelectStatement: <NewSelection extends string>(content: import("./safe-string").SafeString) => StringifiedSelectStatement<NewSelection>;
export declare const fromStringifiedSelectStatement: <NewSelection extends string>(content: SafeString) => StringifiedSelectStatement<NewSelection>;
/**

@@ -49,7 +51,15 @@ *

* @category starter
* @since 0.0.0
* @since 1.0.0
*/
export declare const with_: <Selection extends string, Alias extends string>(select: SelectStatement<any, any>, alias: Alias, columns?: Selection[]) => CommonTableExpression<Selection, Alias>;
export declare const with_: <Selection extends string, Alias extends string>(alias: Alias, select: SelectStatement<any, Selection>) => CommonTableExpressionFactory<`${Alias}.${Selection}`, Alias>;
/**
*
* Create a common table expression, renaming the selecion.
*
* @category starter
* @since 1.0.0
*/
export declare const withR: <Selection extends string, Alias extends string>(alias: Alias, columns: readonly Selection[], select: SelectStatement<any, any>) => CommonTableExpressionFactory<`${Alias}.${Selection}`, Alias>;
/**
*
* Select data from no source.

@@ -59,3 +69,3 @@ *

*
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -67,3 +77,3 @@ * assert.strictEqual(q1.stringify(), "SELECT 123 AS `a`");

*/
export declare const fromNothing: <NewSelection extends string>(it: Record<NewSelection, import("./safe-string").SafeString>) => SelectStatement<never, NewSelection>;
export declare const fromNothing: <NewSelection extends string>(it: Record<NewSelection, SafeString>) => SelectStatement<never, NewSelection>;
/**

@@ -73,3 +83,3 @@ * Creates a compound query using 'UNION'

* @example
* import { fromNothing, sql, union } from "sql-select-ts";
* import { fromNothing, dsql as sql, union } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -84,3 +94,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const union: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const union: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -92,3 +102,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, unionAll } from "sql-select-ts";
* import { fromNothing, dsql as sql, unionAll } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -103,3 +113,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const unionAll: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const unionAll: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -111,3 +121,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, intersect } from "sql-select-ts";
* import { fromNothing, dsql as sql, intersect } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -122,3 +132,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const intersect: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const intersect: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -130,3 +140,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, except } from "sql-select-ts";
* import { fromNothing, dsql as sql, except } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -141,3 +151,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const except: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const except: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -151,3 +161,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -168,3 +178,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -185,3 +195,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -198,5 +208,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
sql,
dsql,
/**

@@ -281,1 +291,16 @@ *

RowOf, } from "./ts-helpers";
/**
* Creates a query selecting from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export declare const select: <NewSelection extends string, FromAlias extends string, FromSelection extends string, FromScope extends string, FromAmbigous extends string>(f: (f: Record<FromSelection, SafeString> & NoSelectFieldsCompileError) => Record<NewSelection, SafeString>, from: TableOrSubquery<FromAlias, FromScope, FromSelection, FromAmbigous>) => SelectStatement<FromSelection | FromScope, NewSelection>;
/**
*
* Creates a query selecting all from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export declare const selectStar: <FromAlias extends string, FromSelection extends string, FromScope extends string, FromAmbigous extends string>(from: TableOrSubquery<FromAlias, FromScope, FromSelection, FromAmbigous>) => SelectStatement<FromSelection, FromSelection>;

@@ -7,3 +7,3 @@ /**

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { CommonTableExpressionFactory } from "./classes/common-table-expression";
import { SelectStatement } from "./classes/select-statement";

@@ -48,7 +48,15 @@ import { Table } from "./classes/table";

* @category starter
* @since 0.0.0
* @since 1.0.0
*/
export var with_ = CommonTableExpression.define;
export var with_ = CommonTableExpressionFactory.define;
/**
*
* Create a common table expression, renaming the selecion.
*
* @category starter
* @since 1.0.0
*/
export var withR = CommonTableExpressionFactory.defineRenamed;
/**
*
* Select data from no source.

@@ -58,3 +66,3 @@ *

*
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -71,3 +79,3 @@ * assert.strictEqual(q1.stringify(), "SELECT 123 AS `a`");

* @example
* import { fromNothing, sql, union } from "sql-select-ts";
* import { fromNothing, dsql as sql, union } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -87,3 +95,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, unionAll } from "sql-select-ts";
* import { fromNothing, dsql as sql, unionAll } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -103,3 +111,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, intersect } from "sql-select-ts";
* import { fromNothing, dsql as sql, intersect } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -119,3 +127,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, except } from "sql-select-ts";
* import { fromNothing, dsql as sql, except } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -137,3 +145,3 @@ * const q2 = fromNothing({ a: sql(456) });

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -154,3 +162,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -171,3 +179,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -184,5 +192,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
sql,
dsql,
/**

@@ -200,1 +208,18 @@ *

buildSql, } from "./safe-string";
/**
* Creates a query selecting from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export var select = function (f, from) {
return from.select(f);
};
/**
*
* Creates a query selecting all from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export var selectStar = function (from) { return from.selectStar(); };
import { Compound } from "./classes/compound";
import { SelectStatement } from "./classes/select-statement";
export declare const printCompoundInternal: <Scope extends string, Selection extends string>(compound: Compound<Scope, Selection>, parenthesis: boolean) => PrintInternalRet;
declare type PrintInternalRet = {
content: string;
with_?: string;
};
declare type PrintInternalRet = string;
export declare const printSelectStatementInternal: <Scope extends string, Selection extends string>(selectStatement: SelectStatement<Scope, Selection>, parenthesis: boolean) => PrintInternalRet;

@@ -9,0 +6,0 @@ export declare const printSelectStatement: <Scope extends string, Selection extends string>(it: SelectStatement<Scope, Selection>) => string;

@@ -11,3 +11,2 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { Joined } from "./classes/joined";

@@ -43,3 +42,3 @@ import { SelectStatement } from "./classes/select-statement";

var sel = compound.__props.content
.map(function (it) { return printInternal(it, false).content; })
.map(function (it) { return printInternal(it, false); })
.join(" ".concat(compound.__props.qualifier, " "));

@@ -54,25 +53,13 @@ var q = [

if (parenthesis) {
return { content: "(".concat(q, ")") };
return "(".concat(q, ")");
}
return { content: q };
return q;
};
var printStringifiedSelectInternal = function (it) { return ({
content: "(".concat(it.__props.content.content, ")"),
}); };
var printCteInternal = function (cte) {
var cols = cte.__props.columns.length > 0
? "(".concat(cte.__props.columns.join(", "), ")")
: "";
var content = printInternal(cte.__props.select, false).content;
var with_ = "".concat(cte.__props.alias).concat(cols, " AS (").concat(content, ")");
return { content: cte.__props.alias, with_: with_ };
};
var printStringifiedSelectInternal = function (it) { return "(".concat(it.__props.content.content, ")"); };
var printTableInternal = function (table) {
var final = table.__props.final ? " FINAL" : "";
if (table.__props.name === table.__props.alias) {
return { content: wrapAliasSplitDots(table.__props.name) + final };
return wrapAliasSplitDots(table.__props.name) + final;
}
return {
content: "".concat(wrapAliasSplitDots(table.__props.name), " AS ").concat(wrapAlias(table.__props.alias)).concat(final),
};
return "".concat(wrapAliasSplitDots(table.__props.name), " AS ").concat(wrapAlias(table.__props.alias)).concat(final);
};

@@ -101,3 +88,3 @@ var printConstraint = function (c) {

var printAliasedCode = function (code, alias) {
var str = printInternal(code, true).content;
var str = printInternal(code, true);
if (code instanceof Table) {

@@ -127,6 +114,15 @@ return str;

var content = [head, tail].filter(function (it) { return it.length > 0; }).join(" ");
return {
content: content,
};
return content;
};
var printCtes = function (ctes) {
return ctes
.map(function (cte) {
var cols = cte.columns.length > 0
? "(".concat(cte.columns.map(wrapAliasSplitDots).join(", "), ")")
: "";
var content = printInternal(cte.select, false);
return "".concat(wrapAlias(cte.alias)).concat(cols, " AS (").concat(content, ")");
})
.join(", ");
};
var printClickhouseWith = function (withes) {

@@ -137,3 +133,3 @@ return withes

var k = _a[0], v = _a[1];
return "".concat(printInternal(v, true).content, " AS ").concat(wrapAlias(k));
return "".concat(printInternal(v, true), " AS ").concat(wrapAlias(k));
});

@@ -146,3 +142,2 @@ })

export var printSelectStatementInternal = function (selectStatement, parenthesis) {
var _a;
var selection = selectStatement.__props.selection

@@ -194,7 +189,4 @@ .map(function (it) {

var from = selectStatement.__props.from != null
? "FROM ".concat(printInternal(selectStatement.__props.from, true).content)
? "FROM ".concat(printInternal(selectStatement.__props.from, true))
: "";
var withFromCte = selectStatement.__props.from != null
? (_a = printInternal(selectStatement.__props.from, true).with_) !== null && _a !== void 0 ? _a : ""
: "";
var distinct = selectStatement.__props.distinct ? "DISTINCT" : "";

@@ -204,7 +196,10 @@ var clickhouseWith = selectStatement.__props.clickhouseWith.length > 0

: "";
var withFromCte = selectStatement.__props.ctes.length > 0
? printCtes(selectStatement.__props.ctes)
: "";
var withKeyword = withFromCte.length > 0 || clickhouseWith.length > 0 ? "WITH" : "";
var contentNoParenthesis = [
withKeyword,
clickhouseWith,
withFromCte,
clickhouseWith,
"SELECT",

@@ -227,5 +222,3 @@ distinct,

: contentNoParenthesis;
return {
content: content,
};
return content;
};

@@ -245,5 +238,2 @@ var printInternal = function (it, parenthesis) {

}
if (it instanceof CommonTableExpression) {
return printCteInternal(it);
}
if (it instanceof StringifiedSelectStatement) {

@@ -255,3 +245,3 @@ return printStringifiedSelectInternal(it);

};
export var printSelectStatement = function (it) { return printSelectStatementInternal(it, false).content; };
export var printCompound = function (it) { return printCompoundInternal(it, false).content; };
export var printSelectStatement = function (it) { return printSelectStatementInternal(it, false); };
export var printCompound = function (it) { return printCompoundInternal(it, false); };

@@ -32,3 +32,3 @@ /**

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -47,3 +47,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -106,3 +106,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -119,5 +119,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
export declare const sql: SqlStringBuilder<never[]>;
export declare const dsql: SqlStringBuilder<never[]>;
export {};

@@ -23,3 +23,3 @@ /**

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -41,3 +41,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -82,6 +82,6 @@ * assert.strictEqual(isSafeString(sql(123)), true);

else if (val instanceof SelectStatement) {
return printSelectStatementInternal(val, true).content;
return printSelectStatementInternal(val, true);
}
else if (val instanceof Compound) {
return printCompoundInternal(val, true).content;
return printCompoundInternal(val, true);
}

@@ -171,3 +171,3 @@ else if (Array.isArray(val)) {

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -184,4 +184,4 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
export var sql = buildSql([]);
export var dsql = buildSql([]);

@@ -7,3 +7,2 @@ /**

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { Joined } from "./classes/joined";

@@ -14,3 +13,3 @@ import { SelectStatement } from "./classes/select-statement";

import { SafeString } from "./safe-string";
export declare type TableOrSubquery<Alias extends string, Scope extends string, Selection extends string, Ambiguous extends string> = SelectStatement<Scope, Selection> | StringifiedSelectStatement<Selection> | Table<Alias, Selection> | CommonTableExpression<Alias, Selection> | Joined<Selection, Scope, Alias, Ambiguous> | Compound<Scope, Selection>;
export declare type TableOrSubquery<Alias extends string, Scope extends string, Selection extends string, Ambiguous extends string> = SelectStatement<Scope, Selection> | StringifiedSelectStatement<Selection> | Table<Selection, Alias> | Joined<Selection, Scope, Alias, Ambiguous> | Compound<Scope, Selection>;
export declare type NoSelectFieldsCompileError = {

@@ -25,3 +24,3 @@ ["✕"]: CompileError<["'.select(f => f)' is invalid"]>;

}
export interface NonEmptyArray<A> extends Array<A> {
export interface NonEmptyArray<A> extends ReadonlyArray<A> {
0: A;

@@ -37,4 +36,9 @@ }

_tag: "using";
keys: string[];
keys: ReadonlyArray<string>;
};
export declare type SelectionOfSelectStatement<T> = T extends SelectStatement<infer _Scope, infer Selection> ? Selection : never;
export declare type CTE = {
readonly columns: ReadonlyArray<string>;
readonly alias: string;
readonly select: SelectStatement<any, any>;
};
import { NonEmptyArray } from "./types";
export declare const makeArray: <T>(it: T | T[]) => T[];
export declare const makeNonEmptyArray: <T>(it: T | T[]) => NonEmptyArray<T>;
export declare const makeArray: <T>(it: T | readonly T[]) => readonly T[];
export declare const makeNonEmptyArray: <T>(it: T | readonly T[]) => NonEmptyArray<T>;
export declare const absurd: <A>(_: never) => A;
export declare const hole: <T>() => T;

@@ -5,2 +5,3 @@ export var makeArray = function (it) {

}
// @ts-expect-error - readonly array is array
return [it];

@@ -15,2 +16,3 @@ };

}
// @ts-expect-error - readonly array is array
return [it];

@@ -17,0 +19,0 @@ };

@@ -23,7 +23,7 @@ import { SafeString } from "../safe-string";

*/
on: (on: (fields: Record<Scope, SafeString>) => SafeString | SafeString[]) => Joined<Selection, Scope, Aliases, Ambiguous>;
on: (on: (fields: Record<Scope, SafeString>) => SafeString | ReadonlyArray<SafeString>) => Joined<Selection, Scope, Aliases, Ambiguous>;
/**
* @since 0.0.0
*/
using: (keys: UsingPossibleKeys[]) => Joined<Selection, Scope, Aliases, Ambiguous>;
using: (keys: ReadonlyArray<UsingPossibleKeys>) => Joined<Selection, Scope, Aliases, Ambiguous>;
}

@@ -50,3 +50,3 @@ /**

*/
selectStarOfAliases: <TheAliases extends Aliases>(aliases: TheAliases[]) => SelectStatement<Selection | Scope, RemoveAliasFromSelection<TheAliases, Selection> | RemoveAliasFromSelection<TheAliases, Scope>>;
selectStarOfAliases: <TheAliases extends Aliases>(aliases: readonly TheAliases[]) => SelectStatement<Selection | Scope, RemoveAliasFromSelection<TheAliases, Selection> | RemoveAliasFromSelection<TheAliases, Scope>>;
/**

@@ -53,0 +53,0 @@ * @since 0.0.0

@@ -7,6 +7,3 @@ import { SafeString } from "../safe-string";

import { Table } from "./table";
declare type ReplaceT<Selection extends string> = readonly (readonly [
Selection,
SafeString | number
])[];
declare type ReplaceT<Selection extends string> = ReadonlyArray<readonly [Selection, SafeString | number]>;
/**

@@ -30,2 +27,3 @@ *

private setClickhouseWith;
private setCtes;
private setPrewhere;

@@ -47,3 +45,3 @@ private setHaving;

*/
prewhere: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
prewhere: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -73,7 +71,7 @@ * @since 0.0.0

*/
where: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
where: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**
* @since 0.0.0
*/
having: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
having: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -86,7 +84,7 @@ * @since 0.0.0

*/
orderBy: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
orderBy: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**
* @since 0.0.0
*/
groupBy: (f: (fields: Record<Scope | Selection, SafeString>) => SafeString[] | SafeString) => SelectStatement<Scope, Selection>;
groupBy: (f: (fields: Record<Scope | Selection, SafeString>) => ReadonlyArray<SafeString> | SafeString) => SelectStatement<Scope, Selection>;
/**

@@ -93,0 +91,0 @@ * @since 0.0.0

@@ -85,2 +85,10 @@ "use strict";

};
this.setCtes = function (ctes) {
_this.__props = __assign(__assign({}, _this.__props), { ctes: ctes });
return _this;
};
/**
* @internal
*/
this.__setCtes = this.setCtes;
this.setPrewhere = function (prewhere) {

@@ -323,2 +331,3 @@ _this.__props = __assign(__assign({}, _this.__props), { prewhere: prewhere });

clickhouseWith: [],
ctes: [],
});

@@ -344,2 +353,3 @@ };

clickhouseWith: [],
ctes: [],
});

@@ -346,0 +356,0 @@ };

@@ -11,6 +11,6 @@ import { SafeString } from "./safe-string";

_tag: typeof StarOfAliasSymbolURI;
aliases: string[];
aliases: ReadonlyArray<string>;
};
export declare const isStarOfAliasSymbol: (it: any) => it is StarOfAliasSymbol;
export declare const StarOfAliasesSymbol: (aliases: string[]) => StarOfAliasSymbol;
export declare const StarOfAliasesSymbol: (aliases: ReadonlyArray<string>) => StarOfAliasSymbol;
declare const AliasedRowsURI: "AliasedRows";

@@ -17,0 +17,0 @@ export declare type AliasedRows<Selection extends string> = {

@@ -7,6 +7,8 @@ /**

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { CommonTableExpressionFactory } from "./classes/common-table-expression";
import { SelectStatement } from "./classes/select-statement";
import { Table } from "./classes/table";
import { StringifiedSelectStatement } from "./classes/stringified-select-statement";
import { SafeString } from "./safe-string";
import { NoSelectFieldsCompileError, TableOrSubquery } from "./types";
/**

@@ -25,3 +27,3 @@ *

*/
export declare const fromStringifiedSelectStatement: <NewSelection extends string>(content: import("./safe-string").SafeString) => StringifiedSelectStatement<NewSelection>;
export declare const fromStringifiedSelectStatement: <NewSelection extends string>(content: SafeString) => StringifiedSelectStatement<NewSelection>;
/**

@@ -49,7 +51,15 @@ *

* @category starter
* @since 0.0.0
* @since 1.0.0
*/
export declare const with_: <Selection extends string, Alias extends string>(select: SelectStatement<any, any>, alias: Alias, columns?: Selection[]) => CommonTableExpression<Selection, Alias>;
export declare const with_: <Selection extends string, Alias extends string>(alias: Alias, select: SelectStatement<any, Selection>) => CommonTableExpressionFactory<`${Alias}.${Selection}`, Alias>;
/**
*
* Create a common table expression, renaming the selecion.
*
* @category starter
* @since 1.0.0
*/
export declare const withR: <Selection extends string, Alias extends string>(alias: Alias, columns: readonly Selection[], select: SelectStatement<any, any>) => CommonTableExpressionFactory<`${Alias}.${Selection}`, Alias>;
/**
*
* Select data from no source.

@@ -59,3 +69,3 @@ *

*
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -67,3 +77,3 @@ * assert.strictEqual(q1.stringify(), "SELECT 123 AS `a`");

*/
export declare const fromNothing: <NewSelection extends string>(it: Record<NewSelection, import("./safe-string").SafeString>) => SelectStatement<never, NewSelection>;
export declare const fromNothing: <NewSelection extends string>(it: Record<NewSelection, SafeString>) => SelectStatement<never, NewSelection>;
/**

@@ -73,3 +83,3 @@ * Creates a compound query using 'UNION'

* @example
* import { fromNothing, sql, union } from "sql-select-ts";
* import { fromNothing, dsql as sql, union } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -84,3 +94,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const union: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const union: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -92,3 +102,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, unionAll } from "sql-select-ts";
* import { fromNothing, dsql as sql, unionAll } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -103,3 +113,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const unionAll: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const unionAll: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -111,3 +121,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, intersect } from "sql-select-ts";
* import { fromNothing, dsql as sql, intersect } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -122,3 +132,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const intersect: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const intersect: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -130,3 +140,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

* @example
* import { fromNothing, sql, except } from "sql-select-ts";
* import { fromNothing, dsql as sql, except } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -141,3 +151,3 @@ * const q2 = fromNothing({ a: sql(456) });

*/
export declare const except: <C extends SelectStatement<any, any>, CS extends SelectStatement<any, any>[]>(content: CS & {
export declare const except: <C extends SelectStatement<any, any>, CS extends readonly SelectStatement<any, any>[]>(content: CS & {
0: C;

@@ -151,3 +161,3 @@ }) => Compound<import("./types").SelectionOfSelectStatement<C> | import("./types").SelectionOfSelectStatement<CS[number]>, import("./types").SelectionOfSelectStatement<C>>;

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -168,3 +178,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -185,3 +195,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -198,5 +208,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
sql,
dsql,
/**

@@ -281,1 +291,16 @@ *

RowOf, } from "./ts-helpers";
/**
* Creates a query selecting from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export declare const select: <NewSelection extends string, FromAlias extends string, FromSelection extends string, FromScope extends string, FromAmbigous extends string>(f: (f: Record<FromSelection, SafeString> & NoSelectFieldsCompileError) => Record<NewSelection, SafeString>, from: TableOrSubquery<FromAlias, FromScope, FromSelection, FromAmbigous>) => SelectStatement<FromSelection | FromScope, NewSelection>;
/**
*
* Creates a query selecting all from the second parameter.
*
* @category starter
* @since 1.0.0
*/
export declare const selectStar: <FromAlias extends string, FromSelection extends string, FromScope extends string, FromAmbigous extends string>(from: TableOrSubquery<FromAlias, FromScope, FromSelection, FromAmbigous>) => SelectStatement<FromSelection, FromSelection>;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSql = exports.buildSerializer = exports.sql = exports.castSafe = exports.isSafeString = exports.except = exports.intersect = exports.unionAll = exports.union = exports.fromNothing = exports.with_ = exports.table = exports.fromStringifiedSelectStatement = void 0;
exports.selectStar = exports.select = exports.buildSql = exports.buildSerializer = exports.dsql = exports.castSafe = exports.isSafeString = exports.except = exports.intersect = exports.unionAll = exports.union = exports.fromNothing = exports.withR = exports.with_ = exports.table = exports.fromStringifiedSelectStatement = void 0;
var compound_1 = require("./classes/compound");
var cte_1 = require("./classes/cte");
var common_table_expression_1 = require("./classes/common-table-expression");
var select_statement_1 = require("./classes/select-statement");

@@ -51,7 +51,15 @@ var table_1 = require("./classes/table");

* @category starter
* @since 0.0.0
* @since 1.0.0
*/
exports.with_ = cte_1.CommonTableExpression.define;
exports.with_ = common_table_expression_1.CommonTableExpressionFactory.define;
/**
*
* Create a common table expression, renaming the selecion.
*
* @category starter
* @since 1.0.0
*/
exports.withR = common_table_expression_1.CommonTableExpressionFactory.defineRenamed;
/**
*
* Select data from no source.

@@ -61,3 +69,3 @@ *

*
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -74,3 +82,3 @@ * assert.strictEqual(q1.stringify(), "SELECT 123 AS `a`");

* @example
* import { fromNothing, sql, union } from "sql-select-ts";
* import { fromNothing, dsql as sql, union } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -90,3 +98,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, unionAll } from "sql-select-ts";
* import { fromNothing, dsql as sql, unionAll } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -106,3 +114,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, intersect } from "sql-select-ts";
* import { fromNothing, dsql as sql, intersect } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -122,3 +130,3 @@ * const q2 = fromNothing({ a: sql(456) });

* @example
* import { fromNothing, sql, except } from "sql-select-ts";
* import { fromNothing, dsql as sql, except } from "sql-select-ts";
* const q1 = fromNothing({ a: sql(123) });

@@ -140,3 +148,3 @@ * const q2 = fromNothing({ a: sql(456) });

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -157,3 +165,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -174,3 +182,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -187,5 +195,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return safe_string_1.sql; } });
Object.defineProperty(exports, "dsql", { enumerable: true, get: function () { return safe_string_1.dsql; } });
/**

@@ -203,1 +211,20 @@ *

Object.defineProperty(exports, "buildSql", { enumerable: true, get: function () { return safe_string_1.buildSql; } });
/**
* Creates a query selecting from the second parameter.
*
* @category starter
* @since 1.0.0
*/
var select = function (f, from) {
return from.select(f);
};
exports.select = select;
/**
*
* Creates a query selecting all from the second parameter.
*
* @category starter
* @since 1.0.0
*/
var selectStar = function (from) { return from.selectStar(); };
exports.selectStar = selectStar;
import { Compound } from "./classes/compound";
import { SelectStatement } from "./classes/select-statement";
export declare const printCompoundInternal: <Scope extends string, Selection extends string>(compound: Compound<Scope, Selection>, parenthesis: boolean) => PrintInternalRet;
declare type PrintInternalRet = {
content: string;
with_?: string;
};
declare type PrintInternalRet = string;
export declare const printSelectStatementInternal: <Scope extends string, Selection extends string>(selectStatement: SelectStatement<Scope, Selection>, parenthesis: boolean) => PrintInternalRet;

@@ -9,0 +6,0 @@ export declare const printSelectStatement: <Scope extends string, Selection extends string>(it: SelectStatement<Scope, Selection>) => string;

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

var compound_1 = require("./classes/compound");
var cte_1 = require("./classes/cte");
var joined_1 = require("./classes/joined");

@@ -46,3 +45,3 @@ var select_statement_1 = require("./classes/select-statement");

var sel = compound.__props.content
.map(function (it) { return printInternal(it, false).content; })
.map(function (it) { return printInternal(it, false); })
.join(" ".concat(compound.__props.qualifier, " "));

@@ -57,26 +56,14 @@ var q = [

if (parenthesis) {
return { content: "(".concat(q, ")") };
return "(".concat(q, ")");
}
return { content: q };
return q;
};
exports.printCompoundInternal = printCompoundInternal;
var printStringifiedSelectInternal = function (it) { return ({
content: "(".concat(it.__props.content.content, ")"),
}); };
var printCteInternal = function (cte) {
var cols = cte.__props.columns.length > 0
? "(".concat(cte.__props.columns.join(", "), ")")
: "";
var content = printInternal(cte.__props.select, false).content;
var with_ = "".concat(cte.__props.alias).concat(cols, " AS (").concat(content, ")");
return { content: cte.__props.alias, with_: with_ };
};
var printStringifiedSelectInternal = function (it) { return "(".concat(it.__props.content.content, ")"); };
var printTableInternal = function (table) {
var final = table.__props.final ? " FINAL" : "";
if (table.__props.name === table.__props.alias) {
return { content: (0, wrap_alias_1.wrapAliasSplitDots)(table.__props.name) + final };
return (0, wrap_alias_1.wrapAliasSplitDots)(table.__props.name) + final;
}
return {
content: "".concat((0, wrap_alias_1.wrapAliasSplitDots)(table.__props.name), " AS ").concat((0, wrap_alias_1.wrapAlias)(table.__props.alias)).concat(final),
};
return "".concat((0, wrap_alias_1.wrapAliasSplitDots)(table.__props.name), " AS ").concat((0, wrap_alias_1.wrapAlias)(table.__props.alias)).concat(final);
};

@@ -105,3 +92,3 @@ var printConstraint = function (c) {

var printAliasedCode = function (code, alias) {
var str = printInternal(code, true).content;
var str = printInternal(code, true);
if (code instanceof table_1.Table) {

@@ -131,6 +118,15 @@ return str;

var content = [head, tail].filter(function (it) { return it.length > 0; }).join(" ");
return {
content: content,
};
return content;
};
var printCtes = function (ctes) {
return ctes
.map(function (cte) {
var cols = cte.columns.length > 0
? "(".concat(cte.columns.map(wrap_alias_1.wrapAliasSplitDots).join(", "), ")")
: "";
var content = printInternal(cte.select, false);
return "".concat((0, wrap_alias_1.wrapAlias)(cte.alias)).concat(cols, " AS (").concat(content, ")");
})
.join(", ");
};
var printClickhouseWith = function (withes) {

@@ -141,3 +137,3 @@ return withes

var k = _a[0], v = _a[1];
return "".concat(printInternal(v, true).content, " AS ").concat((0, wrap_alias_1.wrapAlias)(k));
return "".concat(printInternal(v, true), " AS ").concat((0, wrap_alias_1.wrapAlias)(k));
});

@@ -150,3 +146,2 @@ })

var printSelectStatementInternal = function (selectStatement, parenthesis) {
var _a;
var selection = selectStatement.__props.selection

@@ -198,7 +193,4 @@ .map(function (it) {

var from = selectStatement.__props.from != null
? "FROM ".concat(printInternal(selectStatement.__props.from, true).content)
? "FROM ".concat(printInternal(selectStatement.__props.from, true))
: "";
var withFromCte = selectStatement.__props.from != null
? (_a = printInternal(selectStatement.__props.from, true).with_) !== null && _a !== void 0 ? _a : ""
: "";
var distinct = selectStatement.__props.distinct ? "DISTINCT" : "";

@@ -208,7 +200,10 @@ var clickhouseWith = selectStatement.__props.clickhouseWith.length > 0

: "";
var withFromCte = selectStatement.__props.ctes.length > 0
? printCtes(selectStatement.__props.ctes)
: "";
var withKeyword = withFromCte.length > 0 || clickhouseWith.length > 0 ? "WITH" : "";
var contentNoParenthesis = [
withKeyword,
clickhouseWith,
withFromCte,
clickhouseWith,
"SELECT",

@@ -231,5 +226,3 @@ distinct,

: contentNoParenthesis;
return {
content: content,
};
return content;
};

@@ -250,5 +243,2 @@ exports.printSelectStatementInternal = printSelectStatementInternal;

}
if (it instanceof cte_1.CommonTableExpression) {
return printCteInternal(it);
}
if (it instanceof stringified_select_statement_1.StringifiedSelectStatement) {

@@ -260,5 +250,5 @@ return printStringifiedSelectInternal(it);

};
var printSelectStatement = function (it) { return (0, exports.printSelectStatementInternal)(it, false).content; };
var printSelectStatement = function (it) { return (0, exports.printSelectStatementInternal)(it, false); };
exports.printSelectStatement = printSelectStatement;
var printCompound = function (it) { return (0, exports.printCompoundInternal)(it, false).content; };
var printCompound = function (it) { return (0, exports.printCompoundInternal)(it, false); };
exports.printCompound = printCompound;

@@ -32,3 +32,3 @@ /**

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -47,3 +47,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -106,3 +106,3 @@ * assert.strictEqual(isSafeString(sql(123)), true);

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -119,5 +119,5 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
export declare const sql: SqlStringBuilder<never[]>;
export declare const dsql: SqlStringBuilder<never[]>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sql = exports.buildSql = exports.buildSerializer = exports.isSafeString = exports.castSafe = exports.SafeStringURI = void 0;
exports.dsql = exports.buildSql = exports.buildSerializer = exports.isSafeString = exports.castSafe = exports.SafeStringURI = void 0;
/**

@@ -26,3 +26,3 @@ * Safe String and it's building mechanisms allows us to have painless, injection safe SQL string building.

*
* import { castSafe, sql } from "sql-select-ts";
* import { castSafe, dsql as sql } from "sql-select-ts";
*

@@ -45,3 +45,3 @@ * assert.strictEqual(castSafe(";'abc'").content, ";'abc'");

*
* import { isSafeString, sql } from "sql-select-ts";
* import { isSafeString, dsql as sql } from "sql-select-ts";
*

@@ -87,6 +87,6 @@ * assert.strictEqual(isSafeString(sql(123)), true);

else if (val instanceof select_statement_1.SelectStatement) {
return (0, print_1.printSelectStatementInternal)(val, true).content;
return (0, print_1.printSelectStatementInternal)(val, true);
}
else if (val instanceof compound_1.Compound) {
return (0, print_1.printCompoundInternal)(val, true).content;
return (0, print_1.printCompoundInternal)(val, true);
}

@@ -178,3 +178,3 @@ else if (Array.isArray(val)) {

* @example
* import { fromNothing, sql } from "sql-select-ts";
* import { fromNothing, dsql as sql } from "sql-select-ts";
* assert.strictEqual(sql(";'abc'").content, "';\\'abc\\''");

@@ -191,4 +191,4 @@ * assert.strictEqual(sql(123).content, "123");

* @category string-builder
* @since 0.0.0
* @since 1.0.0
*/
exports.sql = (0, exports.buildSql)([]);
exports.dsql = (0, exports.buildSql)([]);

@@ -7,3 +7,2 @@ /**

import { Compound } from "./classes/compound";
import { CommonTableExpression } from "./classes/cte";
import { Joined } from "./classes/joined";

@@ -14,3 +13,3 @@ import { SelectStatement } from "./classes/select-statement";

import { SafeString } from "./safe-string";
export declare type TableOrSubquery<Alias extends string, Scope extends string, Selection extends string, Ambiguous extends string> = SelectStatement<Scope, Selection> | StringifiedSelectStatement<Selection> | Table<Alias, Selection> | CommonTableExpression<Alias, Selection> | Joined<Selection, Scope, Alias, Ambiguous> | Compound<Scope, Selection>;
export declare type TableOrSubquery<Alias extends string, Scope extends string, Selection extends string, Ambiguous extends string> = SelectStatement<Scope, Selection> | StringifiedSelectStatement<Selection> | Table<Selection, Alias> | Joined<Selection, Scope, Alias, Ambiguous> | Compound<Scope, Selection>;
export declare type NoSelectFieldsCompileError = {

@@ -25,3 +24,3 @@ ["✕"]: CompileError<["'.select(f => f)' is invalid"]>;

}
export interface NonEmptyArray<A> extends Array<A> {
export interface NonEmptyArray<A> extends ReadonlyArray<A> {
0: A;

@@ -37,4 +36,9 @@ }

_tag: "using";
keys: string[];
keys: ReadonlyArray<string>;
};
export declare type SelectionOfSelectStatement<T> = T extends SelectStatement<infer _Scope, infer Selection> ? Selection : never;
export declare type CTE = {
readonly columns: ReadonlyArray<string>;
readonly alias: string;
readonly select: SelectStatement<any, any>;
};
import { NonEmptyArray } from "./types";
export declare const makeArray: <T>(it: T | T[]) => T[];
export declare const makeNonEmptyArray: <T>(it: T | T[]) => NonEmptyArray<T>;
export declare const makeArray: <T>(it: T | readonly T[]) => readonly T[];
export declare const makeNonEmptyArray: <T>(it: T | readonly T[]) => NonEmptyArray<T>;
export declare const absurd: <A>(_: never) => A;
export declare const hole: <T>() => T;

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

}
// @ts-expect-error - readonly array is array
return [it];

@@ -19,2 +20,3 @@ };

}
// @ts-expect-error - readonly array is array
return [it];

@@ -21,0 +23,0 @@ };

{
"name": "sql-select-ts",
"version": "0.0.9",
"version": "1.0.0",
"description": "A modern, database-agnostic, composable SELECT query builder with great typescript support.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc