rado 1.0.15 → 1.2.0

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 (81) hide show
  1. package/dist/compat.d.ts +3 -3
  2. package/dist/compat.js +2 -0
  3. package/dist/core/Builder.d.ts +14 -9
  4. package/dist/core/Builder.js +24 -32
  5. package/dist/core/Column.d.ts +13 -4
  6. package/dist/core/Column.js +43 -8
  7. package/dist/core/Constraint.d.ts +16 -5
  8. package/dist/core/Constraint.js +17 -6
  9. package/dist/core/Database.d.ts +11 -4
  10. package/dist/core/Database.js +20 -4
  11. package/dist/core/Dialect.js +2 -2
  12. package/dist/core/Driver.d.ts +3 -3
  13. package/dist/core/Emitter.d.ts +7 -29
  14. package/dist/core/Emitter.js +31 -139
  15. package/dist/core/Index.d.ts +1 -1
  16. package/dist/core/Internal.d.ts +5 -4
  17. package/dist/core/Queries.d.ts +46 -0
  18. package/dist/core/{Query.js → Queries.js} +10 -8
  19. package/dist/core/Resolver.d.ts +2 -2
  20. package/dist/core/Selection.d.ts +7 -10
  21. package/dist/core/Selection.js +15 -13
  22. package/dist/core/Sql.d.ts +8 -29
  23. package/dist/core/Sql.js +67 -118
  24. package/dist/core/Table.d.ts +7 -3
  25. package/dist/core/Table.js +24 -8
  26. package/dist/core/Virtual.d.ts +1 -1
  27. package/dist/core/Virtual.js +15 -14
  28. package/dist/core/expr/Conditions.d.ts +4 -4
  29. package/dist/core/expr/Conditions.js +18 -8
  30. package/dist/core/expr/Field.d.ts +8 -6
  31. package/dist/core/expr/Field.js +3 -3
  32. package/dist/core/expr/Include.d.ts +10 -7
  33. package/dist/core/expr/Include.js +29 -12
  34. package/dist/core/expr/Input.d.ts +3 -1
  35. package/dist/core/expr/Input.js +24 -7
  36. package/dist/core/expr/Json.js +2 -2
  37. package/dist/core/query/CTE.d.ts +8 -0
  38. package/dist/core/query/CTE.js +33 -0
  39. package/dist/core/query/Delete.d.ts +14 -13
  40. package/dist/core/query/Delete.js +32 -6
  41. package/dist/core/query/Insert.d.ts +17 -36
  42. package/dist/core/query/Insert.js +121 -72
  43. package/dist/core/query/Query.d.ts +124 -0
  44. package/dist/core/query/Select.d.ts +74 -33
  45. package/dist/core/query/Select.js +255 -57
  46. package/dist/core/query/Shared.d.ts +3 -0
  47. package/dist/core/query/Shared.js +23 -0
  48. package/dist/core/query/Update.d.ts +13 -13
  49. package/dist/core/query/Update.js +51 -22
  50. package/dist/driver/d1.d.ts +2 -2
  51. package/dist/driver/libsql.d.ts +2 -2
  52. package/dist/driver/mysql2.d.ts +2 -2
  53. package/dist/driver/pg.d.ts +2 -2
  54. package/dist/driver/pglite.d.ts +2 -2
  55. package/dist/index.d.ts +7 -7
  56. package/dist/index.js +7 -7
  57. package/dist/mysql/columns.d.ts +37 -37
  58. package/dist/mysql/columns.js +32 -15
  59. package/dist/mysql/dialect.js +6 -7
  60. package/dist/mysql/diff.js +2 -1
  61. package/dist/mysql.d.ts +3 -2
  62. package/dist/mysql.js +11 -2
  63. package/dist/postgres/columns.d.ts +13 -13
  64. package/dist/postgres/columns.js +15 -6
  65. package/dist/postgres/dialect.js +6 -7
  66. package/dist/postgres/diff.js +2 -1
  67. package/dist/postgres.d.ts +3 -2
  68. package/dist/postgres.js +11 -2
  69. package/dist/sqlite/columns.d.ts +16 -1
  70. package/dist/sqlite/columns.js +36 -3
  71. package/dist/sqlite/dialect.js +6 -6
  72. package/dist/sqlite/diff.js +3 -5
  73. package/dist/sqlite.d.ts +3 -2
  74. package/dist/sqlite.js +11 -2
  75. package/dist/universal/functions.js +4 -1
  76. package/package.json +4 -4
  77. package/dist/core/Join.d.ts +0 -1
  78. package/dist/core/Query.d.ts +0 -46
  79. package/dist/core/query/Union.d.ts +0 -35
  80. package/dist/core/query/Union.js +0 -107
  81. /package/dist/core/{Join.js → query/Query.js} +0 -0
@@ -2,41 +2,41 @@
2
2
  import {
3
3
  getData,
4
4
  getTable,
5
- hasSql,
6
5
  internalData,
7
6
  internalQuery,
8
7
  internalSelection
9
8
  } from "../Internal.js";
10
- import { Query } from "../Query.js";
9
+ import { SingleQuery } from "../Queries.js";
11
10
  import {
12
11
  selection
13
12
  } from "../Selection.js";
14
13
  import { sql } from "../Sql.js";
15
14
  import { and } from "../expr/Conditions.js";
16
- import { input } from "../expr/Input.js";
17
- var Update = class extends Query {
15
+ import { mapToColumn } from "../expr/Input.js";
16
+ import { formatCTE } from "./CTE.js";
17
+ import { formatModifiers } from "./Shared.js";
18
+ var Update = class _Update extends SingleQuery {
18
19
  [internalData];
19
20
  constructor(data) {
20
21
  super(data);
21
22
  this[internalData] = data;
22
- if (data.returning) this[internalSelection] = data.returning;
23
+ if (data.returning) this[internalSelection] = selection(data.returning);
23
24
  }
24
25
  get [internalQuery]() {
25
- return sql.chunk("emitUpdate", this);
26
+ return updateQuery(getData(this));
27
+ }
28
+ limit(limit) {
29
+ return new _Update({ ...getData(this), limit });
30
+ }
31
+ offset(offset) {
32
+ return new _Update({ ...getData(this), offset });
33
+ }
34
+ orderBy(...orderBy) {
35
+ return new _Update({ ...getData(this), orderBy });
26
36
  }
27
37
  };
28
38
  var UpdateTable = class _UpdateTable extends Update {
29
- set(values) {
30
- const { table } = getData(this);
31
- const set = sql.join(
32
- Object.entries(values).map(([key, value]) => {
33
- const column = getTable(table).columns[key];
34
- const { mapToDriverValue } = getData(column);
35
- const expr = value && typeof value === "object" && hasSql(value) ? value : input(mapToDriverValue?.(value) ?? value);
36
- return sql`${sql.identifier(key)} = ${expr}`;
37
- }),
38
- sql`, `
39
- );
39
+ set(set) {
40
40
  return new _UpdateTable({ ...getData(this), set });
41
41
  }
42
42
  where(...where) {
@@ -47,13 +47,42 @@ var UpdateTable = class _UpdateTable extends Update {
47
47
  }
48
48
  returning(returning) {
49
49
  const data = getData(this);
50
- return new Update({
51
- ...data,
52
- returning: returning ? selection(returning) : selection.table(data.table)
53
- });
50
+ return new Update({ ...data, returning: returning ?? data.update });
54
51
  }
55
52
  };
53
+ function updateQuery(query) {
54
+ const { update: table, set: values, where, returning } = query;
55
+ const tableApi = getTable(table);
56
+ if (!values) throw new Error("Update values are required");
57
+ const set = sql.join(
58
+ Object.entries(tableApi.columns).map(([key, column]) => {
59
+ const columnApi = getData(column);
60
+ const { name, $onUpdate } = columnApi;
61
+ let expr;
62
+ if (!(key in values)) {
63
+ if ($onUpdate) expr = $onUpdate();
64
+ else return;
65
+ } else {
66
+ expr = mapToColumn(columnApi, values[key]);
67
+ }
68
+ const fieldName = name ?? key;
69
+ return sql`${sql.identifier(fieldName)} = ${expr}`;
70
+ }),
71
+ sql`, `
72
+ );
73
+ return sql.query(
74
+ formatCTE(query),
75
+ {
76
+ update: sql.identifier(tableApi.name),
77
+ set,
78
+ where,
79
+ returning: returning && selection(returning)
80
+ },
81
+ formatModifiers(query)
82
+ ).inlineFields(false);
83
+ }
56
84
  export {
57
85
  Update,
58
- UpdateTable
86
+ UpdateTable,
87
+ updateQuery
59
88
  };
@@ -1,5 +1,5 @@
1
1
  import { AsyncDatabase } from '../core/Database.js';
2
- import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
2
+ import type { AsyncDriver, AsyncStatement, BatchedQuery, PrepareOptions } from '../core/Driver.js';
3
3
  type Client = D1Database;
4
4
  declare class PreparedStatement implements AsyncStatement {
5
5
  private stmt;
@@ -19,7 +19,7 @@ export declare class D1Driver implements AsyncDriver {
19
19
  exec(query: string): Promise<void>;
20
20
  prepare(sql: string, options: PrepareOptions): PreparedStatement;
21
21
  close(): Promise<void>;
22
- batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
22
+ batch(queries: Array<BatchedQuery>): Promise<Array<Array<unknown>>>;
23
23
  transaction<T>(): Promise<T>;
24
24
  }
25
25
  export declare function connect(client: Client): AsyncDatabase<'sqlite'>;
@@ -1,6 +1,6 @@
1
1
  import type { Client, InValue, Transaction } from '@libsql/client';
2
2
  import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
3
- import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
3
+ import type { AsyncDriver, AsyncStatement, BatchedQuery, PrepareOptions } from '../core/Driver.js';
4
4
  type Queryable = Client | Transaction;
5
5
  declare class PreparedStatement implements AsyncStatement {
6
6
  private client;
@@ -21,7 +21,7 @@ export declare class LibSQLClient implements AsyncDriver {
21
21
  exec(query: string): Promise<void>;
22
22
  prepare(sql: string, options: PrepareOptions): PreparedStatement;
23
23
  close(): Promise<void>;
24
- batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
24
+ batch(queries: Array<BatchedQuery>): Promise<Array<Array<unknown>>>;
25
25
  transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['sqlite']): Promise<T>;
26
26
  }
27
27
  export declare function connect(client: Client): AsyncDatabase<'sqlite'>;
@@ -1,7 +1,7 @@
1
1
  import type { Connection } from 'mysql2';
2
2
  import type { Pool, PoolConnection, Connection as PromiseConnection } from 'mysql2/promise';
3
3
  import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
4
- import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
4
+ import type { AsyncDriver, AsyncStatement, BatchedQuery, PrepareOptions } from '../core/Driver.js';
5
5
  type Queryable = PromiseConnection | Pool | PoolConnection;
6
6
  declare class PreparedStatement implements AsyncStatement {
7
7
  #private;
@@ -24,7 +24,7 @@ export declare class Mysql2Driver implements AsyncDriver {
24
24
  exec(query: string): Promise<void>;
25
25
  prepare(sql: string, options?: PrepareOptions): PreparedStatement;
26
26
  close(): Promise<void>;
27
- batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
27
+ batch(queries: Array<BatchedQuery>): Promise<Array<Array<unknown>>>;
28
28
  transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['mysql']): Promise<T>;
29
29
  }
30
30
  export declare function connect(client: Queryable | Connection): AsyncDatabase<'mysql'>;
@@ -1,6 +1,6 @@
1
1
  import type { Client, Pool, PoolClient } from 'pg';
2
2
  import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
3
- import type { AsyncDriver, AsyncStatement, BatchQuery, PrepareOptions } from '../core/Driver.js';
3
+ import type { AsyncDriver, AsyncStatement, BatchedQuery, PrepareOptions } from '../core/Driver.js';
4
4
  type Queryable = Client | Pool | PoolClient;
5
5
  declare class PreparedStatement implements AsyncStatement {
6
6
  private client;
@@ -22,7 +22,7 @@ export declare class PgDriver implements AsyncDriver {
22
22
  exec(query: string): Promise<void>;
23
23
  prepare(sql: string, options?: PrepareOptions): PreparedStatement;
24
24
  close(): Promise<void>;
25
- batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
25
+ batch(queries: Array<BatchedQuery>): Promise<Array<Array<unknown>>>;
26
26
  transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres']): Promise<T>;
27
27
  }
28
28
  export declare function connect(client: Queryable): AsyncDatabase<'postgres'>;
@@ -1,6 +1,6 @@
1
1
  import type { PGlite, Transaction } from '@electric-sql/pglite';
2
2
  import { AsyncDatabase, type TransactionOptions } from '../core/Database.js';
3
- import type { AsyncDriver, AsyncStatement, BatchQuery } from '../core/Driver.js';
3
+ import type { AsyncDriver, AsyncStatement, BatchedQuery } from '../core/Driver.js';
4
4
  type Queryable = PGlite | Transaction;
5
5
  declare class PreparedStatement implements AsyncStatement {
6
6
  private client;
@@ -21,7 +21,7 @@ export declare class PGliteDriver implements AsyncDriver {
21
21
  exec(query: string): Promise<void>;
22
22
  close(): Promise<void>;
23
23
  prepare(sql: string): PreparedStatement;
24
- batch(queries: Array<BatchQuery>): Promise<Array<Array<unknown>>>;
24
+ batch(queries: Array<BatchedQuery>): Promise<Array<Array<unknown>>>;
25
25
  transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres']): Promise<T>;
26
26
  }
27
27
  export declare function connect(db: PGlite): AsyncDatabase<'postgres'>;
package/dist/index.d.ts CHANGED
@@ -4,17 +4,17 @@ export * from './core/Column.js';
4
4
  export * from './core/Constraint.js';
5
5
  export * from './core/Database.js';
6
6
  export * from './core/Driver.js';
7
- export * from './core/Index.js';
8
- export * from './core/Internal.js';
9
- export * from './core/Query.js';
10
- export * from './core/Selection.js';
11
- export * from './core/Sql.js';
12
- export * from './core/Table.js';
13
7
  export * from './core/expr/Aggregate.js';
14
8
  export * from './core/expr/Conditions.js';
15
9
  export * from './core/expr/Include.js';
10
+ export * from './core/Index.js';
11
+ export * from './core/Internal.js';
12
+ export * from './core/Queries.js';
13
+ export * from './core/query/CTE.js';
16
14
  export * from './core/query/Delete.js';
17
15
  export * from './core/query/Insert.js';
18
16
  export * from './core/query/Select.js';
19
- export * from './core/query/Union.js';
20
17
  export * from './core/query/Update.js';
18
+ export * from './core/Selection.js';
19
+ export * from './core/Sql.js';
20
+ export * from './core/Table.js';
package/dist/index.js CHANGED
@@ -5,17 +5,17 @@ export * from "./core/Column.js";
5
5
  export * from "./core/Constraint.js";
6
6
  export * from "./core/Database.js";
7
7
  export * from "./core/Driver.js";
8
- export * from "./core/Index.js";
9
- export * from "./core/Internal.js";
10
- export * from "./core/Query.js";
11
- export * from "./core/Selection.js";
12
- export * from "./core/Sql.js";
13
- export * from "./core/Table.js";
14
8
  export * from "./core/expr/Aggregate.js";
15
9
  export * from "./core/expr/Conditions.js";
16
10
  export * from "./core/expr/Include.js";
11
+ export * from "./core/Index.js";
12
+ export * from "./core/Internal.js";
13
+ export * from "./core/Queries.js";
14
+ export * from "./core/query/CTE.js";
17
15
  export * from "./core/query/Delete.js";
18
16
  export * from "./core/query/Insert.js";
19
17
  export * from "./core/query/Select.js";
20
- export * from "./core/query/Union.js";
21
18
  export * from "./core/query/Update.js";
19
+ export * from "./core/Selection.js";
20
+ export * from "./core/Sql.js";
21
+ export * from "./core/Table.js";
@@ -1,71 +1,71 @@
1
- import { JsonColumn, type Column } from '../core/Column.js';
1
+ import { type Column, type ColumnArguments, JsonColumn } from '../core/Column.js';
2
2
  type Precision = 0 | 1 | 2 | 3 | 4 | 5 | 6;
3
- export declare function bigint(name: string | undefined, options: {
3
+ export declare function bigint(...args: ColumnArguments<{
4
4
  mode: 'number';
5
5
  unsigned?: boolean;
6
- }): Column<number | null>;
7
- export declare function bigint(name?: string, options?: {
6
+ }>): Column<number | null>;
7
+ export declare function bigint(...args: ColumnArguments<{
8
8
  unsigned?: boolean;
9
- }): Column<bigint | null>;
10
- export declare function binary(name?: string, options?: {
9
+ }>): Column<bigint | null>;
10
+ export declare function binary(...args: ColumnArguments<{
11
11
  length?: number;
12
- }): Column<Uint8Array | null>;
12
+ }>): Column<Uint8Array | null>;
13
13
  export declare function boolean(name?: string): Column<boolean | null>;
14
14
  export declare function blob(name?: string): Column<Uint8Array | null>;
15
- export declare function char(name?: string, options?: {
16
- length: number;
17
- }): Column<string | null>;
18
- export declare function date(name?: string, options?: {
15
+ export declare function char(...args: ColumnArguments<{
16
+ length?: number;
17
+ }>): Column<string | null>;
18
+ export declare function date(...args: ColumnArguments<{
19
19
  mode: 'string';
20
- }): Column<string | null>;
21
- export declare function date(name: string | undefined, options: {
20
+ }>): Column<string | null>;
21
+ export declare function date(...args: ColumnArguments<{
22
22
  mode: 'date';
23
- }): Column<Date | null>;
24
- export declare function datetime(name?: string, options?: {
23
+ }>): Column<Date | null>;
24
+ export declare function datetime(...args: ColumnArguments<{
25
25
  fsp?: Precision;
26
- }): Column<Date | null>;
27
- export declare function datetime(name: string | undefined, options: {
26
+ }>): Column<Date | null>;
27
+ export declare function datetime(...args: ColumnArguments<{
28
28
  mode: 'string';
29
29
  fsp?: Precision;
30
- }): Column<string | null>;
31
- export declare function decimal(name: string | undefined, options: {
30
+ }>): Column<string | null>;
31
+ export declare function decimal(...args: ColumnArguments<{
32
32
  precision?: number;
33
33
  scale?: number;
34
- }): Column<number | null>;
34
+ }>): Column<number | null>;
35
35
  export declare function float(name?: string): Column<number | null>;
36
36
  export declare function integer(name?: string): Column<number | null>;
37
37
  export declare const int: typeof integer;
38
38
  export declare function json<T>(name?: string): JsonColumn<T | null>;
39
- export declare function mediumint(name?: string, options?: {
39
+ export declare function mediumint(...args: ColumnArguments<{
40
40
  unsigned?: boolean;
41
- }): Column<number | null>;
41
+ }>): Column<number | null>;
42
42
  export declare function real(name?: string): Column<number | null>;
43
43
  export declare function serial(name?: string): Column<number | null>;
44
- export declare function smallint(name?: string, options?: {
44
+ export declare function smallint(...args: ColumnArguments<{
45
45
  unsigned?: boolean;
46
- }): Column<number | null>;
46
+ }>): Column<number | null>;
47
47
  export declare function text(name?: string): Column<string | null>;
48
48
  export declare function tinytext(name?: string): Column<string | null>;
49
49
  export declare function mediumtext(name?: string): Column<string | null>;
50
50
  export declare function longtext(name?: string): Column<string | null>;
51
- export declare function time(name?: string, options?: {
51
+ export declare function time(...args: ColumnArguments<{
52
52
  fsp?: Precision;
53
- }): Column<string | null>;
54
- export declare function timestamp(name: string | undefined, options?: {
53
+ }>): Column<string | null>;
54
+ export declare function timestamp(...args: ColumnArguments<{
55
55
  fsp?: Precision;
56
- }): Column<Date | null>;
57
- export declare function timestamp(name?: string, options?: {
56
+ }>): Column<Date | null>;
57
+ export declare function timestamp(...args: ColumnArguments<{
58
58
  mode: 'string';
59
59
  fsp?: Precision;
60
- }): Column<string | null>;
61
- export declare function tinyint(name?: string, options?: {
60
+ }>): Column<string | null>;
61
+ export declare function tinyint(...args: ColumnArguments<{
62
62
  unsigned?: boolean;
63
- }): Column<number | null>;
64
- export declare function varbinary(name?: string, options?: {
63
+ }>): Column<number | null>;
64
+ export declare function varbinary(...args: ColumnArguments<{
65
+ length?: number;
66
+ }>): Column<Uint8Array | null>;
67
+ export declare function varchar(...args: ColumnArguments<{
65
68
  length?: number;
66
- }): Column<Uint8Array | null>;
67
- export declare function varchar(name?: string, options?: {
68
- length: number;
69
- }): Column<string | null>;
69
+ }>): Column<string | null>;
70
70
  export declare function year(name?: string): Column<number | null>;
71
71
  export {};
@@ -1,13 +1,19 @@
1
1
  // src/mysql/columns.ts
2
- import { JsonColumn, column } from "../core/Column.js";
3
- function bigint(name, options) {
2
+ import {
3
+ JsonColumn,
4
+ column,
5
+ columnConfig
6
+ } from "../core/Column.js";
7
+ function bigint(...args) {
8
+ const { name, options } = columnConfig(args);
4
9
  return column({
5
10
  name,
6
11
  type: column[options?.unsigned ? "bigint unsigned" : "bigint"](),
7
12
  mapFromDriverValue: options?.mode === "number" ? Number : BigInt
8
13
  });
9
14
  }
10
- function binary(name, options) {
15
+ function binary(...args) {
16
+ const { name, options } = columnConfig(args);
11
17
  return column({ name, type: column.binary(options?.length) });
12
18
  }
13
19
  function boolean(name) {
@@ -16,10 +22,12 @@ function boolean(name) {
16
22
  function blob(name) {
17
23
  return column({ name, type: column.blob() });
18
24
  }
19
- function char(name, options) {
25
+ function char(...args) {
26
+ const { name, options } = columnConfig(args);
20
27
  return column({ name, type: column.char(options?.length) });
21
28
  }
22
- function date(name, options) {
29
+ function date(...args) {
30
+ const { name, options } = columnConfig(args);
23
31
  return column({
24
32
  name,
25
33
  type: column.date(),
@@ -31,7 +39,8 @@ function date(name, options) {
31
39
  }
32
40
  });
33
41
  }
34
- function datetime(name, options) {
42
+ function datetime(...args) {
43
+ const { name, options } = columnConfig(args);
35
44
  return column({
36
45
  name,
37
46
  type: column.datetime(options?.fsp),
@@ -43,10 +52,11 @@ function datetime(name, options) {
43
52
  }
44
53
  });
45
54
  }
46
- function decimal(name, options) {
55
+ function decimal(...args) {
56
+ const { name, options } = columnConfig(args);
47
57
  return column({
48
58
  name,
49
- type: column.decimal(options.precision, options.scale)
59
+ type: column.decimal(options?.precision, options?.scale)
50
60
  });
51
61
  }
52
62
  function float(name) {
@@ -65,7 +75,8 @@ function json(name) {
65
75
  }
66
76
  });
67
77
  }
68
- function mediumint(name, options) {
78
+ function mediumint(...args) {
79
+ const { name, options } = columnConfig(args);
69
80
  return column({
70
81
  name,
71
82
  type: column[options?.unsigned ? "mediumint unsigned" : "mediumint"]()
@@ -77,7 +88,8 @@ function real(name) {
77
88
  function serial(name) {
78
89
  return column({ name, type: column.serial() });
79
90
  }
80
- function smallint(name, options) {
91
+ function smallint(...args) {
92
+ const { name, options } = columnConfig(args);
81
93
  return column({
82
94
  name,
83
95
  type: column[options?.unsigned ? "smallint unsigned" : "smallint"]()
@@ -95,10 +107,12 @@ function mediumtext(name) {
95
107
  function longtext(name) {
96
108
  return column({ name, type: column.longtext() });
97
109
  }
98
- function time(name, options) {
110
+ function time(...args) {
111
+ const { name, options } = columnConfig(args);
99
112
  return column({ name, type: column.time(options?.fsp) });
100
113
  }
101
- function timestamp(name, options) {
114
+ function timestamp(...args) {
115
+ const { name, options } = columnConfig(args);
102
116
  return column({
103
117
  name,
104
118
  type: column.timestamp(options?.fsp),
@@ -110,16 +124,19 @@ function timestamp(name, options) {
110
124
  }
111
125
  });
112
126
  }
113
- function tinyint(name, options) {
127
+ function tinyint(...args) {
128
+ const { name, options } = columnConfig(args);
114
129
  return column({
115
130
  name,
116
131
  type: column[options?.unsigned ? "tinyint unsigned" : "tinyint"]()
117
132
  });
118
133
  }
119
- function varbinary(name, options) {
134
+ function varbinary(...args) {
135
+ const { name, options } = columnConfig(args);
120
136
  return column({ name, type: column.varbinary(options?.length) });
121
137
  }
122
- function varchar(name, options) {
138
+ function varchar(...args) {
139
+ const { name, options } = columnConfig(args);
123
140
  return column({ name, type: column.varchar(options?.length) });
124
141
  }
125
142
  function year(name) {
@@ -12,13 +12,16 @@ var mysqlDialect = new Dialect(
12
12
  "mysql",
13
13
  class extends Emitter {
14
14
  runtime = "mysql";
15
- paramIndex = 0;
16
15
  emitValue(value) {
17
- this.sql += "?";
18
16
  this.params.push(new ValueParam(value));
17
+ this.sql += "?";
18
+ }
19
+ emitPlaceholder(name) {
20
+ this.params.push(new NamedParam(name));
21
+ this.sql += "?";
19
22
  }
20
23
  emitJsonPath({ target, asSql, segments }) {
21
- target.emitTo(this);
24
+ target.emit(this);
22
25
  this.sql += asSql ? "->>" : "->";
23
26
  this.sql += this.quoteString(
24
27
  `$${segments.map((p) => typeof p === "number" ? `[${p}]` : `.${p}`).join("")}`
@@ -32,10 +35,6 @@ var mysqlDialect = new Dialect(
32
35
  return this.sql += this.quoteString(value);
33
36
  this.sql += this.quoteString(JSON.stringify(value));
34
37
  }
35
- emitPlaceholder(name) {
36
- this.sql += "?";
37
- this.params.push(new NamedParam(name));
38
- }
39
38
  quoteString(input) {
40
39
  return SINGLE_QUOTE + input.replace(MATCH_SINGLE_QUOTE, ESCAPE_SINGLE_QUOTE) + SINGLE_QUOTE;
41
40
  }
@@ -1,4 +1,5 @@
1
1
  // src/mysql/diff.ts
2
+ import { formatColumn } from "../core/Column.js";
2
3
  import { getData, getTable } from "../core/Internal.js";
3
4
  import { schema } from "../core/Schema.js";
4
5
  import { sql } from "../core/Sql.js";
@@ -106,7 +107,7 @@ var mysqlDiff = (hasTable) => {
106
107
  stmts.push(
107
108
  sql.query({
108
109
  alterTable,
109
- addColumn: [column2, sql.chunk("emitColumn", schemaInstruction)]
110
+ addColumn: [column2, formatColumn(schemaInstruction)]
110
111
  })
111
112
  );
112
113
  } else {
package/dist/mysql.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/Union.js';
3
+ export { except, exceptAll, intersect, intersectAll, union, unionAll } from './core/query/Select.js';
3
4
  export { schema as mysqlSchema } from './core/Schema.js';
4
- export { alias, table as mysqlTable } from './core/Table.js';
5
+ export { alias, table as mysqlTable, tableCreator as mysqlTableCreator } from './core/Table.js';
5
6
  export * from './mysql/builder.js';
6
7
  export * from './mysql/columns.js';
7
8
  export * from './mysql/dialect.js';
package/dist/mysql.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/mysql.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 "./mysql/builder.js";
14
19
  export * from "./mysql/columns.js";
15
20
  export * from "./mysql/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 mysqlSchema,
24
30
  table as mysqlTable,
31
+ tableCreator as mysqlTableCreator,
32
+ primaryKey,
25
33
  union,
26
34
  unionAll,
35
+ unique,
27
36
  uniqueIndex
28
37
  };
@@ -1,4 +1,4 @@
1
- import { JsonColumn, type Column } from '../core/Column.js';
1
+ import { type Column, type ColumnArguments, JsonColumn } from '../core/Column.js';
2
2
  type Precision = 0 | 1 | 2 | 3 | 4 | 5 | 6;
3
3
  type IntervalFields = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'year to month' | 'day to hour' | 'day to minute' | 'day to second' | 'hour to minute' | 'hour to second' | 'minute to second';
4
4
  export declare function bigint(name: string | undefined, options: {
@@ -24,10 +24,10 @@ export declare function inet(name?: string): Column<string | null>;
24
24
  export declare function integer(name?: string): Column<number | null>;
25
25
  export declare const int: typeof integer;
26
26
  export declare function oid(name?: string): Column<number | null>;
27
- export declare function interval(name?: string, options?: {
27
+ export declare function interval(...args: ColumnArguments<{
28
28
  fields?: IntervalFields;
29
29
  precision?: Precision;
30
- }): Column<string | null>;
30
+ }>): Column<string | null>;
31
31
  export declare function serial(name?: string): Column<number>;
32
32
  export declare function boolean(name?: string): Column<boolean | null>;
33
33
  export declare function bytea(name?: string): Column<Uint8Array | null>;
@@ -36,28 +36,28 @@ export declare function json<T>(name?: string): JsonColumn<T | null>;
36
36
  export declare function jsonb<T>(name?: string): JsonColumn<T | null>;
37
37
  export declare function macaddr(name?: string): Column<string | null>;
38
38
  export declare function macaddr8(name?: string): Column<string | null>;
39
- export declare function numeric(name?: string, options?: {
39
+ export declare function numeric(...args: ColumnArguments<{
40
40
  precision?: number;
41
41
  scale?: number;
42
- }): Column<number | null>;
42
+ }>): Column<number | null>;
43
43
  export declare function real(name?: string): Column<number | null>;
44
44
  export declare function smallint(name?: string): Column<number | null>;
45
45
  export declare function smallserial(name?: string): Column<number | null>;
46
- export declare function time(name: string | undefined, options?: {
46
+ export declare function time(...args: ColumnArguments<{
47
47
  precision?: Precision;
48
48
  withTimeZone?: boolean;
49
- }): Column<string | null>;
50
- export declare function timestamp(name: string | undefined, options?: {
49
+ }>): Column<string | null>;
50
+ export declare function timestamp(...args: ColumnArguments<{
51
51
  precision?: Precision;
52
52
  withTimeZone?: boolean;
53
- }): Column<Date | null>;
54
- export declare function timestamp(name?: string, options?: {
53
+ }>): Column<Date | null>;
54
+ export declare function timestamp(...args: ColumnArguments<{
55
55
  mode: 'string';
56
56
  precision?: Precision;
57
57
  withTimeZone?: boolean;
58
- }): Column<string | null>;
58
+ }>): Column<string | null>;
59
59
  export declare function uuid(name?: string): Column<string | null>;
60
- export declare function varchar(name?: string, options?: {
60
+ export declare function varchar(...args: ColumnArguments<{
61
61
  length: number;
62
- }): Column<string | null>;
62
+ }>): Column<string | null>;
63
63
  export {};