@triptease/sql-template 0.13.11 → 0.17.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Expression.d.ts +2 -0
- package/Expression.js +7 -0
- package/Identifier.d.ts +8 -0
- package/Identifier.js +22 -0
- package/SQL.d.ts +2 -4
- package/SQL.js +10 -33
- package/Template.d.ts +6 -0
- package/Template.js +23 -0
- package/Text.d.ts +7 -0
- package/Text.js +17 -0
- package/Value.d.ts +9 -0
- package/Value.js +27 -0
- package/index.d.ts +6 -2
- package/index.js +6 -6
- package/package.json +1 -1
- package/CompositeTemplate.d.ts +0 -9
- package/CompositeTemplate.js +0 -21
- package/api.d.ts +0 -12
- package/api.js +0 -12
package/Expression.d.ts
ADDED
package/Expression.js
ADDED
package/Identifier.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Expression } from "./Expression";
|
|
2
|
+
import { Template } from "./Template";
|
|
3
|
+
export declare class Identifier extends Expression {
|
|
4
|
+
identifier: string;
|
|
5
|
+
constructor(identifier: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function id(identifier: string): Identifier;
|
|
8
|
+
export declare function ids(identifiers: any[], separator?: string): Template;
|
package/Identifier.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ids = exports.id = exports.Identifier = void 0;
|
|
4
|
+
const Expression_1 = require("./Expression");
|
|
5
|
+
const Template_1 = require("./Template");
|
|
6
|
+
const Text_1 = require("./Text");
|
|
7
|
+
class Identifier extends Expression_1.Expression {
|
|
8
|
+
constructor(identifier) {
|
|
9
|
+
super();
|
|
10
|
+
this.identifier = identifier;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Identifier = Identifier;
|
|
14
|
+
function id(identifier) {
|
|
15
|
+
return new Identifier(identifier);
|
|
16
|
+
}
|
|
17
|
+
exports.id = id;
|
|
18
|
+
function ids(identifiers, separator = ', ') {
|
|
19
|
+
return (0, Template_1.template)(...identifiers.flatMap((v, i) => i > 0 ? [(0, Text_1.text)(separator), id(v)] : [id(v)]));
|
|
20
|
+
}
|
|
21
|
+
exports.ids = ids;
|
|
22
|
+
//# sourceMappingURL=Identifier.js.map
|
package/SQL.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function SQL(
|
|
3
|
-
export declare function spread(values: any[]): SqlTemplate;
|
|
4
|
-
export declare function raw(value: string): SqlTemplate;
|
|
1
|
+
import { Template } from "./Template";
|
|
2
|
+
export declare function SQL(chunks: TemplateStringsArray, ...values: any[]): Template;
|
package/SQL.js
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (value === undefined)
|
|
14
|
-
return [null];
|
|
15
|
-
if ((0, api_1.isSqlTemplate)(value))
|
|
16
|
-
return value.values;
|
|
17
|
-
return [value];
|
|
18
|
-
}
|
|
19
|
-
function SQL(text, ...values) {
|
|
20
|
-
return text.reduce((a, t, i) => {
|
|
21
|
-
if (i === values.length)
|
|
22
|
-
return (0, api_1.sqlTemplate)(a.text + t, a.values);
|
|
23
|
-
const value = values[i];
|
|
24
|
-
const newText = t + calculateAdditionalText(value);
|
|
25
|
-
const newValues = calculateNewValues(value);
|
|
26
|
-
return (0, api_1.sqlTemplate)(a.text + newText, [...a.values, ...newValues]);
|
|
27
|
-
}, (0, api_1.sqlTemplate)());
|
|
3
|
+
exports.SQL = void 0;
|
|
4
|
+
const Template_1 = require("./Template");
|
|
5
|
+
const Text_1 = require("./Text");
|
|
6
|
+
const Value_1 = require("./Value");
|
|
7
|
+
function SQL(chunks, ...values) {
|
|
8
|
+
return (0, Template_1.template)(...chunks.flatMap((chunk, index) => {
|
|
9
|
+
if (index > (values.length - 1))
|
|
10
|
+
return [(0, Text_1.text)(chunk)];
|
|
11
|
+
return [(0, Text_1.text)(chunk), (0, Value_1.value)(values[index])];
|
|
12
|
+
}));
|
|
28
13
|
}
|
|
29
14
|
exports.SQL = SQL;
|
|
30
|
-
function spread(values) {
|
|
31
|
-
return (0, CompositeTemplate_1.compose)(values.map(v => (0, api_1.sqlTemplate)(placeholder, calculateNewValues(v))));
|
|
32
|
-
}
|
|
33
|
-
exports.spread = spread;
|
|
34
|
-
function raw(value) {
|
|
35
|
-
return (0, api_1.sqlTemplate)(value, []);
|
|
36
|
-
}
|
|
37
|
-
exports.raw = raw;
|
|
38
15
|
//# sourceMappingURL=SQL.js.map
|
package/Template.d.ts
ADDED
package/Template.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.template = exports.Template = void 0;
|
|
4
|
+
const Expression_1 = require("./Expression");
|
|
5
|
+
const Text_1 = require("./Text");
|
|
6
|
+
class Template extends Expression_1.Expression {
|
|
7
|
+
constructor(expressions) {
|
|
8
|
+
super();
|
|
9
|
+
this.expressions = expressions;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.Template = Template;
|
|
13
|
+
function template(...expressions) {
|
|
14
|
+
return new Template(expressions.flatMap(e => {
|
|
15
|
+
if (e instanceof Text_1.Text && e.text === '')
|
|
16
|
+
return [];
|
|
17
|
+
if (e instanceof Template)
|
|
18
|
+
return e.expressions;
|
|
19
|
+
return [e];
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
exports.template = template;
|
|
23
|
+
//# sourceMappingURL=Template.js.map
|
package/Text.d.ts
ADDED
package/Text.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.raw = exports.text = exports.Text = void 0;
|
|
4
|
+
const Expression_1 = require("./Expression");
|
|
5
|
+
class Text extends Expression_1.Expression {
|
|
6
|
+
constructor(text) {
|
|
7
|
+
super();
|
|
8
|
+
this.text = text;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.Text = Text;
|
|
12
|
+
function text(text) {
|
|
13
|
+
return new Text(text);
|
|
14
|
+
}
|
|
15
|
+
exports.text = text;
|
|
16
|
+
exports.raw = text;
|
|
17
|
+
//# sourceMappingURL=Text.js.map
|
package/Value.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Expression } from "./Expression";
|
|
2
|
+
import { Template } from "./Template";
|
|
3
|
+
export declare class Value extends Expression {
|
|
4
|
+
value: any;
|
|
5
|
+
constructor(value: any);
|
|
6
|
+
}
|
|
7
|
+
export declare function value(value: any): Expression;
|
|
8
|
+
export declare function values(values: any[], separator?: string): Template;
|
|
9
|
+
export declare const spread: typeof values;
|
package/Value.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.spread = exports.values = exports.value = exports.Value = void 0;
|
|
4
|
+
const Expression_1 = require("./Expression");
|
|
5
|
+
const Template_1 = require("./Template");
|
|
6
|
+
const Text_1 = require("./Text");
|
|
7
|
+
class Value extends Expression_1.Expression {
|
|
8
|
+
constructor(value) {
|
|
9
|
+
super();
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Value = Value;
|
|
14
|
+
function value(value) {
|
|
15
|
+
if (value instanceof Expression_1.Expression)
|
|
16
|
+
return value;
|
|
17
|
+
if (value === undefined)
|
|
18
|
+
return new Value(null);
|
|
19
|
+
return new Value(value);
|
|
20
|
+
}
|
|
21
|
+
exports.value = value;
|
|
22
|
+
function values(values, separator = ', ') {
|
|
23
|
+
return (0, Template_1.template)(...values.flatMap((v, i) => i > 0 ? [(0, Text_1.text)(separator), value(v)] : [value(v)]));
|
|
24
|
+
}
|
|
25
|
+
exports.values = values;
|
|
26
|
+
exports.spread = values;
|
|
27
|
+
//# sourceMappingURL=Value.js.map
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.raw = exports.spread = exports.SQL = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./Expression"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./Identifier"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./SQL"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./Template"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./Text"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./Value"), exports);
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
package/CompositeTemplate.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SqlTemplate } from "./api";
|
|
2
|
-
export declare class CompositeTemplate implements SqlTemplate {
|
|
3
|
-
private fragments;
|
|
4
|
-
private joiner;
|
|
5
|
-
constructor(fragments: SqlTemplate[], joiner: string);
|
|
6
|
-
get text(): string;
|
|
7
|
-
get values(): ReadonlyArray<any>;
|
|
8
|
-
}
|
|
9
|
-
export declare function compose(fragments: SqlTemplate[], joiner?: string): SqlTemplate;
|
package/CompositeTemplate.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compose = exports.CompositeTemplate = void 0;
|
|
4
|
-
class CompositeTemplate {
|
|
5
|
-
constructor(fragments, joiner) {
|
|
6
|
-
this.fragments = fragments;
|
|
7
|
-
this.joiner = joiner;
|
|
8
|
-
}
|
|
9
|
-
get text() {
|
|
10
|
-
return this.fragments.map(f => f.text).join(this.joiner);
|
|
11
|
-
}
|
|
12
|
-
get values() {
|
|
13
|
-
return this.fragments.flatMap(f => f.values);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.CompositeTemplate = CompositeTemplate;
|
|
17
|
-
function compose(fragments, joiner = ', ') {
|
|
18
|
-
return new CompositeTemplate(fragments, joiner);
|
|
19
|
-
}
|
|
20
|
-
exports.compose = compose;
|
|
21
|
-
//# sourceMappingURL=CompositeTemplate.js.map
|
package/api.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare type SimpleObject = {
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
};
|
|
4
|
-
export interface SqlClient {
|
|
5
|
-
query(template: SqlTemplate): Promise<SimpleObject[]>;
|
|
6
|
-
}
|
|
7
|
-
export interface SqlTemplate {
|
|
8
|
-
readonly text: string;
|
|
9
|
-
readonly values: ReadonlyArray<any>;
|
|
10
|
-
}
|
|
11
|
-
export declare function isSqlTemplate(value: any): value is SqlTemplate;
|
|
12
|
-
export declare function sqlTemplate(text?: string, values?: ReadonlyArray<any>): SqlTemplate;
|
package/api.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sqlTemplate = exports.isSqlTemplate = void 0;
|
|
4
|
-
function isSqlTemplate(value) {
|
|
5
|
-
return value && typeof value['text'] === 'string' && Array.isArray(value['values']);
|
|
6
|
-
}
|
|
7
|
-
exports.isSqlTemplate = isSqlTemplate;
|
|
8
|
-
function sqlTemplate(text = '', values = []) {
|
|
9
|
-
return { text, values };
|
|
10
|
-
}
|
|
11
|
-
exports.sqlTemplate = sqlTemplate;
|
|
12
|
-
//# sourceMappingURL=api.js.map
|