rado 0.1.62 → 0.1.63

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 (148) hide show
  1. package/dist/define/Column.d.ts +58 -58
  2. package/dist/define/Cursor.d.ts +87 -87
  3. package/dist/define/Expr.d.ts +172 -172
  4. package/dist/define/Fields.d.ts +13 -13
  5. package/dist/define/Functions.d.ts +5 -5
  6. package/dist/define/Id.d.ts +3 -3
  7. package/dist/define/Index.d.ts +17 -17
  8. package/dist/define/Ops.d.ts +7 -7
  9. package/dist/define/OrderBy.d.ts +9 -9
  10. package/dist/define/Param.d.ts +15 -15
  11. package/dist/define/Query.d.ts +109 -109
  12. package/dist/define/Schema.d.ts +18 -18
  13. package/dist/define/Selection.d.ts +20 -20
  14. package/dist/define/Table.d.ts +62 -62
  15. package/dist/define/Target.d.ts +38 -38
  16. package/dist/define/Update.d.ts +4 -4
  17. package/dist/driver/better-sqlite3.d.ts +15 -15
  18. package/dist/driver/bun-sqlite.d.ts +18 -18
  19. package/dist/driver/sql.js.d.ts +15 -15
  20. package/dist/driver/sqlite3.d.ts +18 -18
  21. package/dist/index.d.ts +21 -21
  22. package/dist/lib/Driver.d.ts +110 -110
  23. package/dist/lib/Formatter.d.ts +81 -81
  24. package/dist/lib/Formatter.js +3 -3
  25. package/dist/lib/Sanitizer.d.ts +5 -5
  26. package/dist/lib/SqlError.d.ts +3 -3
  27. package/dist/lib/Statement.d.ts +33 -33
  28. package/dist/sqlite/SqliteFormatter.d.ts +11 -11
  29. package/dist/sqlite/SqliteFunctions.d.ts +165 -165
  30. package/dist/sqlite/SqliteSchema.d.ts +25 -25
  31. package/dist/sqlite.d.ts +2 -2
  32. package/package.json +60 -60
  33. package/dist/CPU.20230126.092143.12244.0.001.cpuprofile +0 -1
  34. package/dist/Column.d.ts +0 -54
  35. package/dist/Column.js +0 -63
  36. package/dist/Cursor.d.ts +0 -77
  37. package/dist/Cursor.js +0 -221
  38. package/dist/Driver.d.ts +0 -89
  39. package/dist/Driver.js +0 -262
  40. package/dist/Expr.d.ts +0 -149
  41. package/dist/Expr.js +0 -284
  42. package/dist/Fields.d.ts +0 -11
  43. package/dist/Fields.js +0 -0
  44. package/dist/Formatter.d.ts +0 -55
  45. package/dist/Formatter.js +0 -496
  46. package/dist/Functions.d.ts +0 -7
  47. package/dist/Functions.js +0 -11
  48. package/dist/Id.d.ts +0 -3
  49. package/dist/Id.js +0 -0
  50. package/dist/Ops.d.ts +0 -8
  51. package/dist/Ops.js +0 -45
  52. package/dist/OrderBy.d.ts +0 -9
  53. package/dist/OrderBy.js +0 -9
  54. package/dist/Param.d.ts +0 -15
  55. package/dist/Param.js +0 -18
  56. package/dist/Query.d.ts +0 -107
  57. package/dist/Query.js +0 -74
  58. package/dist/Sanitizer.d.ts +0 -4
  59. package/dist/Sanitizer.js +0 -0
  60. package/dist/Schema.d.ts +0 -23
  61. package/dist/Schema.js +0 -60
  62. package/dist/Selection.d.ts +0 -20
  63. package/dist/Selection.js +0 -7
  64. package/dist/Statement.d.ts +0 -57
  65. package/dist/Statement.js +0 -184
  66. package/dist/Table.d.ts +0 -56
  67. package/dist/Table.js +0 -104
  68. package/dist/Target.d.ts +0 -30
  69. package/dist/Target.js +0 -37
  70. package/dist/Update.d.ts +0 -4
  71. package/dist/Update.js +0 -0
  72. package/dist/lib/Column.d.ts +0 -57
  73. package/dist/lib/Column.js +0 -63
  74. package/dist/lib/Cursor.d.ts +0 -79
  75. package/dist/lib/Cursor.js +0 -231
  76. package/dist/lib/Expr.d.ts +0 -154
  77. package/dist/lib/Expr.js +0 -284
  78. package/dist/lib/Fields.d.ts +0 -13
  79. package/dist/lib/Fields.js +0 -0
  80. package/dist/lib/Functions.d.ts +0 -5
  81. package/dist/lib/Functions.js +0 -11
  82. package/dist/lib/Id.d.ts +0 -3
  83. package/dist/lib/Id.js +0 -0
  84. package/dist/lib/Index.d.ts +0 -17
  85. package/dist/lib/Index.js +0 -20
  86. package/dist/lib/Ops.d.ts +0 -8
  87. package/dist/lib/Ops.js +0 -45
  88. package/dist/lib/OrderBy.d.ts +0 -9
  89. package/dist/lib/OrderBy.js +0 -9
  90. package/dist/lib/Param.d.ts +0 -20
  91. package/dist/lib/Param.js +0 -27
  92. package/dist/lib/Query.d.ts +0 -109
  93. package/dist/lib/Query.js +0 -74
  94. package/dist/lib/Schema.d.ts +0 -18
  95. package/dist/lib/Schema.js +0 -67
  96. package/dist/lib/Selection.d.ts +0 -20
  97. package/dist/lib/Selection.js +0 -7
  98. package/dist/lib/Table.d.ts +0 -62
  99. package/dist/lib/Table.js +0 -130
  100. package/dist/lib/Target.d.ts +0 -30
  101. package/dist/lib/Target.js +0 -37
  102. package/dist/lib/Update.d.ts +0 -4
  103. package/dist/lib/Update.js +0 -0
  104. package/dist/sqlite/index.d.ts +0 -2
  105. package/dist/sqlite/index.js +0 -3
  106. package/dist/src/driver/better-sqlite3.js +0 -49
  107. package/dist/src/driver/sql.js.js +0 -66
  108. package/dist/src/driver/sqlite3.js +0 -87
  109. package/dist/src/index.js +0 -24
  110. package/dist/src/lib/Column.js +0 -63
  111. package/dist/src/lib/Cursor.js +0 -231
  112. package/dist/src/lib/Driver.js +0 -316
  113. package/dist/src/lib/Expr.js +0 -284
  114. package/dist/src/lib/Fields.js +0 -0
  115. package/dist/src/lib/Formatter.js +0 -625
  116. package/dist/src/lib/Functions.js +0 -11
  117. package/dist/src/lib/Id.js +0 -0
  118. package/dist/src/lib/Index.js +0 -20
  119. package/dist/src/lib/Ops.js +0 -45
  120. package/dist/src/lib/OrderBy.js +0 -9
  121. package/dist/src/lib/Param.js +0 -27
  122. package/dist/src/lib/Query.js +0 -74
  123. package/dist/src/lib/Sanitizer.js +0 -0
  124. package/dist/src/lib/Schema.js +0 -67
  125. package/dist/src/lib/Selection.js +0 -7
  126. package/dist/src/lib/Statement.js +0 -103
  127. package/dist/src/lib/Table.js +0 -130
  128. package/dist/src/lib/Target.js +0 -37
  129. package/dist/src/lib/Update.js +0 -0
  130. package/dist/src/sqlite/SqliteFormatter.js +0 -67
  131. package/dist/src/sqlite/SqliteFunctions.js +0 -146
  132. package/dist/src/sqlite/SqliteSchema.js +0 -47
  133. package/dist/src/sqlite.js +0 -3
  134. package/dist/test/DbSuite.js +0 -28
  135. package/dist/test/TSTestTypes.js +0 -6
  136. package/dist/test/TestBasic.js +0 -172
  137. package/dist/test/TestExtend.js +0 -68
  138. package/dist/test/TestFts5.js +0 -34
  139. package/dist/test/TestFunctions.js +0 -28
  140. package/dist/test/TestJoins.js +0 -34
  141. package/dist/test/TestJson.js +0 -33
  142. package/dist/test/TestPrepare.js +0 -27
  143. package/dist/test/TestRawSql.js +0 -31
  144. package/dist/test/TestSchema.js +0 -69
  145. package/dist/test/TestSubQueries.js +0 -79
  146. package/dist/test/TestTransaction.js +0 -54
  147. package/dist/test/TestUpdate.js +0 -95
  148. package/dist/test/index.js +0 -14
@@ -1,13 +1,13 @@
1
- import { Column, PrimaryKey } from './Column';
2
- import { Expr } from './Expr';
3
- type ObjectUnion<T> = {
4
- [K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
5
- };
6
- type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
7
- type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.IsPrimary<infer V, infer K>] ? Expr<PrimaryKey<V, K>> : [T] extends [Column.IsOptional<infer V>] ? Field<V> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
8
- type FieldsOf<Row> = Row extends Record<string, any> ? {
9
- [K in keyof Row]-?: Field<Row[K]>;
10
- } : never;
11
- type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
12
- export type Fields<T> = IsStrictlyAny<T> extends true ? any : T extends object ? FieldsOf<T> : Field<T>;
13
- export {};
1
+ import { Column, PrimaryKey } from './Column';
2
+ import { Expr } from './Expr';
3
+ type ObjectUnion<T> = {
4
+ [K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
5
+ };
6
+ type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
7
+ type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.IsPrimary<infer V, infer K>] ? Expr<PrimaryKey<V, K>> : [T] extends [Column.IsOptional<infer V>] ? Field<V> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
8
+ type FieldsOf<Row> = Row extends Record<string, any> ? {
9
+ [K in keyof Row]-?: Field<Row[K]>;
10
+ } : never;
11
+ type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
12
+ export type Fields<T> = IsStrictlyAny<T> extends true ? any : T extends object ? FieldsOf<T> : Field<T>;
13
+ export {};
@@ -1,5 +1,5 @@
1
- import { Expr } from './Expr';
2
- export declare const Functions: Functions;
3
- export type Functions = {
4
- [key: string]: (...args: Array<any>) => Expr<any>;
5
- };
1
+ import { Expr } from './Expr';
2
+ export declare const Functions: Functions;
3
+ export type Functions = {
4
+ [key: string]: (...args: Array<any>) => Expr<any>;
5
+ };
@@ -1,3 +1,3 @@
1
- export type Id<T> = T extends {
2
- id: any;
3
- } ? T['id'] : never;
1
+ export type Id<T> = T extends {
2
+ id: any;
3
+ } ? T['id'] : never;
@@ -1,17 +1,17 @@
1
- import { Expr, ExprData } from './Expr';
2
- interface PartialIndexData {
3
- on: Array<ExprData>;
4
- unique?: boolean;
5
- where?: ExprData;
6
- }
7
- export interface IndexData extends PartialIndexData {
8
- name: string;
9
- }
10
- export declare class Index {
11
- data: PartialIndexData;
12
- constructor(data: PartialIndexData);
13
- unique(): Index;
14
- where(where: Expr<boolean>): Index;
15
- }
16
- export declare function index(...on: Array<Expr<any>>): Index;
17
- export {};
1
+ import { Expr, ExprData } from './Expr';
2
+ interface PartialIndexData {
3
+ on: Array<ExprData>;
4
+ unique?: boolean;
5
+ where?: ExprData;
6
+ }
7
+ export interface IndexData extends PartialIndexData {
8
+ name: string;
9
+ }
10
+ export declare class Index {
11
+ data: PartialIndexData;
12
+ constructor(data: PartialIndexData);
13
+ unique(): Index;
14
+ where(where: Expr<boolean>): Index;
15
+ }
16
+ export declare function index(...on: Array<Expr<any>>): Index;
17
+ export {};
@@ -1,7 +1,7 @@
1
- import { Cursor } from './Cursor';
2
- import { Table } from './Table';
3
- export declare function from<Row>(source: Table<Row> | Cursor.SelectMultiple<Row>): Cursor.SelectMultiple<Row>;
4
- export declare function update<Row>(table: Table<Row>): Cursor.Update<Row>;
5
- export declare function insertInto<Row>(table: Table<Row>): Cursor.Insert<Row>;
6
- export declare function deleteFrom<Row>(table: Table<Row>): Cursor.Delete;
7
- export declare function create(...tables: Array<Table<any>>): Cursor.Batch;
1
+ import { Cursor } from './Cursor';
2
+ import { Table } from './Table';
3
+ export declare function from<Row>(source: Table<Row> | Cursor.SelectMultiple<Row>): Cursor.SelectMultiple<Row>;
4
+ export declare function update<Row>(table: Table<Row>): Cursor.Update<Row>;
5
+ export declare function insertInto<Row>(table: Table<Row>): Cursor.Insert<Row>;
6
+ export declare function deleteFrom<Row>(table: Table<Row>): Cursor.Delete;
7
+ export declare function create(...tables: Array<Table<any>>): Cursor.Batch;
@@ -1,9 +1,9 @@
1
- import { ExprData } from './Expr';
2
- export declare enum OrderDirection {
3
- Asc = "Asc",
4
- Desc = "Desc"
5
- }
6
- export type OrderBy = {
7
- expr: ExprData;
8
- order: OrderDirection;
9
- };
1
+ import { ExprData } from './Expr';
2
+ export declare enum OrderDirection {
3
+ Asc = "Asc",
4
+ Desc = "Desc"
5
+ }
6
+ export type OrderBy = {
7
+ expr: ExprData;
8
+ order: OrderDirection;
9
+ };
@@ -1,15 +1,15 @@
1
- export declare enum ParamType {
2
- Value = "Value",
3
- Named = "Named"
4
- }
5
- export type ParamData = {
6
- type: ParamType.Value;
7
- value: any;
8
- } | {
9
- type: ParamType.Named;
10
- name: string;
11
- };
12
- export declare const ParamData: {
13
- Value(value: any): ParamData;
14
- Named(name: string): ParamData;
15
- };
1
+ export declare enum ParamType {
2
+ Value = "Value",
3
+ Named = "Named"
4
+ }
5
+ export type ParamData = {
6
+ type: ParamType.Value;
7
+ value: any;
8
+ } | {
9
+ type: ParamType.Named;
10
+ name: string;
11
+ };
12
+ export declare const ParamData: {
13
+ Value(value: any): ParamData;
14
+ Named(name: string): ParamData;
15
+ };
@@ -1,109 +1,109 @@
1
- import { ColumnData } from './Column';
2
- import { ExprData } from './Expr';
3
- import { IndexData } from './Index';
4
- import { OrderBy } from './OrderBy';
5
- import { Schema } from './Schema';
6
- import { Target } from './Target';
7
- export declare enum QueryType {
8
- Insert = "Insert",
9
- Select = "Select",
10
- Update = "Update",
11
- Delete = "Delete",
12
- CreateTable = "CreateTable",
13
- CreateIndex = "CreateIndex",
14
- DropIndex = "DropIndex",
15
- AlterTable = "AlterTable",
16
- Batch = "Batch",
17
- Transaction = "Transaction",
18
- Raw = "Raw"
19
- }
20
- export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.CreateIndex | Query.DropIndex | Query.AlterTable | Query.Batch | Query.Transaction | Query.Raw;
21
- export declare namespace Query {
22
- interface QueryBase {
23
- limit?: number;
24
- offset?: number;
25
- type: QueryType;
26
- where?: ExprData;
27
- orderBy?: Array<OrderBy>;
28
- groupBy?: Array<ExprData>;
29
- having?: ExprData;
30
- selection?: ExprData;
31
- singleResult?: boolean;
32
- validate?: boolean;
33
- }
34
- interface Insert extends QueryBase {
35
- type: QueryType.Insert;
36
- into: Schema;
37
- data: Array<any>;
38
- }
39
- function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
40
- interface Select extends QueryBase {
41
- type: QueryType.Select;
42
- selection: ExprData;
43
- from: Target;
44
- }
45
- function Select(select: Omit<Select, 'type'>): Query.Select;
46
- interface Update extends QueryBase {
47
- type: QueryType.Update;
48
- table: Schema;
49
- set?: Record<string, any>;
50
- }
51
- function Update(update: Omit<Update, 'type'>): Query.Update;
52
- interface Delete extends QueryBase {
53
- type: QueryType.Delete;
54
- table: Schema;
55
- }
56
- function Delete(del: Omit<Delete, 'type'>): Query.Delete;
57
- interface CreateTable extends QueryBase {
58
- type: QueryType.CreateTable;
59
- table: Schema;
60
- ifNotExists?: boolean;
61
- }
62
- function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
63
- interface CreateIndex extends QueryBase {
64
- type: QueryType.CreateIndex;
65
- table: Schema;
66
- index: IndexData;
67
- ifNotExists?: boolean;
68
- }
69
- function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
70
- interface DropIndex extends QueryBase {
71
- type: QueryType.DropIndex;
72
- table: Schema;
73
- name: string;
74
- ifExists?: boolean;
75
- }
76
- function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
77
- interface Batch extends QueryBase {
78
- type: QueryType.Batch;
79
- queries: Array<Query<any>>;
80
- }
81
- function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
82
- enum TransactionOperation {
83
- Begin = "Begin",
84
- Commit = "Commit",
85
- Rollback = "Rollback"
86
- }
87
- interface Transaction extends QueryBase {
88
- type: QueryType.Transaction;
89
- id: string;
90
- op: TransactionOperation;
91
- }
92
- function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
93
- type RawReturn = 'row' | 'rows' | undefined;
94
- interface Raw extends QueryBase {
95
- type: QueryType.Raw;
96
- expectedReturn?: 'row' | 'rows';
97
- strings: ReadonlyArray<string>;
98
- params: Array<any>;
99
- }
100
- function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
101
- interface AlterTable extends QueryBase {
102
- type: QueryType.AlterTable;
103
- table: Schema;
104
- alterColumn?: ColumnData;
105
- addColumn?: ColumnData;
106
- dropColumn?: string;
107
- }
108
- function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
109
- }
1
+ import { ColumnData } from './Column';
2
+ import { ExprData } from './Expr';
3
+ import { IndexData } from './Index';
4
+ import { OrderBy } from './OrderBy';
5
+ import { Schema } from './Schema';
6
+ import { Target } from './Target';
7
+ export declare enum QueryType {
8
+ Insert = "Insert",
9
+ Select = "Select",
10
+ Update = "Update",
11
+ Delete = "Delete",
12
+ CreateTable = "CreateTable",
13
+ CreateIndex = "CreateIndex",
14
+ DropIndex = "DropIndex",
15
+ AlterTable = "AlterTable",
16
+ Batch = "Batch",
17
+ Transaction = "Transaction",
18
+ Raw = "Raw"
19
+ }
20
+ export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.CreateIndex | Query.DropIndex | Query.AlterTable | Query.Batch | Query.Transaction | Query.Raw;
21
+ export declare namespace Query {
22
+ interface QueryBase {
23
+ limit?: number;
24
+ offset?: number;
25
+ type: QueryType;
26
+ where?: ExprData;
27
+ orderBy?: Array<OrderBy>;
28
+ groupBy?: Array<ExprData>;
29
+ having?: ExprData;
30
+ selection?: ExprData;
31
+ singleResult?: boolean;
32
+ validate?: boolean;
33
+ }
34
+ interface Insert extends QueryBase {
35
+ type: QueryType.Insert;
36
+ into: Schema;
37
+ data: Array<any>;
38
+ }
39
+ function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
40
+ interface Select extends QueryBase {
41
+ type: QueryType.Select;
42
+ selection: ExprData;
43
+ from: Target;
44
+ }
45
+ function Select(select: Omit<Select, 'type'>): Query.Select;
46
+ interface Update extends QueryBase {
47
+ type: QueryType.Update;
48
+ table: Schema;
49
+ set?: Record<string, any>;
50
+ }
51
+ function Update(update: Omit<Update, 'type'>): Query.Update;
52
+ interface Delete extends QueryBase {
53
+ type: QueryType.Delete;
54
+ table: Schema;
55
+ }
56
+ function Delete(del: Omit<Delete, 'type'>): Query.Delete;
57
+ interface CreateTable extends QueryBase {
58
+ type: QueryType.CreateTable;
59
+ table: Schema;
60
+ ifNotExists?: boolean;
61
+ }
62
+ function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
63
+ interface CreateIndex extends QueryBase {
64
+ type: QueryType.CreateIndex;
65
+ table: Schema;
66
+ index: IndexData;
67
+ ifNotExists?: boolean;
68
+ }
69
+ function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
70
+ interface DropIndex extends QueryBase {
71
+ type: QueryType.DropIndex;
72
+ table: Schema;
73
+ name: string;
74
+ ifExists?: boolean;
75
+ }
76
+ function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
77
+ interface Batch extends QueryBase {
78
+ type: QueryType.Batch;
79
+ queries: Array<Query<any>>;
80
+ }
81
+ function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
82
+ enum TransactionOperation {
83
+ Begin = "Begin",
84
+ Commit = "Commit",
85
+ Rollback = "Rollback"
86
+ }
87
+ interface Transaction extends QueryBase {
88
+ type: QueryType.Transaction;
89
+ id: string;
90
+ op: TransactionOperation;
91
+ }
92
+ function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
93
+ type RawReturn = 'row' | 'rows' | undefined;
94
+ interface Raw extends QueryBase {
95
+ type: QueryType.Raw;
96
+ expectedReturn?: 'row' | 'rows';
97
+ strings: ReadonlyArray<string>;
98
+ params: Array<any>;
99
+ }
100
+ function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
101
+ interface AlterTable extends QueryBase {
102
+ type: QueryType.AlterTable;
103
+ table: Schema;
104
+ alterColumn?: ColumnData;
105
+ addColumn?: ColumnData;
106
+ dropColumn?: string;
107
+ }
108
+ function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
109
+ }
@@ -1,18 +1,18 @@
1
- import { Formatter } from '../lib/Formatter';
2
- import { ColumnData } from './Column';
3
- import { IndexData } from './Index';
4
- import { Query } from './Query';
5
- export interface Schema {
6
- name: string;
7
- alias?: string;
8
- columns: Record<string, ColumnData>;
9
- indexes: Record<string, IndexData>;
10
- }
11
- export interface SchemaInstructions {
12
- columns: Record<string, string>;
13
- indexes: Record<string, string>;
14
- }
15
- export declare namespace Schema {
16
- function create(schema: Schema): Query.Batch;
17
- function upgrade(formatter: Formatter, local: SchemaInstructions, schema: Schema): Array<Query>;
18
- }
1
+ import { Formatter } from '../lib/Formatter';
2
+ import { ColumnData } from './Column';
3
+ import { IndexData } from './Index';
4
+ import { Query } from './Query';
5
+ export interface Schema {
6
+ name: string;
7
+ alias?: string;
8
+ columns: Record<string, ColumnData>;
9
+ indexes: Record<string, IndexData>;
10
+ }
11
+ export interface SchemaInstructions {
12
+ columns: Record<string, string>;
13
+ indexes: Record<string, string>;
14
+ }
15
+ export declare namespace Schema {
16
+ function create(schema: Schema): Query.Batch;
17
+ function upgrade(formatter: Formatter, local: SchemaInstructions, schema: Schema): Array<Query>;
18
+ }
@@ -1,20 +1,20 @@
1
- import type { Cursor } from './Cursor';
2
- import type { Expr } from './Expr';
3
- type SelectionBase = (() => any) | Expr<any> | Cursor.SelectMultiple<any> | Cursor.SelectSingle<any>;
4
- interface SelectionRecord extends Record<string, Selection> {
5
- }
6
- export type Selection = SelectionBase | SelectionRecord;
7
- export declare namespace Selection {
8
- const __tableType: unique symbol;
9
- const __cursorType: unique symbol;
10
- type Infer<T> = T extends {
11
- [__tableType](): infer K;
12
- } ? K : T extends {
13
- [__cursorType](): infer K;
14
- } ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
15
- [K in keyof T as T[K] extends () => any ? never : K]: Infer<T[K]>;
16
- } : T extends () => any ? never : T;
17
- type With<A, B> = Expr<Combine<A, B>>;
18
- type Combine<A, B> = Omit<A, keyof Infer<B>> & Infer<B>;
19
- }
20
- export {};
1
+ import type { Cursor } from './Cursor';
2
+ import type { Expr } from './Expr';
3
+ type SelectionBase = (() => any) | Expr<any> | Cursor.SelectMultiple<any> | Cursor.SelectSingle<any>;
4
+ interface SelectionRecord extends Record<string, Selection> {
5
+ }
6
+ export type Selection = SelectionBase | SelectionRecord;
7
+ export declare namespace Selection {
8
+ const __tableType: unique symbol;
9
+ const __cursorType: unique symbol;
10
+ type Infer<T> = T extends {
11
+ [__tableType](): infer K;
12
+ } ? K : T extends {
13
+ [__cursorType](): infer K;
14
+ } ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
15
+ [K in keyof T as T[K] extends () => any ? never : K]: Infer<T[K]>;
16
+ } : T extends () => any ? never : T;
17
+ type With<A, B> = Expr<Combine<A, B>>;
18
+ type Combine<A, B> = Omit<A, keyof Infer<B>> & Infer<B>;
19
+ }
20
+ export {};
@@ -1,62 +1,62 @@
1
- import { Column, PrimaryKey } from './Column';
2
- import { Cursor } from './Cursor';
3
- import { EV, Expr } from './Expr';
4
- import { Fields } from './Fields';
5
- import { Index } from './Index';
6
- import { Schema } from './Schema';
7
- import { Selection } from './Selection';
8
- import { Update } from './Update';
9
- export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>> {
10
- [Selection.__tableType](): Table.Normalize<T>;
11
- constructor(schema: Schema);
12
- fetch(id: EV<T extends {
13
- id: Column.IsPrimary<infer V, any>;
14
- } ? V : never>): Cursor.SelectSingle<Table.Normalize<T> | undefined>;
15
- insertOne(record: Table.Insert<T>): Cursor<Table.Normalize<T>>;
16
- insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
17
- set(data: Update<Table.Normalize<T>>): Cursor.Update<Table.Normalize<T>>;
18
- delete(): Cursor.Delete;
19
- createTable(): Cursor.CreateTable;
20
- as(alias: string): this;
21
- alias(): Record<string, this>;
22
- get(name: string): Expr<any>;
23
- toExpr(): Expr<Table.Normalize<T>>;
24
- schema(): Schema;
25
- }
26
- export declare namespace Table {
27
- type Intersection<A, B> = A & B extends infer U ? {
28
- [P in keyof U]: EV<U[P]>;
29
- } : never;
30
- type OptionalKeys<T> = {
31
- [K in keyof T]: null extends T[K] ? K : T[K] extends Column.IsPrimary<any, any> ? K : T[K] extends Column.IsOptional<any> ? K : never;
32
- }[keyof T];
33
- type RequiredKeys<T> = {
34
- [K in keyof T]: null extends T[K] ? never : T[K] extends Column.IsPrimary<any, any> ? never : T[K] extends Column.IsOptional<any> ? never : K;
35
- }[keyof T];
36
- type Optionals<T> = {
37
- [K in keyof T]?: T[K] extends Column.IsOptional<infer V> ? V : T[K] extends Column.IsPrimary<infer V, infer K> ? PrimaryKey<V, K> : T[K];
38
- };
39
- export type Insert<T> = Intersection<Optionals<Pick<T, OptionalKeys<T>>>, Pick<T, RequiredKeys<T>>>;
40
- export type Normalize<T> = {
41
- [K in keyof T]: T[K] extends Column.IsOptional<infer V> ? V : T[K] extends Column.IsPrimary<infer V, infer K> ? PrimaryKey<V, K> : T[K];
42
- };
43
- export type Infer<T> = T extends Table<infer U> ? Normalize<U> : never;
44
- export {};
45
- }
46
- export type TableOptions<T, R> = {
47
- name: string;
48
- alias?: string;
49
- columns: {
50
- [K in keyof T]: Column<T[K]>;
51
- };
52
- indexes?: (this: Fields<T>) => Record<string, Index>;
53
- };
54
- export declare function table<T extends {}, R>(options: TableOptions<T, R>): Table<T> & Fields<T>;
55
- export declare namespace table {
56
- export type infer<T> = Table.Infer<T>;
57
- type Extensions<T> = {
58
- [key: string]: (this: T, ...args: any[]) => any;
59
- };
60
- export function extend<T extends Table<any>, E extends Extensions<T>>(target: T, extensions: E): T & E;
61
- export {};
62
- }
1
+ import { Column, PrimaryKey } from './Column';
2
+ import { Cursor } from './Cursor';
3
+ import { EV, Expr } from './Expr';
4
+ import { Fields } from './Fields';
5
+ import { Index } from './Index';
6
+ import { Schema } from './Schema';
7
+ import { Selection } from './Selection';
8
+ import { Update } from './Update';
9
+ export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>> {
10
+ [Selection.__tableType](): Table.Normalize<T>;
11
+ constructor(schema: Schema);
12
+ fetch(id: EV<T extends {
13
+ id: Column.IsPrimary<infer V, any>;
14
+ } ? V : never>): Cursor.SelectSingle<Table.Normalize<T> | undefined>;
15
+ insertOne(record: Table.Insert<T>): Cursor<Table.Normalize<T>>;
16
+ insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
17
+ set(data: Update<Table.Normalize<T>>): Cursor.Update<Table.Normalize<T>>;
18
+ delete(): Cursor.Delete;
19
+ createTable(): Cursor.CreateTable;
20
+ as(alias: string): this;
21
+ alias(): Record<string, this>;
22
+ get(name: string): Expr<any>;
23
+ toExpr(): Expr<Table.Normalize<T>>;
24
+ schema(): Schema;
25
+ }
26
+ export declare namespace Table {
27
+ type Intersection<A, B> = A & B extends infer U ? {
28
+ [P in keyof U]: EV<U[P]>;
29
+ } : never;
30
+ type OptionalKeys<T> = {
31
+ [K in keyof T]: null extends T[K] ? K : T[K] extends Column.IsPrimary<any, any> ? K : T[K] extends Column.IsOptional<any> ? K : never;
32
+ }[keyof T];
33
+ type RequiredKeys<T> = {
34
+ [K in keyof T]: null extends T[K] ? never : T[K] extends Column.IsPrimary<any, any> ? never : T[K] extends Column.IsOptional<any> ? never : K;
35
+ }[keyof T];
36
+ type Optionals<T> = {
37
+ [K in keyof T]?: T[K] extends Column.IsOptional<infer V> ? V : T[K] extends Column.IsPrimary<infer V, infer K> ? PrimaryKey<V, K> : T[K];
38
+ };
39
+ export type Insert<T> = Intersection<Optionals<Pick<T, OptionalKeys<T>>>, Pick<T, RequiredKeys<T>>>;
40
+ export type Normalize<T> = {
41
+ [K in keyof T]: T[K] extends Column.IsOptional<infer V> ? V : T[K] extends Column.IsPrimary<infer V, infer K> ? PrimaryKey<V, K> : T[K];
42
+ };
43
+ export type Infer<T> = T extends Table<infer U> ? Normalize<U> : never;
44
+ export {};
45
+ }
46
+ export type TableOptions<T, R> = {
47
+ name: string;
48
+ alias?: string;
49
+ columns: {
50
+ [K in keyof T]: Column<T[K]>;
51
+ };
52
+ indexes?: (this: Fields<T>) => Record<string, Index>;
53
+ };
54
+ export declare function table<T extends {}, R>(options: TableOptions<T, R>): Table<T> & Fields<T>;
55
+ export declare namespace table {
56
+ export type infer<T> = Table.Infer<T>;
57
+ type Extensions<T> = {
58
+ [key: string]: (this: T, ...args: any[]) => any;
59
+ };
60
+ export function extend<T extends Table<any>, E extends Extensions<T>>(target: T, extensions: E): T & E;
61
+ export {};
62
+ }
@@ -1,38 +1,38 @@
1
- import { ExprData } from './Expr';
2
- import { Query as QueryData } from './Query';
3
- import { Schema } from './Schema';
4
- export declare enum TargetType {
5
- Expr = "Expr",
6
- Query = "Query",
7
- Table = "Table",
8
- Join = "Join"
9
- }
10
- export type Target = Target.Expr | Target.Query | Target.Table | Target.Join;
11
- export declare namespace Target {
12
- interface Expr {
13
- type: TargetType.Expr;
14
- expr: ExprData;
15
- alias?: string;
16
- }
17
- function Expr(expr: ExprData, alias?: string): Expr;
18
- interface Query {
19
- type: TargetType.Query;
20
- query: QueryData;
21
- alias?: string;
22
- }
23
- function Query(query: QueryData, alias?: string): Query;
24
- interface Table {
25
- type: TargetType.Table;
26
- table: Schema;
27
- }
28
- function Table(table: Schema): Table;
29
- interface Join {
30
- type: TargetType.Join;
31
- left: Target;
32
- right: Target;
33
- joinType: 'left' | 'inner';
34
- on: ExprData;
35
- }
36
- function Join(left: Target, right: Target, joinType: 'left' | 'inner', on: ExprData): Join;
37
- function source(from: Target): Schema | undefined;
38
- }
1
+ import { ExprData } from './Expr';
2
+ import { Query as QueryData } from './Query';
3
+ import { Schema } from './Schema';
4
+ export declare enum TargetType {
5
+ Expr = "Expr",
6
+ Query = "Query",
7
+ Table = "Table",
8
+ Join = "Join"
9
+ }
10
+ export type Target = Target.Expr | Target.Query | Target.Table | Target.Join;
11
+ export declare namespace Target {
12
+ interface Expr {
13
+ type: TargetType.Expr;
14
+ expr: ExprData;
15
+ alias?: string;
16
+ }
17
+ function Expr(expr: ExprData, alias?: string): Expr;
18
+ interface Query {
19
+ type: TargetType.Query;
20
+ query: QueryData;
21
+ alias?: string;
22
+ }
23
+ function Query(query: QueryData, alias?: string): Query;
24
+ interface Table {
25
+ type: TargetType.Table;
26
+ table: Schema;
27
+ }
28
+ function Table(table: Schema): Table;
29
+ interface Join {
30
+ type: TargetType.Join;
31
+ left: Target;
32
+ right: Target;
33
+ joinType: 'left' | 'inner';
34
+ on: ExprData;
35
+ }
36
+ function Join(left: Target, right: Target, joinType: 'left' | 'inner', on: ExprData): Join;
37
+ function source(from: Target): Schema | undefined;
38
+ }