rado 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +2 -0
  2. package/dist/define/CTE.d.ts +2 -0
  3. package/dist/define/CTE.js +51 -0
  4. package/dist/define/Cursor.d.ts +65 -42
  5. package/dist/define/Cursor.js +170 -88
  6. package/dist/define/Expr.d.ts +2 -2
  7. package/dist/define/Expr.js +4 -1
  8. package/dist/define/Ops.d.ts +1 -6
  9. package/dist/define/Ops.js +10 -7
  10. package/dist/define/Query.d.ts +117 -2
  11. package/dist/define/Query.js +472 -17
  12. package/dist/define/Selection.d.ts +1 -1
  13. package/dist/define/Table.d.ts +6 -3
  14. package/dist/define/Table.js +6 -1
  15. package/dist/define/VirtualTable.d.ts +1 -1
  16. package/dist/define/query/Delete.d.ts +0 -2
  17. package/dist/define/query/Delete.js +0 -3
  18. package/dist/define/query/Select.d.ts +0 -2
  19. package/dist/define/query/Select.js +1 -14
  20. package/dist/deno/driver/better-sqlite3.js +57 -0
  21. package/dist/deno/driver/bun-sqlite.js +69 -0
  22. package/dist/deno/driver/sql.js.js +72 -0
  23. package/dist/deno/driver/sqlite3.js +123 -0
  24. package/dist/deno/index.js +14 -0
  25. package/dist/deno/lib/Driver.js +330 -0
  26. package/dist/deno/lib/Formatter.js +715 -0
  27. package/dist/deno/lib/SqlError.js +11 -0
  28. package/dist/deno/lib/Statement.js +108 -0
  29. package/dist/deno/sqlite/SqliteFormatter.js +70 -0
  30. package/dist/deno/sqlite/SqliteFunctions.js +150 -0
  31. package/dist/deno/sqlite/SqliteSchema.js +47 -0
  32. package/dist/deno/sqlite.js +3 -0
  33. package/dist/deno/util/Callable.js +15 -0
  34. package/dist/driver/bun-sqlite.js +1 -2
  35. package/dist/index.d.ts +0 -8
  36. package/dist/index.js +0 -8
  37. package/dist/lib/Driver.d.ts +1 -2
  38. package/dist/lib/Formatter.js +17 -3
  39. package/dist/sqlite/index.d.ts +2 -0
  40. package/dist/sqlite/index.js +3 -0
  41. package/dist/src/driver/better-sqlite3.js +49 -0
  42. package/dist/src/driver/sql.js.js +66 -0
  43. package/dist/src/driver/sqlite3.js +87 -0
  44. package/dist/src/index.js +24 -0
  45. package/dist/{lib → src/lib}/Column.js +1 -6
  46. package/dist/{lib → src/lib}/Cursor.js +25 -50
  47. package/dist/src/lib/Driver.js +316 -0
  48. package/dist/{lib → src/lib}/Expr.js +4 -4
  49. package/dist/src/lib/Formatter.js +625 -0
  50. package/dist/{lib → src/lib}/Ops.js +14 -5
  51. package/dist/src/lib/Sanitizer.js +0 -0
  52. package/dist/src/lib/Statement.js +103 -0
  53. package/dist/{lib → src/lib}/Table.js +1 -1
  54. package/dist/{lib → src/lib}/Target.js +4 -9
  55. package/dist/src/lib/Update.js +0 -0
  56. package/dist/src/sqlite/SqliteFormatter.js +67 -0
  57. package/dist/src/sqlite/SqliteFunctions.js +146 -0
  58. package/dist/src/sqlite/SqliteSchema.js +47 -0
  59. package/dist/src/sqlite.js +3 -0
  60. package/dist/test/DbSuite.js +28 -0
  61. package/dist/test/TSTestTypes.js +6 -0
  62. package/dist/test/TestBasic.js +172 -0
  63. package/dist/test/TestExtend.js +68 -0
  64. package/dist/test/TestFts5.js +34 -0
  65. package/dist/test/TestFunctions.js +28 -0
  66. package/dist/test/TestJoins.js +34 -0
  67. package/dist/test/TestJson.js +33 -0
  68. package/dist/test/TestPrepare.js +27 -0
  69. package/dist/test/TestRawSql.js +31 -0
  70. package/dist/test/TestSchema.js +69 -0
  71. package/dist/test/TestSubQueries.js +79 -0
  72. package/dist/test/TestTransaction.js +54 -0
  73. package/dist/test/TestUpdate.js +95 -0
  74. package/dist/test/index.js +14 -0
  75. package/package.json +1 -1
  76. package/dist/lib/Column.d.ts +0 -57
  77. package/dist/lib/Cursor.d.ts +0 -85
  78. package/dist/lib/Expr.d.ts +0 -154
  79. package/dist/lib/Fields.d.ts +0 -13
  80. package/dist/lib/Functions.d.ts +0 -5
  81. package/dist/lib/Id.d.ts +0 -3
  82. package/dist/lib/Index.d.ts +0 -17
  83. package/dist/lib/Ops.d.ts +0 -7
  84. package/dist/lib/OrderBy.d.ts +0 -9
  85. package/dist/lib/Param.d.ts +0 -20
  86. package/dist/lib/Query.d.ts +0 -109
  87. package/dist/lib/Schema.d.ts +0 -18
  88. package/dist/lib/Selection.d.ts +0 -20
  89. package/dist/lib/Table.d.ts +0 -62
  90. package/dist/lib/Target.d.ts +0 -38
  91. package/dist/lib/Update.d.ts +0 -4
  92. /package/dist/{lib/Fields.js → deno/lib/Sanitizer.js} +0 -0
  93. /package/dist/{lib/Id.js → src/lib/Fields.js} +0 -0
  94. /package/dist/{lib → src/lib}/Functions.js +0 -0
  95. /package/dist/{lib/Update.js → src/lib/Id.js} +0 -0
  96. /package/dist/{lib → src/lib}/Index.js +0 -0
  97. /package/dist/{lib → src/lib}/OrderBy.js +0 -0
  98. /package/dist/{lib → src/lib}/Param.js +0 -0
  99. /package/dist/{lib → src/lib}/Query.js +0 -0
  100. /package/dist/{lib → src/lib}/Schema.js +0 -0
  101. /package/dist/{lib → src/lib}/Selection.js +0 -0
@@ -1,154 +0,0 @@
1
- import { Cursor } from './Cursor';
2
- import { Fields } from './Fields';
3
- import { OrderBy } from './OrderBy';
4
- import { ParamData } from './Param';
5
- import { Query } from './Query';
6
- import { Selection } from './Selection';
7
- import { Target } from './Target';
8
- export declare enum UnOp {
9
- Not = "Not",
10
- IsNull = "IsNull"
11
- }
12
- export declare enum BinOp {
13
- Add = "Add",
14
- Subt = "Subt",
15
- Mult = "Mult",
16
- Mod = "Mod",
17
- Div = "Div",
18
- Greater = "Greater",
19
- GreaterOrEqual = "GreaterOrEqual",
20
- Less = "Less",
21
- LessOrEqual = "LessOrEqual",
22
- Equals = "Equals",
23
- NotEquals = "NotEquals",
24
- And = "And",
25
- Or = "Or",
26
- Like = "Like",
27
- Glob = "Glob",
28
- Match = "Match",
29
- In = "In",
30
- NotIn = "NotIn",
31
- Concat = "Concat"
32
- }
33
- export declare enum ExprType {
34
- UnOp = "UnOp",
35
- BinOp = "BinOp",
36
- Field = "Field",
37
- Param = "Param",
38
- Call = "Call",
39
- Query = "Query",
40
- Record = "Record",
41
- Row = "Row",
42
- Map = "Map",
43
- Filter = "Filter",
44
- Merge = "Merge",
45
- Case = "Case"
46
- }
47
- export type ExprData = {
48
- type: ExprType.UnOp;
49
- op: UnOp;
50
- expr: ExprData;
51
- } | {
52
- type: ExprType.BinOp;
53
- op: BinOp;
54
- a: ExprData;
55
- b: ExprData;
56
- } | {
57
- type: ExprType.Field;
58
- expr: ExprData;
59
- field: string;
60
- } | {
61
- type: ExprType.Param;
62
- param: ParamData;
63
- } | {
64
- type: ExprType.Call;
65
- method: string;
66
- params: Array<ExprData>;
67
- } | {
68
- type: ExprType.Query;
69
- query: Query.Select;
70
- } | {
71
- type: ExprType.Record;
72
- fields: Record<string, ExprData>;
73
- } | {
74
- type: ExprType.Merge;
75
- a: ExprData;
76
- b: ExprData;
77
- } | {
78
- type: ExprType.Row;
79
- target: Target;
80
- } | {
81
- type: ExprType.Map;
82
- target: Target;
83
- result: ExprData;
84
- } | {
85
- type: ExprType.Filter;
86
- target: Target;
87
- condition: ExprData;
88
- } | {
89
- type: ExprType.Case;
90
- expr: ExprData;
91
- cases: Record<string, ExprData>;
92
- defaultCase?: ExprData;
93
- };
94
- export declare const ExprData: {
95
- UnOp(op: UnOp, expr: ExprData): ExprData;
96
- BinOp(op: BinOp, a: ExprData, b: ExprData): ExprData;
97
- Field(expr: ExprData, field: string): ExprData;
98
- Param(param: ParamData): ExprData;
99
- Call(method: string, params: Array<ExprData>): ExprData;
100
- Query(query: Query.Select): ExprData;
101
- Record(fields: Record<string, ExprData>): ExprData;
102
- Merge(a: ExprData, b: ExprData): ExprData;
103
- Row(target: Target): ExprData;
104
- Map(target: Target, result: ExprData): ExprData;
105
- Filter(target: Target, condition: ExprData): ExprData;
106
- Case(expr: ExprData, cases: Record<string, ExprData>, defaultCase?: ExprData): ExprData;
107
- create(input: any): ExprData;
108
- };
109
- /** Expression or value of type T */
110
- export type EV<T> = Expr<T> | T;
111
- export declare class Expr<T> {
112
- expr: ExprData;
113
- static NULL: ExprData;
114
- static value<T>(value: T): Expr<T>;
115
- static create<T>(input: EV<T>): Expr<T>;
116
- static and(...conditions: Array<EV<boolean>>): Expr<boolean>;
117
- static or(...conditions: Array<EV<boolean>>): Expr<boolean>;
118
- constructor(expr: ExprData);
119
- asc(): OrderBy;
120
- desc(): OrderBy;
121
- not(): Expr<boolean>;
122
- or(this: Expr<boolean>, that: EV<boolean>): Expr<boolean>;
123
- and(this: Expr<boolean>, that: EV<boolean>): Expr<boolean>;
124
- isNull(): Expr<boolean>;
125
- isNotNull(): Expr<boolean>;
126
- isNot(that: EV<T>): Expr<boolean>;
127
- is(that: EV<T> | Cursor.SelectSingle<T>): Expr<boolean>;
128
- in(that: EV<Array<T>> | Cursor.SelectMultiple<T>): Expr<boolean>;
129
- notIn(that: EV<Array<T>> | Cursor.SelectMultiple<T>): Expr<boolean>;
130
- add(this: Expr<number>, that: EV<number>): Expr<number>;
131
- substract(this: Expr<number>, that: EV<number>): Expr<number>;
132
- multiply(this: Expr<number>, that: EV<number>): Expr<number>;
133
- remainder(this: Expr<number>, that: EV<number>): Expr<number>;
134
- divide(this: Expr<number>, that: EV<number>): Expr<number>;
135
- greater(that: EV<any>): Expr<boolean>;
136
- greaterOrEqual(that: EV<any>): Expr<boolean>;
137
- less(that: EV<any>): Expr<boolean>;
138
- lessOrEqual(that: EV<any>): Expr<boolean>;
139
- concat(this: Expr<string>, that: EV<string>): Expr<string>;
140
- like(this: Expr<string>, that: EV<string>): Expr<boolean>;
141
- glob(this: Expr<string>, that: EV<string>): Expr<boolean>;
142
- match(this: Expr<string>, that: EV<string>): Expr<boolean>;
143
- with<X extends Selection>(that: X): Selection.With<T, X>;
144
- at<T>(this: Expr<Array<T>>, index: number): Expr<T | null>;
145
- filter<T>(this: Expr<Array<T>>, fn: (cursor: Fields<T>) => Expr<boolean>): Expr<Array<T>>;
146
- map<T, X extends Selection>(this: Expr<Array<T>>, fn: (cursor: Fields<T>) => X): Expr<Array<Selection.Infer<X>>>;
147
- sure(): Expr<NonNullable<T>>;
148
- get<T>(name: string): Expr<T>;
149
- }
150
- export declare namespace Expr {
151
- type Record<T> = Expr<T> & {
152
- [K in keyof T]: Expr<T[K]>;
153
- };
154
- }
@@ -1,13 +0,0 @@
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 +0,0 @@
1
- import { Expr } from './Expr';
2
- export declare const Functions: Functions;
3
- export type Functions = {
4
- [key: string]: (...args: Array<any>) => Expr<any>;
5
- };
package/dist/lib/Id.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export type Id<T> = T extends {
2
- id: any;
3
- } ? T['id'] : never;
@@ -1,17 +0,0 @@
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 {};
package/dist/lib/Ops.d.ts DELETED
@@ -1,7 +0,0 @@
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 +0,0 @@
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,20 +0,0 @@
1
- import { Expr } from './Expr';
2
- export declare enum ParamType {
3
- Value = "Value",
4
- Named = "Named"
5
- }
6
- export type ParamData = {
7
- type: ParamType.Value;
8
- value: any;
9
- } | {
10
- type: ParamType.Named;
11
- name: string;
12
- };
13
- export declare const ParamData: {
14
- Value(value: any): ParamData;
15
- Named(name: string): ParamData;
16
- };
17
- export type Params<T> = {
18
- [K in keyof T]: Expr<T[K]>;
19
- };
20
- export declare function createParams<T>(): Params<T>;
@@ -1,109 +0,0 @@
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 +0,0 @@
1
- import { ColumnData } from './Column';
2
- import { Formatter } from './Formatter';
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 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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,4 +0,0 @@
1
- import type { EV } from './Expr';
2
- export type Update<Row> = Partial<{
3
- [K in keyof Row]: EV<Row[K]>;
4
- }>;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes