rado 1.0.5 → 1.0.6
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/dist/core/Query.d.ts +1 -1
- package/dist/core/Query.js +2 -2
- package/dist/core/Sql.d.ts +2 -1
- package/dist/core/Sql.js +8 -1
- package/dist/core/expr/Conditions.js +9 -7
- package/dist/sqlite/functions.d.ts +1 -5
- package/dist/sqlite/functions.js +0 -2
- package/dist/universal/functions.d.ts +1 -1
- package/dist/universal/functions.js +9 -5
- package/package.json +1 -1
package/dist/core/Query.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare abstract class Query<Result, Meta extends QueryMeta> extends Exec
|
|
|
32
32
|
get(db?: HasResolver): Deliver<Meta, Result | null>;
|
|
33
33
|
run(db?: HasResolver): Deliver<Meta, void>;
|
|
34
34
|
prepare<Inputs extends Record<string, unknown>>(name?: string): PreparedQuery<Result, Inputs, Meta>;
|
|
35
|
-
toSQL(): {
|
|
35
|
+
toSQL(db?: HasResolver): {
|
|
36
36
|
sql: string;
|
|
37
37
|
params: Array<unknown>;
|
|
38
38
|
};
|
package/dist/core/Query.js
CHANGED
|
@@ -80,8 +80,8 @@ var Query = class extends Executable {
|
|
|
80
80
|
prepare(name) {
|
|
81
81
|
return getData(this).resolver.prepare(this, name);
|
|
82
82
|
}
|
|
83
|
-
toSQL() {
|
|
84
|
-
const
|
|
83
|
+
toSQL(db) {
|
|
84
|
+
const resolver = db ? getResolver(db) : getData(this).resolver;
|
|
85
85
|
if (!resolver)
|
|
86
86
|
throw new Error("Query has no resolver");
|
|
87
87
|
return resolver.toSQL(this);
|
package/dist/core/Sql.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class Sql<Value = unknown> implements HasSql<Value> {
|
|
|
29
29
|
field(field: FieldData): Sql<Value>;
|
|
30
30
|
add(sql: HasSql): Sql<Value>;
|
|
31
31
|
value(value: unknown): Sql<Value>;
|
|
32
|
+
getValue(): Value | undefined;
|
|
32
33
|
inline(value: unknown): Sql<Value>;
|
|
33
34
|
jsonPath(path: Array<string | number>): Sql<Value>;
|
|
34
35
|
placeholder(name: string): Sql<Value>;
|
|
@@ -48,7 +49,7 @@ export declare namespace sql {
|
|
|
48
49
|
export function identifier<T>(identifier: string): Sql<T>;
|
|
49
50
|
export function field<T>(field: FieldData): Sql<T>;
|
|
50
51
|
export function chunk<Type extends keyof EmitMethods>(type: Type, inner: Parameters<EmitMethods[Type]>[0]): Sql;
|
|
51
|
-
export function universal(runtimes: Partial<Record<Runtime | 'default', Sql
|
|
52
|
+
export function universal<T>(runtimes: Partial<Record<Runtime | 'default', Sql<T>>>): Sql<T>;
|
|
52
53
|
type QueryChunk = HasSql | undefined;
|
|
53
54
|
export function query(ast: Record<string, boolean | QueryChunk | Array<QueryChunk>>): Sql;
|
|
54
55
|
export function join<T>(items: Array<Sql | HasSql | undefined | false>, separator?: Sql): Sql<T>;
|
package/dist/core/Sql.js
CHANGED
|
@@ -46,6 +46,13 @@ var Sql = class _Sql {
|
|
|
46
46
|
value(value) {
|
|
47
47
|
return this.chunk("emitValue", value);
|
|
48
48
|
}
|
|
49
|
+
getValue() {
|
|
50
|
+
if (this.#chunks.length !== 1)
|
|
51
|
+
return;
|
|
52
|
+
const chunk = this.#chunks[0];
|
|
53
|
+
if (chunk?.type === "emitValue")
|
|
54
|
+
return chunk.inner;
|
|
55
|
+
}
|
|
49
56
|
inline(value) {
|
|
50
57
|
return this.chunk("emitInline", value);
|
|
51
58
|
}
|
|
@@ -141,7 +148,7 @@ function sql(strings, ...inner) {
|
|
|
141
148
|
}
|
|
142
149
|
sql2.chunk = chunk;
|
|
143
150
|
function universal(runtimes) {
|
|
144
|
-
return chunk("emitUniversal", runtimes);
|
|
151
|
+
return empty().chunk("emitUniversal", runtimes);
|
|
145
152
|
}
|
|
146
153
|
sql2.universal = universal;
|
|
147
154
|
function query(ast) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/expr/Conditions.ts
|
|
2
|
-
import { getQuery } from "../Internal.js";
|
|
2
|
+
import { getQuery, getSql, hasSql } from "../Internal.js";
|
|
3
3
|
import { sql } from "../Sql.js";
|
|
4
4
|
import { input } from "./Input.js";
|
|
5
5
|
function bool(impl) {
|
|
@@ -41,19 +41,21 @@ function not(condition) {
|
|
|
41
41
|
return bool(sql`not ${input(condition)}`);
|
|
42
42
|
}
|
|
43
43
|
function inArray(left, right) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const value = (hasSql(right) ? getSql(right).getValue() : void 0) ?? right;
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
if (value.length === 0)
|
|
46
47
|
return sql`false`;
|
|
47
|
-
return bool(sql`${input(left)} in (${sql.join(
|
|
48
|
+
return bool(sql`${input(left)} in (${sql.join(value.map(input), sql`, `)})`);
|
|
48
49
|
}
|
|
49
50
|
return bool(sql`${input(left)} in ${input(right)}`);
|
|
50
51
|
}
|
|
51
52
|
function notInArray(left, right) {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const value = (hasSql(right) ? getSql(right).getValue() : void 0) ?? right;
|
|
54
|
+
if (Array.isArray(value)) {
|
|
55
|
+
if (value.length === 0)
|
|
54
56
|
return sql`true`;
|
|
55
57
|
return bool(
|
|
56
|
-
sql`${input(left)} not in (${sql.join(
|
|
58
|
+
sql`${input(left)} not in (${sql.join(value.map(input), sql`, `)})`
|
|
57
59
|
);
|
|
58
60
|
}
|
|
59
61
|
return bool(sql`${input(left)} not in ${input(right)}`);
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HasSql, HasTable } from '../core/Internal.js';
|
|
2
2
|
import { type Sql } from '../core/Sql.js';
|
|
3
3
|
import { type Input } from '../core/expr/Input.js';
|
|
4
4
|
/**: The count(X) function returns a count of the number of times that X is not NULL in a group. The count(*) function (with no arguments) returns the total number of rows in the group. */
|
|
5
5
|
export declare const count: (x?: HasSql) => Sql<number>;
|
|
6
6
|
/** The iif(X,Y,Z) function returns the value Y if X is true, and Z otherwise. The iif(X,Y,Z) function is logically equivalent to and generates the same bytecode as the CASE HasSql "CASE WHEN X THEN Y ELSE Z END".*/
|
|
7
7
|
export declare const iif: <T>(x: Input<boolean>, y: Input<T>, z: Input<T>) => Sql<T>;
|
|
8
|
-
/**
|
|
9
|
-
* The EXISTS operator always evaluates to one of the integer values 0 and 1. If executing the SELECT statement specified as the right-hand operand of the EXISTS operator would return one or more rows, then the EXISTS operator evaluates to 1. If executing the SELECT would return no rows at all, then the EXISTS operator evaluates to 0.
|
|
10
|
-
*/
|
|
11
|
-
export declare const exists: (cursor: HasQuery) => Sql<boolean>;
|
|
12
8
|
/** Use the match operator for the FTS5 module */
|
|
13
9
|
export declare const match: (table: HasTable, searchTerm: Input<string>) => Sql<boolean>;
|
|
14
10
|
/** Returns a real value reflecting the accuracy of the current match */
|
package/dist/sqlite/functions.js
CHANGED
|
@@ -4,7 +4,6 @@ import { Functions } from "../core/expr/Functions.js";
|
|
|
4
4
|
import { input } from "../core/expr/Input.js";
|
|
5
5
|
var count = Functions.count;
|
|
6
6
|
var iif = Functions.iif;
|
|
7
|
-
var exists = Functions.exists;
|
|
8
7
|
var match = Functions.match;
|
|
9
8
|
var bm25 = Functions.bm25;
|
|
10
9
|
var highlight = Functions.highlight;
|
|
@@ -101,7 +100,6 @@ export {
|
|
|
101
100
|
date,
|
|
102
101
|
datetime,
|
|
103
102
|
degrees,
|
|
104
|
-
exists,
|
|
105
103
|
exp,
|
|
106
104
|
floor,
|
|
107
105
|
group_concat,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Sql } from '../core/Sql.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type Input } from '../core/expr/Input.js';
|
|
3
3
|
export declare function lastInsertId(): Sql<number>;
|
|
4
4
|
export declare function concat(...slices: Array<Input<string | null>>): Sql<string>;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
// src/universal/functions.ts
|
|
2
2
|
import { sql } from "../core/Sql.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Functions } from "../core/expr/Functions.js";
|
|
4
|
+
import { input } from "../core/expr/Input.js";
|
|
4
5
|
var insertId = sql.universal({
|
|
5
|
-
sqlite:
|
|
6
|
-
postgres:
|
|
7
|
-
mysql:
|
|
6
|
+
sqlite: Functions.last_insert_rowid(),
|
|
7
|
+
postgres: Functions.lastval(),
|
|
8
|
+
mysql: Functions.last_insert_id()
|
|
8
9
|
}).mapWith(Number);
|
|
9
10
|
function lastInsertId() {
|
|
10
11
|
return insertId;
|
|
11
12
|
}
|
|
12
13
|
function concat(...slices) {
|
|
13
|
-
return
|
|
14
|
+
return sql.universal({
|
|
15
|
+
mysql: Functions.concat(...slices),
|
|
16
|
+
default: sql.join(slices.map(input), sql` || `)
|
|
17
|
+
});
|
|
14
18
|
}
|
|
15
19
|
export {
|
|
16
20
|
concat,
|