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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/dist/compat.d.ts +3 -3
  3. package/dist/compat.js +2 -0
  4. package/dist/core/Builder.d.ts +14 -9
  5. package/dist/core/Builder.js +24 -32
  6. package/dist/core/Column.d.ts +26 -8
  7. package/dist/core/Column.js +62 -14
  8. package/dist/core/Constraint.d.ts +16 -5
  9. package/dist/core/Constraint.js +17 -6
  10. package/dist/core/Database.d.ts +11 -4
  11. package/dist/core/Database.js +20 -4
  12. package/dist/core/Dialect.js +2 -2
  13. package/dist/core/Driver.d.ts +3 -3
  14. package/dist/core/Emitter.d.ts +7 -29
  15. package/dist/core/Emitter.js +31 -139
  16. package/dist/core/Index.d.ts +1 -1
  17. package/dist/core/Internal.d.ts +5 -4
  18. package/dist/core/Queries.d.ts +46 -0
  19. package/dist/core/{Query.js → Queries.js} +10 -8
  20. package/dist/core/Resolver.d.ts +2 -2
  21. package/dist/core/Selection.d.ts +7 -10
  22. package/dist/core/Selection.js +15 -13
  23. package/dist/core/Sql.d.ts +8 -29
  24. package/dist/core/Sql.js +67 -118
  25. package/dist/core/Table.d.ts +7 -3
  26. package/dist/core/Table.js +24 -8
  27. package/dist/core/Virtual.d.ts +1 -1
  28. package/dist/core/Virtual.js +15 -14
  29. package/dist/core/expr/Conditions.d.ts +4 -4
  30. package/dist/core/expr/Conditions.js +18 -8
  31. package/dist/core/expr/Field.d.ts +8 -6
  32. package/dist/core/expr/Field.js +3 -3
  33. package/dist/core/expr/Include.d.ts +10 -7
  34. package/dist/core/expr/Include.js +29 -12
  35. package/dist/core/expr/Input.d.ts +3 -1
  36. package/dist/core/expr/Input.js +24 -7
  37. package/dist/core/expr/Json.js +2 -2
  38. package/dist/core/query/CTE.d.ts +8 -0
  39. package/dist/core/query/CTE.js +33 -0
  40. package/dist/core/query/Delete.d.ts +14 -13
  41. package/dist/core/query/Delete.js +32 -6
  42. package/dist/core/query/Insert.d.ts +17 -36
  43. package/dist/core/query/Insert.js +121 -72
  44. package/dist/core/query/Query.d.ts +124 -0
  45. package/dist/core/query/Select.d.ts +74 -33
  46. package/dist/core/query/Select.js +255 -57
  47. package/dist/core/query/Shared.d.ts +3 -0
  48. package/dist/core/query/Shared.js +23 -0
  49. package/dist/core/query/Update.d.ts +13 -13
  50. package/dist/core/query/Update.js +51 -22
  51. package/dist/driver/d1.d.ts +2 -2
  52. package/dist/driver/libsql.d.ts +2 -2
  53. package/dist/driver/mysql2.d.ts +2 -2
  54. package/dist/driver/pg.d.ts +2 -2
  55. package/dist/driver/pglite.d.ts +2 -2
  56. package/dist/index.d.ts +7 -7
  57. package/dist/index.js +7 -7
  58. package/dist/mysql/columns.d.ts +37 -37
  59. package/dist/mysql/columns.js +32 -15
  60. package/dist/mysql/dialect.js +6 -7
  61. package/dist/mysql/diff.js +2 -1
  62. package/dist/mysql.d.ts +3 -2
  63. package/dist/mysql.js +11 -2
  64. package/dist/postgres/columns.d.ts +13 -13
  65. package/dist/postgres/columns.js +15 -6
  66. package/dist/postgres/dialect.js +6 -7
  67. package/dist/postgres/diff.js +2 -1
  68. package/dist/postgres.d.ts +3 -2
  69. package/dist/postgres.js +11 -2
  70. package/dist/sqlite/columns.d.ts +16 -1
  71. package/dist/sqlite/columns.js +36 -3
  72. package/dist/sqlite/dialect.js +6 -6
  73. package/dist/sqlite/diff.js +3 -5
  74. package/dist/sqlite.d.ts +3 -2
  75. package/dist/sqlite.js +11 -2
  76. package/dist/universal/columns.js +34 -18
  77. package/dist/universal/functions.js +4 -1
  78. package/package.json +4 -4
  79. package/dist/core/Join.d.ts +0 -1
  80. package/dist/core/Query.d.ts +0 -46
  81. package/dist/core/query/Union.d.ts +0 -35
  82. package/dist/core/query/Union.js +0 -107
  83. /package/dist/core/{Join.js → query/Query.js} +0 -0
@@ -1,5 +1,9 @@
1
1
  // src/postgres/columns.ts
2
- import { JsonColumn, column } from "../core/Column.js";
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(name, options) {
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(name, options) {
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(name, options) {
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(name, options) {
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(name, options) {
159
+ function varchar(...args) {
160
+ const { name, options } = columnConfig(args);
152
161
  return column({
153
162
  name,
154
163
  type: column.varchar(options?.length)
@@ -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.emitTo(this);
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
  }
@@ -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, sql.chunk("emitColumn", schemaInstruction)]
149
+ addColumn: [column2, formatColumn(schemaInstruction)]
149
150
  })
150
151
  );
151
152
  } else {
@@ -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/Union.js';
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/Union.js";
11
+ } from "./core/query/Select.js";
11
12
  import { schema } from "./core/Schema.js";
12
- import { alias, table } from "./core/Table.js";
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
  };
@@ -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>;
@@ -1,5 +1,9 @@
1
1
  // src/sqlite/columns.ts
2
- import { JsonColumn, column } from "../core/Column.js";
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(name) {
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(name) {
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) {
@@ -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.emitTo(this);
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
  }
@@ -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
- sql.chunk("emitColumn", {
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/Union.js';
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/Union.js";
9
- import { alias, table } from "./core/Table.js";
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 = sql.universal({
5
- sqlite: sql`integer`,
6
- postgres: sql`integer generated always as identity`,
7
- mysql: sql`int not null auto_increment`
8
- });
9
- var blobType = sql.universal({
10
- postgres: sql`bytea`,
11
- default: sql`blob`
12
- });
13
- var numberType = sql.universal({
14
- mysql: sql`double`,
15
- default: sql`numeric`
16
- });
17
- var jsonbType = sql.universal({
18
- mysql: sql`json`,
19
- default: sql`jsonb`
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(slices.map(input), sql` || `)
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.0.15",
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": "rm -rf dist && bun run build",
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.4.0",
30
- "@biomejs/biome": "^1.8.3",
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",
@@ -1 +0,0 @@
1
- export type JoinOperator = 'left' | 'right' | 'inner' | 'full';
@@ -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>;
@@ -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