rado 1.0.3 → 1.0.4
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type HasSql } from '../Internal.js';
|
|
2
|
+
import type { Either } from '../MetaData.js';
|
|
3
|
+
import type { Query } from '../Query.js';
|
|
2
4
|
import { type Sql } from '../Sql.js';
|
|
3
|
-
import type { Select } from '../query/Select.js';
|
|
4
5
|
import { type Input } from './Input.js';
|
|
5
6
|
export declare const eq: <T>(left: Input<T>, right: Input<T>) => Sql<boolean>;
|
|
6
7
|
export declare const ne: <T>(left: Input<T>, right: Input<T>) => Sql<boolean>;
|
|
@@ -18,8 +19,8 @@ export declare const arrayOverlaps: <T>(left: Input<Array<T>>, right: Input<Arra
|
|
|
18
19
|
export declare function and(...conditions: Array<undefined | Input<boolean>>): Sql<boolean>;
|
|
19
20
|
export declare function or(...conditions: Array<undefined | Input<boolean>>): Sql<boolean>;
|
|
20
21
|
export declare function not(condition: Input<boolean>): Sql<boolean>;
|
|
21
|
-
export declare function inArray<T>(left: Input<T>, right: Input<Array<T>>): Sql<boolean>;
|
|
22
|
-
export declare function notInArray<T>(left: Input<T>, right: Input<Array<T>>): Sql<boolean>;
|
|
22
|
+
export declare function inArray<T>(left: Input<T>, right: Query<T, any> | Input<Array<T>>): Sql<boolean>;
|
|
23
|
+
export declare function notInArray<T>(left: Input<T>, right: Query<T, any> | Input<Array<T>>): Sql<boolean>;
|
|
23
24
|
export declare function isNull(value: Input): Sql<boolean>;
|
|
24
25
|
export declare function isNotNull(value: Input): Sql<boolean>;
|
|
25
26
|
export declare function between<T>(value: Input<T>, left: Input<T>, right: Input<T>): Sql<boolean>;
|
|
@@ -29,4 +30,4 @@ export declare function desc<T>(input: HasSql<T>): Sql;
|
|
|
29
30
|
export declare function distinct<T>(input: HasSql<T>): Sql;
|
|
30
31
|
export declare function when<In, Out>(compare: Input<In>, ...cases: Array<[condition: Input<In>, result: Input<Out>] | Input<Out>>): Sql<Out>;
|
|
31
32
|
export declare function when<Out>(...cases: Array<[condition: Input<boolean>, result: Input<Out>] | Input<Out>>): Sql<Out>;
|
|
32
|
-
export declare function exists
|
|
33
|
+
export declare function exists(query: Query<any, Either>): Sql<boolean>;
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
import { getQuery } from "../Internal.js";
|
|
3
3
|
import { sql } from "../Sql.js";
|
|
4
4
|
import { input } from "./Input.js";
|
|
5
|
+
function bool(impl) {
|
|
6
|
+
return impl.mapWith(Boolean);
|
|
7
|
+
}
|
|
5
8
|
function binop(operator) {
|
|
6
|
-
return (left, right) => sql`${input(left)} ${sql.unsafe(operator)} ${input(right)}
|
|
9
|
+
return (left, right) => bool(sql`${input(left)} ${sql.unsafe(operator)} ${input(right)}`);
|
|
7
10
|
}
|
|
8
11
|
var eq = binop("=");
|
|
9
12
|
var ne = binop("<>");
|
|
@@ -21,49 +24,53 @@ var arrayOverlaps = binop("&&");
|
|
|
21
24
|
function and(...conditions) {
|
|
22
25
|
const inputs = conditions.filter((v) => v !== void 0).map(input);
|
|
23
26
|
if (inputs.length === 0)
|
|
24
|
-
return sql`true
|
|
27
|
+
return bool(sql`true`);
|
|
25
28
|
if (inputs.length === 1)
|
|
26
|
-
return inputs[0];
|
|
27
|
-
return sql`(${sql.join(inputs, sql` and `)})
|
|
29
|
+
return bool(inputs[0]);
|
|
30
|
+
return bool(sql`(${sql.join(inputs, sql` and `)})`);
|
|
28
31
|
}
|
|
29
32
|
function or(...conditions) {
|
|
30
33
|
const inputs = conditions.filter((v) => v !== void 0).map(input);
|
|
31
34
|
if (inputs.length === 0)
|
|
32
|
-
return sql`true
|
|
35
|
+
return bool(sql`true`);
|
|
33
36
|
if (inputs.length === 1)
|
|
34
|
-
return inputs[0];
|
|
35
|
-
return sql`(${sql.join(inputs, sql` or `)})
|
|
37
|
+
return bool(inputs[0]);
|
|
38
|
+
return bool(sql`(${sql.join(inputs, sql` or `)})`);
|
|
36
39
|
}
|
|
37
40
|
function not(condition) {
|
|
38
|
-
return sql`not ${input(condition)}
|
|
41
|
+
return bool(sql`not ${input(condition)}`);
|
|
39
42
|
}
|
|
40
43
|
function inArray(left, right) {
|
|
41
44
|
if (Array.isArray(right)) {
|
|
42
45
|
if (right.length === 0)
|
|
43
46
|
return sql`false`;
|
|
44
|
-
return sql`${input(left)} in (${sql.join(right.map(input), sql`, `)})
|
|
47
|
+
return bool(sql`${input(left)} in (${sql.join(right.map(input), sql`, `)})`);
|
|
45
48
|
}
|
|
46
|
-
return sql`${input(left)} in ${input(right)}
|
|
49
|
+
return bool(sql`${input(left)} in ${input(right)}`);
|
|
47
50
|
}
|
|
48
51
|
function notInArray(left, right) {
|
|
49
52
|
if (Array.isArray(right)) {
|
|
50
53
|
if (right.length === 0)
|
|
51
54
|
return sql`true`;
|
|
52
|
-
return
|
|
55
|
+
return bool(
|
|
56
|
+
sql`${input(left)} not in (${sql.join(right.map(input), sql`, `)})`
|
|
57
|
+
);
|
|
53
58
|
}
|
|
54
|
-
return sql`${input(left)} not in ${input(right)}
|
|
59
|
+
return bool(sql`${input(left)} not in ${input(right)}`);
|
|
55
60
|
}
|
|
56
61
|
function isNull(value) {
|
|
57
|
-
return sql`${input(value)} is null
|
|
62
|
+
return bool(sql`${input(value)} is null`);
|
|
58
63
|
}
|
|
59
64
|
function isNotNull(value) {
|
|
60
|
-
return sql`${input(value)} is not null
|
|
65
|
+
return bool(sql`${input(value)} is not null`);
|
|
61
66
|
}
|
|
62
67
|
function between(value, left, right) {
|
|
63
|
-
return sql`${input(value)} between ${input(left)} and ${input(right)}
|
|
68
|
+
return bool(sql`${input(value)} between ${input(left)} and ${input(right)}`);
|
|
64
69
|
}
|
|
65
70
|
function notBetween(value, left, right) {
|
|
66
|
-
return
|
|
71
|
+
return bool(
|
|
72
|
+
sql`${input(value)} not between ${input(left)} and ${input(right)}`
|
|
73
|
+
);
|
|
67
74
|
}
|
|
68
75
|
function asc(input2) {
|
|
69
76
|
return sql`${input2} asc`;
|
|
@@ -94,7 +101,7 @@ function when(...cases) {
|
|
|
94
101
|
]);
|
|
95
102
|
}
|
|
96
103
|
function exists(query) {
|
|
97
|
-
return sql`exists (${getQuery(query)})
|
|
104
|
+
return bool(sql`exists (${getQuery(query)})`);
|
|
98
105
|
}
|
|
99
106
|
export {
|
|
100
107
|
and,
|
|
@@ -25,10 +25,10 @@ export declare class Select<Input, Meta extends QueryMeta = QueryMeta> extends U
|
|
|
25
25
|
constructor(data: SelectData<Meta>);
|
|
26
26
|
as(alias: string): SubQuery<Input>;
|
|
27
27
|
from(target: HasTarget | HasSql): Select<Input, Meta>;
|
|
28
|
-
leftJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
29
|
-
rightJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
30
|
-
innerJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
31
|
-
fullJoin(right: HasTable, on: HasSql<boolean>): Select<Input, Meta>;
|
|
28
|
+
leftJoin(right: HasTable | HasTarget, on: HasSql<boolean>): Select<Input, Meta>;
|
|
29
|
+
rightJoin(right: HasTable | HasTarget, on: HasSql<boolean>): Select<Input, Meta>;
|
|
30
|
+
innerJoin(right: HasTable | HasTarget, on: HasSql<boolean>): Select<Input, Meta>;
|
|
31
|
+
fullJoin(right: HasTable | HasTarget, on: HasSql<boolean>): Select<Input, Meta>;
|
|
32
32
|
where(...where: Array<HasSql<boolean> | undefined>): Select<Input, Meta>;
|
|
33
33
|
groupBy(...exprs: Array<HasSql>): Select<Input, Meta>;
|
|
34
34
|
having(having: HasSql<boolean> | ((self: Input) => HasSql<boolean>)): Select<Input, Meta>;
|
|
@@ -69,8 +69,12 @@ type MarkFieldsAsNullable<Input, TableName extends string> = Expand<{
|
|
|
69
69
|
}>;
|
|
70
70
|
export interface SelectionFrom<Input, Meta extends QueryMeta> extends SelectBase<Input, Meta> {
|
|
71
71
|
leftJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<MarkFieldsAsNullable<Input, Name>, Meta>;
|
|
72
|
+
leftJoin(right: HasTarget, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
72
73
|
rightJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
74
|
+
rightJoin(right: HasTarget, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
73
75
|
innerJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
76
|
+
innerJoin(right: HasTarget, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
74
77
|
fullJoin<Definition extends TableDefinition, Name extends string>(right: Table<Definition, Name>, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
78
|
+
fullJoin(right: HasTarget, on: HasSql<boolean>): SelectionFrom<Input, Meta>;
|
|
75
79
|
}
|
|
76
80
|
export {};
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
getQuery,
|
|
5
5
|
getSelection,
|
|
6
6
|
getSql,
|
|
7
|
-
getTable,
|
|
8
7
|
getTarget,
|
|
9
8
|
hasTable,
|
|
10
9
|
hasTarget,
|
|
@@ -50,11 +49,11 @@ var Select = class _Select extends UnionBase {
|
|
|
50
49
|
const { from, select: current } = getData(this);
|
|
51
50
|
return new _Select({
|
|
52
51
|
...getData(this),
|
|
53
|
-
select: current?.join(right, operator),
|
|
52
|
+
select: hasTable(right) ? current?.join(right, operator) : current,
|
|
54
53
|
from: sql.join([
|
|
55
54
|
from,
|
|
56
55
|
sql.unsafe(`${operator} join`),
|
|
57
|
-
|
|
56
|
+
getTarget(right),
|
|
58
57
|
sql`on ${on}`
|
|
59
58
|
])
|
|
60
59
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rado",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"size": "esbuild src/index.ts --bundle --minify --format=esm --outdir=dist",
|
|
9
9
|
"profile": "PROFILE=true bun build.ts && cd bin && (rimraf CPU*.cpuprofile || true) && node --cpu-prof --cpu-prof-interval=100 test && speedscope CPU*.cpuprofile",
|
|
10
10
|
"prepublishOnly": "rm -rf dist && bun run build",
|
|
11
|
-
"cycles": "madge --
|
|
11
|
+
"cycles": "madge --circular src/index.ts src/sqlite.ts src/mysql.ts src/postgres.ts",
|
|
12
12
|
"test:bun": "bun test",
|
|
13
13
|
"test:node": "node --test-force-exit --test-concurrency=1 --import tsx --test \"**/*.test.ts\"",
|
|
14
14
|
"test:deno": "deno test --no-check --allow-read"
|