rado 1.0.15 → 1.2.1
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/README.md +2 -2
- package/dist/compat.d.ts +3 -3
- package/dist/compat.js +2 -0
- package/dist/core/Builder.d.ts +14 -9
- package/dist/core/Builder.js +24 -32
- package/dist/core/Column.d.ts +26 -8
- package/dist/core/Column.js +62 -14
- package/dist/core/Constraint.d.ts +16 -5
- package/dist/core/Constraint.js +17 -6
- package/dist/core/Database.d.ts +11 -4
- package/dist/core/Database.js +20 -4
- package/dist/core/Dialect.js +2 -2
- package/dist/core/Driver.d.ts +3 -3
- package/dist/core/Emitter.d.ts +7 -29
- package/dist/core/Emitter.js +31 -139
- package/dist/core/Index.d.ts +1 -1
- package/dist/core/Internal.d.ts +5 -4
- package/dist/core/Queries.d.ts +46 -0
- package/dist/core/{Query.js → Queries.js} +10 -8
- package/dist/core/Resolver.d.ts +2 -2
- package/dist/core/Selection.d.ts +7 -10
- package/dist/core/Selection.js +15 -13
- package/dist/core/Sql.d.ts +8 -29
- package/dist/core/Sql.js +67 -118
- package/dist/core/Table.d.ts +7 -3
- package/dist/core/Table.js +24 -8
- package/dist/core/Virtual.d.ts +1 -1
- package/dist/core/Virtual.js +15 -14
- package/dist/core/expr/Conditions.d.ts +4 -4
- package/dist/core/expr/Conditions.js +18 -8
- package/dist/core/expr/Field.d.ts +8 -6
- package/dist/core/expr/Field.js +3 -3
- package/dist/core/expr/Include.d.ts +10 -7
- package/dist/core/expr/Include.js +29 -12
- package/dist/core/expr/Input.d.ts +3 -1
- package/dist/core/expr/Input.js +24 -7
- package/dist/core/expr/Json.js +2 -2
- package/dist/core/query/CTE.d.ts +8 -0
- package/dist/core/query/CTE.js +33 -0
- package/dist/core/query/Delete.d.ts +14 -13
- package/dist/core/query/Delete.js +32 -6
- package/dist/core/query/Insert.d.ts +17 -36
- package/dist/core/query/Insert.js +121 -72
- package/dist/core/query/Query.d.ts +124 -0
- package/dist/core/query/Select.d.ts +74 -33
- package/dist/core/query/Select.js +255 -57
- package/dist/core/query/Shared.d.ts +3 -0
- package/dist/core/query/Shared.js +23 -0
- package/dist/core/query/Update.d.ts +13 -13
- package/dist/core/query/Update.js +51 -22
- package/dist/driver/d1.d.ts +2 -2
- package/dist/driver/libsql.d.ts +2 -2
- package/dist/driver/mysql2.d.ts +2 -2
- package/dist/driver/pg.d.ts +2 -2
- package/dist/driver/pglite.d.ts +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.js +7 -7
- package/dist/mysql/columns.d.ts +37 -37
- package/dist/mysql/columns.js +32 -15
- package/dist/mysql/dialect.js +6 -7
- package/dist/mysql/diff.js +2 -1
- package/dist/mysql.d.ts +3 -2
- package/dist/mysql.js +11 -2
- package/dist/postgres/columns.d.ts +13 -13
- package/dist/postgres/columns.js +15 -6
- package/dist/postgres/dialect.js +6 -7
- package/dist/postgres/diff.js +2 -1
- package/dist/postgres.d.ts +3 -2
- package/dist/postgres.js +11 -2
- package/dist/sqlite/columns.d.ts +16 -1
- package/dist/sqlite/columns.js +36 -3
- package/dist/sqlite/dialect.js +6 -6
- package/dist/sqlite/diff.js +3 -5
- package/dist/sqlite.d.ts +3 -2
- package/dist/sqlite.js +11 -2
- package/dist/universal/columns.js +34 -18
- package/dist/universal/functions.js +4 -1
- package/package.json +4 -4
- package/dist/core/Join.d.ts +0 -1
- package/dist/core/Query.d.ts +0 -46
- package/dist/core/query/Union.d.ts +0 -35
- package/dist/core/query/Union.js +0 -107
- /package/dist/core/{Join.js → query/Query.js} +0 -0
package/dist/postgres/columns.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/postgres/columns.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
JsonColumn,
|
|
4
|
+
column,
|
|
5
|
+
columnConfig
|
|
6
|
+
} from "../core/Column.js";
|
|
3
7
|
function bigint(name, options) {
|
|
4
8
|
return column({
|
|
5
9
|
name,
|
|
@@ -54,7 +58,8 @@ var int = integer;
|
|
|
54
58
|
function oid(name) {
|
|
55
59
|
return column({ name, type: column.oid() });
|
|
56
60
|
}
|
|
57
|
-
function interval(
|
|
61
|
+
function interval(...args) {
|
|
62
|
+
const { name, options } = columnConfig(args);
|
|
58
63
|
return column({
|
|
59
64
|
name,
|
|
60
65
|
type: column[options?.fields ? `interval ${options.fields}` : "interval"](
|
|
@@ -104,7 +109,8 @@ function macaddr(name) {
|
|
|
104
109
|
function macaddr8(name) {
|
|
105
110
|
return column({ name, type: column.macaddr8() });
|
|
106
111
|
}
|
|
107
|
-
function numeric(
|
|
112
|
+
function numeric(...args) {
|
|
113
|
+
const { name, options } = columnConfig(args);
|
|
108
114
|
return column({
|
|
109
115
|
name,
|
|
110
116
|
type: column.numeric(options?.precision, options?.scale)
|
|
@@ -125,7 +131,8 @@ function smallint(name) {
|
|
|
125
131
|
function smallserial(name) {
|
|
126
132
|
return column({ name, type: column.smallserial() });
|
|
127
133
|
}
|
|
128
|
-
function time(
|
|
134
|
+
function time(...args) {
|
|
135
|
+
const { name, options } = columnConfig(args);
|
|
129
136
|
return column({
|
|
130
137
|
name,
|
|
131
138
|
type: column[options?.withTimeZone ? "time with time zone" : "time"](
|
|
@@ -133,7 +140,8 @@ function time(name, options) {
|
|
|
133
140
|
)
|
|
134
141
|
});
|
|
135
142
|
}
|
|
136
|
-
function timestamp(
|
|
143
|
+
function timestamp(...args) {
|
|
144
|
+
const { name, options } = columnConfig(args);
|
|
137
145
|
return column({
|
|
138
146
|
name,
|
|
139
147
|
type: column[options?.withTimeZone ? "timestamp with time zone" : "timestamp"](options?.precision),
|
|
@@ -148,7 +156,8 @@ function timestamp(name, options) {
|
|
|
148
156
|
function uuid(name) {
|
|
149
157
|
return column({ name, type: column.uuid() });
|
|
150
158
|
}
|
|
151
|
-
function varchar(
|
|
159
|
+
function varchar(...args) {
|
|
160
|
+
const { name, options } = columnConfig(args);
|
|
152
161
|
return column({
|
|
153
162
|
name,
|
|
154
163
|
type: column.varchar(options?.length)
|
package/dist/postgres/dialect.js
CHANGED
|
@@ -12,13 +12,16 @@ var postgresDialect = new Dialect(
|
|
|
12
12
|
"postgres",
|
|
13
13
|
class extends Emitter {
|
|
14
14
|
runtime = "postgres";
|
|
15
|
-
paramIndex = 0;
|
|
16
15
|
emitValue(value) {
|
|
17
|
-
this.sql += `$${++this.paramIndex}`;
|
|
18
16
|
this.params.push(new ValueParam(value));
|
|
17
|
+
this.sql += `$${this.params.length}`;
|
|
18
|
+
}
|
|
19
|
+
emitPlaceholder(name) {
|
|
20
|
+
this.params.push(new NamedParam(name));
|
|
21
|
+
this.sql += `$${this.params.length}`;
|
|
19
22
|
}
|
|
20
23
|
emitJsonPath({ target, asSql, segments }) {
|
|
21
|
-
target.
|
|
24
|
+
target.emit(this);
|
|
22
25
|
for (let i = 0; i < segments.length; i++) {
|
|
23
26
|
const access = segments[i];
|
|
24
27
|
if (i <= segments.length - 2) this.sql += "->";
|
|
@@ -35,10 +38,6 @@ var postgresDialect = new Dialect(
|
|
|
35
38
|
return this.sql += this.quoteString(value);
|
|
36
39
|
this.sql += this.quoteString(JSON.stringify(value));
|
|
37
40
|
}
|
|
38
|
-
emitPlaceholder(name) {
|
|
39
|
-
this.sql += `$${++this.paramIndex}`;
|
|
40
|
-
this.params.push(new NamedParam(name));
|
|
41
|
-
}
|
|
42
41
|
quoteString(input) {
|
|
43
42
|
return SINGLE_QUOTE + input.replace(MATCH_SINGLE_QUOTE, ESCAPE_SINGLE_QUOTE) + SINGLE_QUOTE;
|
|
44
43
|
}
|
package/dist/postgres/diff.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/postgres/diff.ts
|
|
2
|
+
import { formatColumn } from "../core/Column.js";
|
|
2
3
|
import { getData, getTable } from "../core/Internal.js";
|
|
3
4
|
import { sql } from "../core/Sql.js";
|
|
4
5
|
import { table } from "../core/Table.js";
|
|
@@ -145,7 +146,7 @@ var postgresDiff = (hasTable) => {
|
|
|
145
146
|
stmts.push(
|
|
146
147
|
sql.query({
|
|
147
148
|
alterTable,
|
|
148
|
-
addColumn: [column2,
|
|
149
|
+
addColumn: [column2, formatColumn(schemaInstruction)]
|
|
149
150
|
})
|
|
150
151
|
);
|
|
151
152
|
} else {
|
package/dist/postgres.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { foreignKey, primaryKey, unique } from './core/Constraint.js';
|
|
1
2
|
export { index, uniqueIndex } from './core/Index.js';
|
|
2
|
-
export { except, exceptAll, intersect, intersectAll, union, unionAll } from './core/query/
|
|
3
|
+
export { except, exceptAll, intersect, intersectAll, union, unionAll } from './core/query/Select.js';
|
|
3
4
|
export { schema as pgSchema } from './core/Schema.js';
|
|
4
|
-
export { alias, table as pgTable } from './core/Table.js';
|
|
5
|
+
export { alias, table as pgTable, tableCreator as pgTableCreator } from './core/Table.js';
|
|
5
6
|
export * from './postgres/builder.js';
|
|
6
7
|
export * from './postgres/columns.js';
|
|
7
8
|
export * from './postgres/dialect.js';
|
package/dist/postgres.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/postgres.ts
|
|
2
|
+
import { foreignKey, primaryKey, unique } from "./core/Constraint.js";
|
|
2
3
|
import { index, uniqueIndex } from "./core/Index.js";
|
|
3
4
|
import {
|
|
4
5
|
except,
|
|
@@ -7,9 +8,13 @@ import {
|
|
|
7
8
|
intersectAll,
|
|
8
9
|
union,
|
|
9
10
|
unionAll
|
|
10
|
-
} from "./core/query/
|
|
11
|
+
} from "./core/query/Select.js";
|
|
11
12
|
import { schema } from "./core/Schema.js";
|
|
12
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
alias,
|
|
15
|
+
table,
|
|
16
|
+
tableCreator
|
|
17
|
+
} from "./core/Table.js";
|
|
13
18
|
export * from "./postgres/builder.js";
|
|
14
19
|
export * from "./postgres/columns.js";
|
|
15
20
|
export * from "./postgres/dialect.js";
|
|
@@ -17,12 +22,16 @@ export {
|
|
|
17
22
|
alias,
|
|
18
23
|
except,
|
|
19
24
|
exceptAll,
|
|
25
|
+
foreignKey,
|
|
20
26
|
index,
|
|
21
27
|
intersect,
|
|
22
28
|
intersectAll,
|
|
23
29
|
schema as pgSchema,
|
|
24
30
|
table as pgTable,
|
|
31
|
+
tableCreator as pgTableCreator,
|
|
32
|
+
primaryKey,
|
|
25
33
|
union,
|
|
26
34
|
unionAll,
|
|
35
|
+
unique,
|
|
27
36
|
uniqueIndex
|
|
28
37
|
};
|
package/dist/sqlite/columns.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
import { type Column, JsonColumn } from '../core/Column.js';
|
|
1
|
+
import { type Column, type ColumnArguments, JsonColumn } from '../core/Column.js';
|
|
2
2
|
export declare function boolean(name?: string): Column<boolean | null>;
|
|
3
3
|
export declare function integer(name?: string): Column<number | null>;
|
|
4
|
+
export declare function integer(...args: ColumnArguments<{
|
|
5
|
+
mode: 'boolean';
|
|
6
|
+
}>): Column<boolean | null>;
|
|
7
|
+
export declare function integer(...args: ColumnArguments<{
|
|
8
|
+
mode: 'timestamp';
|
|
9
|
+
}>): Column<Date | null>;
|
|
10
|
+
export declare function integer(...args: ColumnArguments<{
|
|
11
|
+
mode: 'timestamp_ms';
|
|
12
|
+
}>): Column<Date | null>;
|
|
4
13
|
export declare const int: typeof integer;
|
|
5
14
|
export declare function blob(name?: string): Column<Uint8Array | null>;
|
|
15
|
+
export declare function blob(...args: ColumnArguments<{
|
|
16
|
+
mode: 'bigint';
|
|
17
|
+
}>): Column<BigInt | null>;
|
|
18
|
+
export declare function blob<T>(...args: ColumnArguments<{
|
|
19
|
+
mode: 'json';
|
|
20
|
+
}>): Column<T | null>;
|
|
6
21
|
export declare function text(name?: string): Column<string | null>;
|
|
7
22
|
export declare function real(name?: string): Column<number | null>;
|
|
8
23
|
export declare function numeric(name?: string): Column<number | null>;
|
package/dist/sqlite/columns.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/sqlite/columns.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
JsonColumn,
|
|
4
|
+
column,
|
|
5
|
+
columnConfig
|
|
6
|
+
} from "../core/Column.js";
|
|
3
7
|
function boolean(name) {
|
|
4
8
|
return column({
|
|
5
9
|
name,
|
|
@@ -12,11 +16,40 @@ function boolean(name) {
|
|
|
12
16
|
}
|
|
13
17
|
});
|
|
14
18
|
}
|
|
15
|
-
function integer(
|
|
19
|
+
function integer(...args) {
|
|
20
|
+
const { name, options } = columnConfig(args);
|
|
21
|
+
if (options?.mode === "timestamp" || options?.mode === "timestamp_ms") {
|
|
22
|
+
const scale = options.mode === "timestamp" ? 1e3 : 1;
|
|
23
|
+
return column({
|
|
24
|
+
name,
|
|
25
|
+
type: column.integer(),
|
|
26
|
+
mapFromDriverValue(value) {
|
|
27
|
+
if (value === null) return null;
|
|
28
|
+
return new Date(value * scale);
|
|
29
|
+
},
|
|
30
|
+
mapToDriverValue(value) {
|
|
31
|
+
return Math.floor(value.getTime() / scale);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (options?.mode === "boolean") return boolean();
|
|
16
36
|
return column({ name, type: column.integer() });
|
|
17
37
|
}
|
|
18
38
|
var int = integer;
|
|
19
|
-
function blob(
|
|
39
|
+
function blob(...args) {
|
|
40
|
+
const { name, options } = columnConfig(args);
|
|
41
|
+
if (options?.mode === "json") return json(name);
|
|
42
|
+
if (options?.mode === "bigint")
|
|
43
|
+
return column({
|
|
44
|
+
name,
|
|
45
|
+
type: column.blob(),
|
|
46
|
+
mapFromDriverValue(value) {
|
|
47
|
+
return BigInt(value);
|
|
48
|
+
},
|
|
49
|
+
mapToDriverValue(value) {
|
|
50
|
+
return value.toString();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
20
53
|
return column({ name, type: column.blob() });
|
|
21
54
|
}
|
|
22
55
|
function text(name) {
|
package/dist/sqlite/dialect.js
CHANGED
|
@@ -15,11 +15,15 @@ var sqliteDialect = new Dialect(
|
|
|
15
15
|
return typeof value === "boolean" ? value ? 1 : 0 : value;
|
|
16
16
|
}
|
|
17
17
|
emitValue(value) {
|
|
18
|
-
this.sql += "?";
|
|
19
18
|
this.params.push(new ValueParam(value));
|
|
19
|
+
this.sql += "?";
|
|
20
|
+
}
|
|
21
|
+
emitPlaceholder(name) {
|
|
22
|
+
this.params.push(new NamedParam(name));
|
|
23
|
+
this.sql += "?";
|
|
20
24
|
}
|
|
21
25
|
emitJsonPath({ target, asSql, segments }) {
|
|
22
|
-
target.
|
|
26
|
+
target.emit(this);
|
|
23
27
|
this.sql += asSql ? "->>" : "->";
|
|
24
28
|
this.sql += this.quoteString(
|
|
25
29
|
`$${segments.map((p) => typeof p === "number" ? `[${p}]` : `.${p}`).join("")}`
|
|
@@ -33,10 +37,6 @@ var sqliteDialect = new Dialect(
|
|
|
33
37
|
if (typeof value === "boolean") return this.sql += value ? "1" : "0";
|
|
34
38
|
this.sql += `json(${this.quoteString(JSON.stringify(value))})`;
|
|
35
39
|
}
|
|
36
|
-
emitPlaceholder(name) {
|
|
37
|
-
this.sql += "?";
|
|
38
|
-
this.params.push(new NamedParam(name));
|
|
39
|
-
}
|
|
40
40
|
emitIdentifier(identifier) {
|
|
41
41
|
this.sql += DOUBLE_QUOTE + identifier.replace(MATCH_DOUBLE_QUOTE, ESCAPE_DOUBLE_QUOTE) + DOUBLE_QUOTE;
|
|
42
42
|
}
|
package/dist/sqlite/diff.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/sqlite/diff.ts
|
|
2
|
+
import { formatColumn } from "../core/Column.js";
|
|
2
3
|
import { Rollback } from "../core/Database.js";
|
|
3
4
|
import { getData, getQuery, getTable } from "../core/Internal.js";
|
|
4
5
|
import { sql } from "../core/Sql.js";
|
|
@@ -37,7 +38,7 @@ var sqliteDiff = (targetTable) => {
|
|
|
37
38
|
return [
|
|
38
39
|
column2.name,
|
|
39
40
|
inline(
|
|
40
|
-
|
|
41
|
+
formatColumn({
|
|
41
42
|
type: sql.unsafe(column2.type.toLowerCase()),
|
|
42
43
|
notNull: column2.notnull,
|
|
43
44
|
primary: hasSinglePrimaryKey && column2.pk === 1,
|
|
@@ -50,10 +51,7 @@ var sqliteDiff = (targetTable) => {
|
|
|
50
51
|
const schemaColumns = new Map(
|
|
51
52
|
Object.entries(tableApi.columns).map(([name, column2]) => {
|
|
52
53
|
const columnApi = getData(column2);
|
|
53
|
-
return [
|
|
54
|
-
columnApi.name ?? name,
|
|
55
|
-
inline(sql.chunk("emitColumn", columnApi))
|
|
56
|
-
];
|
|
54
|
+
return [columnApi.name ?? name, inline(formatColumn(columnApi))];
|
|
57
55
|
})
|
|
58
56
|
);
|
|
59
57
|
const localIndexes = new Map(
|
package/dist/sqlite.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export { foreignKey, primaryKey, unique } from './core/Constraint.js';
|
|
1
2
|
export { index, uniqueIndex } from './core/Index.js';
|
|
2
|
-
export { except, intersect, union, unionAll } from './core/query/
|
|
3
|
-
export { alias, table as sqliteTable } from './core/Table.js';
|
|
3
|
+
export { except, intersect, union, unionAll } from './core/query/Select.js';
|
|
4
|
+
export { alias, table as sqliteTable, tableCreator as sqliteTableCreator } from './core/Table.js';
|
|
4
5
|
export * from './sqlite/builder.js';
|
|
5
6
|
export * from './sqlite/columns.js';
|
|
6
7
|
export * from './sqlite/dialect.js';
|
package/dist/sqlite.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// src/sqlite.ts
|
|
2
|
+
import { foreignKey, primaryKey, unique } from "./core/Constraint.js";
|
|
2
3
|
import { index, uniqueIndex } from "./core/Index.js";
|
|
3
4
|
import {
|
|
4
5
|
except,
|
|
5
6
|
intersect,
|
|
6
7
|
union,
|
|
7
8
|
unionAll
|
|
8
|
-
} from "./core/query/
|
|
9
|
-
import {
|
|
9
|
+
} from "./core/query/Select.js";
|
|
10
|
+
import {
|
|
11
|
+
alias,
|
|
12
|
+
table,
|
|
13
|
+
tableCreator
|
|
14
|
+
} from "./core/Table.js";
|
|
10
15
|
export * from "./sqlite/builder.js";
|
|
11
16
|
export * from "./sqlite/columns.js";
|
|
12
17
|
export * from "./sqlite/dialect.js";
|
|
@@ -14,10 +19,14 @@ export * from "./sqlite/functions.js";
|
|
|
14
19
|
export {
|
|
15
20
|
alias,
|
|
16
21
|
except,
|
|
22
|
+
foreignKey,
|
|
17
23
|
index,
|
|
18
24
|
intersect,
|
|
25
|
+
primaryKey,
|
|
19
26
|
table as sqliteTable,
|
|
27
|
+
tableCreator as sqliteTableCreator,
|
|
20
28
|
union,
|
|
21
29
|
unionAll,
|
|
30
|
+
unique,
|
|
22
31
|
uniqueIndex
|
|
23
32
|
};
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
// src/universal/columns.ts
|
|
2
|
-
import { JsonColumn, column } from "../core/Column.js";
|
|
2
|
+
import { ColumnType, JsonColumn, column } from "../core/Column.js";
|
|
3
3
|
import { sql } from "../core/Sql.js";
|
|
4
|
-
var idType =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
var idType = new ColumnType(
|
|
5
|
+
"id",
|
|
6
|
+
[],
|
|
7
|
+
sql.universal({
|
|
8
|
+
sqlite: sql`integer`,
|
|
9
|
+
postgres: sql`integer generated always as identity`,
|
|
10
|
+
mysql: sql`int not null auto_increment`
|
|
11
|
+
})
|
|
12
|
+
);
|
|
13
|
+
var blobType = new ColumnType(
|
|
14
|
+
"blob",
|
|
15
|
+
[],
|
|
16
|
+
sql.universal({
|
|
17
|
+
postgres: sql`bytea`,
|
|
18
|
+
default: sql`blob`
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
var numberType = new ColumnType(
|
|
22
|
+
"number",
|
|
23
|
+
[],
|
|
24
|
+
sql.universal({
|
|
25
|
+
mysql: sql`double`,
|
|
26
|
+
default: sql`numeric`
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
var jsonbType = new ColumnType(
|
|
30
|
+
"json",
|
|
31
|
+
[],
|
|
32
|
+
sql.universal({
|
|
33
|
+
mysql: sql`json`,
|
|
34
|
+
default: sql`jsonb`
|
|
35
|
+
})
|
|
36
|
+
);
|
|
21
37
|
function id(name) {
|
|
22
38
|
return column({
|
|
23
39
|
name,
|
|
@@ -13,7 +13,10 @@ function lastInsertId() {
|
|
|
13
13
|
function concat(...slices) {
|
|
14
14
|
return sql.universal({
|
|
15
15
|
mysql: Functions.concat(...slices),
|
|
16
|
-
default: sql.join(
|
|
16
|
+
default: sql.join(
|
|
17
|
+
slices.map((slice) => input(slice)),
|
|
18
|
+
sql` || `
|
|
19
|
+
)
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
export {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rado",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && bun build.ts",
|
|
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
|
-
"prepublishOnly": "
|
|
10
|
+
"prepublishOnly": "bun run build",
|
|
11
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\"",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"files": ["dist"],
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@alinea/suite": "^0.
|
|
30
|
-
"@biomejs/biome": "^1.
|
|
29
|
+
"@alinea/suite": "^0.6.2",
|
|
30
|
+
"@biomejs/biome": "^1.9.4",
|
|
31
31
|
"@cloudflare/workers-types": "^4.20230628.0",
|
|
32
32
|
"@electric-sql/pglite": "^0.2.12",
|
|
33
33
|
"@libsql/client": "^0.10.0",
|
package/dist/core/Join.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type JoinOperator = 'left' | 'right' | 'inner' | 'full';
|
package/dist/core/Query.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type HasQuery, type HasResolver, type HasSql, type HasTarget, internalData, internalQuery } from './Internal.js';
|
|
2
|
-
import type { Deliver, QueryMeta } from './MetaData.js';
|
|
3
|
-
import type { PreparedStatement, Resolver } from './Resolver.js';
|
|
4
|
-
import type { Sql } from './Sql.js';
|
|
5
|
-
export declare class QueryData<Meta extends QueryMeta> {
|
|
6
|
-
resolver?: Resolver<Meta>;
|
|
7
|
-
cte?: {
|
|
8
|
-
recursive: boolean;
|
|
9
|
-
definitions: Array<HasQuery & HasTarget>;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
type Exec = () => any;
|
|
13
|
-
declare class Executable<Result, Meta extends QueryMeta> implements PromiseLike<Array<Result>> {
|
|
14
|
-
#private;
|
|
15
|
-
private brand;
|
|
16
|
-
constructor(exec: Exec);
|
|
17
|
-
[Symbol.iterator](): Generator<Promise<unknown>, Array<Result>, unknown>;
|
|
18
|
-
run(): Deliver<Meta, void>;
|
|
19
|
-
then<TResult1 = Array<Result>, TResult2 = never>(onfulfilled?: ((value: Array<Result>) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
|
|
20
|
-
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | undefined | null): Promise<Array<Result> | TResult>;
|
|
21
|
-
finally(onfinally?: (() => void) | undefined | null): Promise<Array<Result>>;
|
|
22
|
-
}
|
|
23
|
-
export declare class QueryBatch<Results, Meta extends QueryMeta> extends Executable<Results, Meta> {
|
|
24
|
-
constructor(queryResolver: Resolver, queries: Array<HasSql | HasQuery>);
|
|
25
|
-
}
|
|
26
|
-
export declare abstract class Query<Result, Meta extends QueryMeta> extends Executable<Result, Meta> {
|
|
27
|
-
#private;
|
|
28
|
-
readonly [internalData]: QueryData<Meta>;
|
|
29
|
-
abstract [internalQuery]: Sql;
|
|
30
|
-
constructor(data: QueryData<Meta>);
|
|
31
|
-
all(db?: HasResolver): Deliver<Meta, Array<Result>>;
|
|
32
|
-
get(db?: HasResolver): Deliver<Meta, Result | null>;
|
|
33
|
-
run(db?: HasResolver): Deliver<Meta, void>;
|
|
34
|
-
prepare<Inputs extends Record<string, unknown>>(name?: string): PreparedQuery<Result, Inputs, Meta>;
|
|
35
|
-
toSQL(db?: HasResolver): {
|
|
36
|
-
sql: string;
|
|
37
|
-
params: Array<unknown>;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export interface PreparedQuery<Result, Inputs extends Record<string, unknown>, Meta extends QueryMeta> extends PreparedStatement<Meta> {
|
|
41
|
-
all(inputs?: Inputs): Deliver<Meta, Array<Result>>;
|
|
42
|
-
get(inputs?: Inputs): Deliver<Meta, Result>;
|
|
43
|
-
run(inputs?: Inputs): Deliver<Meta, void>;
|
|
44
|
-
execute(inputs?: Inputs): Promise<Array<Result>>;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { type HasQuery, type HasSelection, type HasSql, type HasTarget, internalData, internalQuery, internalSelection } from '../Internal.js';
|
|
2
|
-
import type { IsMysql, IsPostgres, QueryMeta } from '../MetaData.js';
|
|
3
|
-
import { Query, type QueryData } from '../Query.js';
|
|
4
|
-
import type { Selection, SelectionRow } from '../Selection.js';
|
|
5
|
-
import { Sql } from '../Sql.js';
|
|
6
|
-
export interface UnionBaseData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
7
|
-
select?: Selection;
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class UnionBase<Input, Meta extends QueryMeta = QueryMeta> extends Query<SelectionRow<Input>, Meta> {
|
|
10
|
-
#private;
|
|
11
|
-
readonly [internalData]: UnionBaseData<Meta>;
|
|
12
|
-
union(right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
13
|
-
unionAll(right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
14
|
-
intersect(right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
15
|
-
intersectAll(this: UnionBase<Input, IsPostgres | IsMysql>, right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
16
|
-
except(right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
17
|
-
exceptAll(this: UnionBase<Input, IsPostgres | IsMysql>, right: UnionBase<Input, Meta> | ((self: Input & HasTarget) => UnionBase<Input, Meta>)): Union<Input, Meta>;
|
|
18
|
-
}
|
|
19
|
-
export interface UnionData<Meta extends QueryMeta = QueryMeta> extends UnionBaseData<Meta> {
|
|
20
|
-
left: HasQuery;
|
|
21
|
-
operator: HasSql;
|
|
22
|
-
right: HasQuery;
|
|
23
|
-
}
|
|
24
|
-
export declare class Union<Result, Meta extends QueryMeta = QueryMeta> extends UnionBase<Result, Meta> implements HasSelection {
|
|
25
|
-
readonly [internalData]: UnionData<Meta>;
|
|
26
|
-
readonly [internalSelection]: Selection;
|
|
27
|
-
constructor(data: UnionData<Meta>);
|
|
28
|
-
get [internalQuery](): Sql;
|
|
29
|
-
}
|
|
30
|
-
export declare function union<Result, Meta extends QueryMeta>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>, ...rest: Array<UnionBase<Result, Meta>>): Union<Result, Meta>;
|
|
31
|
-
export declare function unionAll<Result, Meta extends QueryMeta>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>): Union<Result, Meta>;
|
|
32
|
-
export declare function intersect<Result, Meta extends QueryMeta>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>): Union<Result, Meta>;
|
|
33
|
-
export declare function intersectAll<Result, Meta extends IsPostgres | IsMysql>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>): Union<Result, Meta>;
|
|
34
|
-
export declare function except<Result, Meta extends QueryMeta>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>): Union<Result, Meta>;
|
|
35
|
-
export declare function exceptAll<Result, Meta extends IsPostgres | IsMysql>(left: UnionBase<Result, Meta>, right: UnionBase<Result, Meta>): Union<Result, Meta>;
|
package/dist/core/query/Union.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// src/core/query/Union.ts
|
|
2
|
-
import {
|
|
3
|
-
getData,
|
|
4
|
-
internalData,
|
|
5
|
-
internalQuery,
|
|
6
|
-
internalSelection
|
|
7
|
-
} from "../Internal.js";
|
|
8
|
-
import { Query } from "../Query.js";
|
|
9
|
-
import { Sql, sql } from "../Sql.js";
|
|
10
|
-
var UnionBase = class extends Query {
|
|
11
|
-
[internalData];
|
|
12
|
-
#makeSelf() {
|
|
13
|
-
const { select } = getData(this);
|
|
14
|
-
return select.makeVirtual(Sql.SELF_TARGET);
|
|
15
|
-
}
|
|
16
|
-
union(right) {
|
|
17
|
-
return new Union({
|
|
18
|
-
...getData(this),
|
|
19
|
-
left: this,
|
|
20
|
-
operator: sql`union`,
|
|
21
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
unionAll(right) {
|
|
25
|
-
return new Union({
|
|
26
|
-
...getData(this),
|
|
27
|
-
left: this,
|
|
28
|
-
operator: sql`union all`,
|
|
29
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
intersect(right) {
|
|
33
|
-
return new Union({
|
|
34
|
-
...getData(this),
|
|
35
|
-
left: this,
|
|
36
|
-
operator: sql`intersect`,
|
|
37
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
intersectAll(right) {
|
|
41
|
-
return new Union({
|
|
42
|
-
...getData(this),
|
|
43
|
-
left: this,
|
|
44
|
-
operator: sql`intersect all`,
|
|
45
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
except(right) {
|
|
49
|
-
return new Union({
|
|
50
|
-
...getData(this),
|
|
51
|
-
left: this,
|
|
52
|
-
operator: sql`except`,
|
|
53
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
exceptAll(right) {
|
|
57
|
-
return new Union({
|
|
58
|
-
...getData(this),
|
|
59
|
-
left: this,
|
|
60
|
-
operator: sql`except all`,
|
|
61
|
-
right: typeof right === "function" ? right(this.#makeSelf()) : right
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var Union = class extends UnionBase {
|
|
66
|
-
[internalData];
|
|
67
|
-
[internalSelection];
|
|
68
|
-
constructor(data) {
|
|
69
|
-
super(data);
|
|
70
|
-
this[internalData] = data;
|
|
71
|
-
this[internalSelection] = data.select;
|
|
72
|
-
}
|
|
73
|
-
get [internalQuery]() {
|
|
74
|
-
return sql.chunk("emitUnion", getData(this));
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
function union(left, right, ...rest) {
|
|
78
|
-
return [right, ...rest].reduce(
|
|
79
|
-
(acc, query) => acc.union(query),
|
|
80
|
-
left
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
function unionAll(left, right) {
|
|
84
|
-
return left.unionAll(right);
|
|
85
|
-
}
|
|
86
|
-
function intersect(left, right) {
|
|
87
|
-
return left.intersect(right);
|
|
88
|
-
}
|
|
89
|
-
function intersectAll(left, right) {
|
|
90
|
-
return left.intersectAll(right);
|
|
91
|
-
}
|
|
92
|
-
function except(left, right) {
|
|
93
|
-
return left.except(right);
|
|
94
|
-
}
|
|
95
|
-
function exceptAll(left, right) {
|
|
96
|
-
return left.exceptAll(right);
|
|
97
|
-
}
|
|
98
|
-
export {
|
|
99
|
-
Union,
|
|
100
|
-
UnionBase,
|
|
101
|
-
except,
|
|
102
|
-
exceptAll,
|
|
103
|
-
intersect,
|
|
104
|
-
intersectAll,
|
|
105
|
-
union,
|
|
106
|
-
unionAll
|
|
107
|
-
};
|
|
File without changes
|