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,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
- }
package/dist/lib/Query.js DELETED
@@ -1,74 +0,0 @@
1
- // src/lib/Query.ts
2
- var QueryType = /* @__PURE__ */ ((QueryType2) => {
3
- QueryType2["Insert"] = "Insert";
4
- QueryType2["Select"] = "Select";
5
- QueryType2["Update"] = "Update";
6
- QueryType2["Delete"] = "Delete";
7
- QueryType2["CreateTable"] = "CreateTable";
8
- QueryType2["CreateIndex"] = "CreateIndex";
9
- QueryType2["DropIndex"] = "DropIndex";
10
- QueryType2["AlterTable"] = "AlterTable";
11
- QueryType2["Batch"] = "Batch";
12
- QueryType2["Transaction"] = "Transaction";
13
- QueryType2["Raw"] = "Raw";
14
- return QueryType2;
15
- })(QueryType || {});
16
- var Query;
17
- ((Query2) => {
18
- function Insert(insert) {
19
- return { type: "Insert" /* Insert */, ...insert };
20
- }
21
- Query2.Insert = Insert;
22
- function Select(select) {
23
- return { type: "Select" /* Select */, ...select };
24
- }
25
- Query2.Select = Select;
26
- function Update(update) {
27
- return { type: "Update" /* Update */, ...update };
28
- }
29
- Query2.Update = Update;
30
- function Delete(del) {
31
- return { type: "Delete" /* Delete */, ...del };
32
- }
33
- Query2.Delete = Delete;
34
- function CreateTable(create) {
35
- return { type: "CreateTable" /* CreateTable */, ...create };
36
- }
37
- Query2.CreateTable = CreateTable;
38
- function CreateIndex(create) {
39
- return { type: "CreateIndex" /* CreateIndex */, ...create };
40
- }
41
- Query2.CreateIndex = CreateIndex;
42
- function DropIndex(drop) {
43
- return { type: "DropIndex" /* DropIndex */, ...drop };
44
- }
45
- Query2.DropIndex = DropIndex;
46
- function Batch(batch) {
47
- return { type: "Batch" /* Batch */, ...batch };
48
- }
49
- Query2.Batch = Batch;
50
- let TransactionOperation;
51
- ((TransactionOperation2) => {
52
- TransactionOperation2["Begin"] = "Begin";
53
- TransactionOperation2["Commit"] = "Commit";
54
- TransactionOperation2["Rollback"] = "Rollback";
55
- })(TransactionOperation = Query2.TransactionOperation || (Query2.TransactionOperation = {}));
56
- function Transaction(transaction) {
57
- return { type: "Transaction" /* Transaction */, ...transaction };
58
- }
59
- Query2.Transaction = Transaction;
60
- function Raw(raw) {
61
- if (raw.strings.some((chunk) => chunk.includes("?")))
62
- throw new TypeError("SQL injection hazard");
63
- return { type: "Raw" /* Raw */, ...raw };
64
- }
65
- Query2.Raw = Raw;
66
- function AlterTable(alter) {
67
- return { type: "AlterTable" /* AlterTable */, ...alter };
68
- }
69
- Query2.AlterTable = AlterTable;
70
- })(Query || (Query = {}));
71
- export {
72
- Query,
73
- QueryType
74
- };
@@ -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,67 +0,0 @@
1
- // src/lib/Schema.ts
2
- import { Query } from "./Query.js";
3
- import { Statement } from "./Statement.js";
4
- var Schema;
5
- ((Schema2) => {
6
- function create(schema) {
7
- const queries = [];
8
- queries.push(Query.CreateTable({ table: schema, ifNotExists: true }));
9
- for (const index of Object.values(schema.indexes))
10
- queries.push(Query.CreateIndex({ table: schema, index, ifNotExists: true }));
11
- return Query.Batch({ queries });
12
- }
13
- Schema2.create = create;
14
- function removeLeadingWhitespace(str) {
15
- return str.replace(/\n\s+/g, "\n");
16
- }
17
- function upgrade(formatter, local, schema) {
18
- const columnNames = /* @__PURE__ */ new Set([
19
- ...Object.keys(local.columns),
20
- ...Object.keys(schema.columns)
21
- ]);
22
- const res = [];
23
- for (const columnName of columnNames) {
24
- const localInstruction = local.columns[columnName];
25
- const schemaCol = schema.columns[columnName];
26
- if (!localInstruction) {
27
- res.push(Query.AlterTable({ table: schema, addColumn: schemaCol }));
28
- } else if (!schemaCol) {
29
- res.push(Query.AlterTable({ table: schema, dropColumn: columnName }));
30
- } else {
31
- const { sql: instruction } = formatter.formatColumn(
32
- { stmt: new Statement(formatter) },
33
- { ...schemaCol, references: void 0 }
34
- );
35
- if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
36
- res.push(Query.AlterTable({ table: schema, alterColumn: schemaCol }));
37
- }
38
- }
39
- }
40
- const indexNames = /* @__PURE__ */ new Set([
41
- ...Object.keys(local.indexes),
42
- ...Object.keys(schema.indexes)
43
- ]);
44
- for (const indexName of indexNames) {
45
- const localInstruction = local.indexes[indexName];
46
- const schemaIndex = schema.indexes[indexName];
47
- if (!localInstruction) {
48
- res.push(Query.CreateIndex({ table: schema, index: schemaIndex }));
49
- } else if (!schemaIndex) {
50
- res.unshift(Query.DropIndex({ table: schema, name: indexName }));
51
- } else {
52
- const { sql: instruction } = formatter.compile(
53
- Query.CreateIndex({ table: schema, index: schemaIndex })
54
- );
55
- if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
56
- res.unshift(Query.DropIndex({ table: schema, name: indexName }));
57
- res.push(Query.CreateIndex({ table: schema, index: schemaIndex }));
58
- }
59
- }
60
- }
61
- return res;
62
- }
63
- Schema2.upgrade = upgrade;
64
- })(Schema || (Schema = {}));
65
- export {
66
- Schema
67
- };
@@ -1,20 +0,0 @@
1
- import type { Cursor } from './Cursor';
2
- import type { Expr } from './Expr';
3
- type SelectionBase = 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]: Infer<T[K]>;
16
- } : 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,7 +0,0 @@
1
- // src/lib/Selection.ts
2
- var Selection;
3
- ((Selection2) => {
4
- })(Selection || (Selection = {}));
5
- export {
6
- Selection
7
- };
@@ -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.Create;
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
- }
package/dist/lib/Table.js DELETED
@@ -1,130 +0,0 @@
1
- // src/lib/Table.ts
2
- import { Cursor } from "./Cursor.js";
3
- import { Expr, ExprData } from "./Expr.js";
4
- import { Query } from "./Query.js";
5
- import { Selection } from "./Selection.js";
6
- import { Target } from "./Target.js";
7
- var Table = class extends Cursor.SelectMultiple {
8
- [Selection.__tableType]() {
9
- throw "assert";
10
- }
11
- constructor(schema) {
12
- super(
13
- Query.Select({
14
- from: Target.Table(schema),
15
- selection: ExprData.Row(Target.Table(schema))
16
- })
17
- );
18
- Object.defineProperty(this, "schema", {
19
- enumerable: false,
20
- value: () => schema
21
- });
22
- if (schema.columns)
23
- for (const column of Object.keys(schema.columns)) {
24
- Object.defineProperty(this, column, {
25
- enumerable: true,
26
- get: () => this.get(column)
27
- });
28
- }
29
- return new Proxy(this, {
30
- get(target, key) {
31
- return key in target ? target[key] : target.get(key);
32
- }
33
- });
34
- }
35
- fetch(id) {
36
- return this.where(this.get("id").is(id)).first();
37
- }
38
- insertOne(record) {
39
- return new Cursor(
40
- Query.Insert({
41
- into: this.schema(),
42
- data: [record],
43
- selection: ExprData.Row(Target.Table(this.schema())),
44
- singleResult: true
45
- })
46
- );
47
- }
48
- insertAll(data) {
49
- return new Cursor.Insert(this.schema()).values(...data);
50
- }
51
- set(data) {
52
- return new Cursor.Update(
53
- Query.Update({
54
- table: this.schema()
55
- })
56
- ).set(data);
57
- }
58
- delete() {
59
- return new Cursor.Delete(Query.Delete({ table: this.schema() }));
60
- }
61
- createTable() {
62
- return new Cursor.Create(this.schema());
63
- }
64
- as(alias) {
65
- return new Table({ ...this.schema(), alias });
66
- }
67
- alias() {
68
- return new Proxy(
69
- {},
70
- {
71
- get: (_, key) => {
72
- return this.as(key);
73
- }
74
- }
75
- );
76
- }
77
- get(name) {
78
- return new Expr(ExprData.Field(this.toExpr().expr, name));
79
- }
80
- toExpr() {
81
- return new Expr(
82
- ExprData.Row(Target.Table(this.schema()))
83
- );
84
- }
85
- schema() {
86
- throw new Error("Not implemented");
87
- }
88
- };
89
- function table(options) {
90
- const schema = {
91
- ...options,
92
- columns: Object.fromEntries(
93
- Object.entries(options.columns).map(([key, column]) => {
94
- const { data } = column;
95
- return [key, { ...data, name: data.name || key }];
96
- })
97
- ),
98
- indexes: {}
99
- };
100
- const indexes = Object.fromEntries(
101
- Object.entries(
102
- options.indexes ? options.indexes.call(
103
- new Expr(ExprData.Row(Target.Table(schema)))
104
- ) : {}
105
- ).map(([key, index]) => {
106
- const indexName = `${schema.name}.${key}`;
107
- return [indexName, { name: indexName, ...index.data }];
108
- })
109
- );
110
- return new Table({
111
- ...schema,
112
- indexes
113
- });
114
- }
115
- ((table2) => {
116
- function extend(target, extensions) {
117
- return new Proxy(target, {
118
- get(target2, key) {
119
- if (key === "as")
120
- return (...args) => extend(target2.as(...args), extensions);
121
- return key in extensions ? extensions[key].bind(target2) : target2[key];
122
- }
123
- });
124
- }
125
- table2.extend = extend;
126
- })(table || (table = {}));
127
- export {
128
- Table,
129
- table
130
- };
@@ -1,30 +0,0 @@
1
- import { ExprData } from './Expr';
2
- import { Schema } from './Schema';
3
- export declare enum TargetType {
4
- Each = "Each",
5
- Table = "Table",
6
- Join = "Join"
7
- }
8
- export type Target = Target.Each | Target.Table | Target.Join;
9
- export declare namespace Target {
10
- interface Each {
11
- type: TargetType.Each;
12
- expr: ExprData;
13
- alias: string;
14
- }
15
- function Each(expr: ExprData, alias: string): Each;
16
- interface Table {
17
- type: TargetType.Table;
18
- table: Schema;
19
- }
20
- function Table(table: Schema): Table;
21
- interface Join {
22
- type: TargetType.Join;
23
- left: Target;
24
- right: Target;
25
- joinType: 'left' | 'inner';
26
- on: ExprData;
27
- }
28
- function Join(left: Target, right: Target, joinType: 'left' | 'inner', on: ExprData): Join;
29
- function source(from: Target): Schema | undefined;
30
- }
@@ -1,37 +0,0 @@
1
- // src/lib/Target.ts
2
- var TargetType = /* @__PURE__ */ ((TargetType2) => {
3
- TargetType2["Each"] = "Each";
4
- TargetType2["Table"] = "Table";
5
- TargetType2["Join"] = "Join";
6
- return TargetType2;
7
- })(TargetType || {});
8
- var Target;
9
- ((Target2) => {
10
- function Each(expr, alias) {
11
- return { type: "Each" /* Each */, expr, alias };
12
- }
13
- Target2.Each = Each;
14
- function Table(table) {
15
- return { type: "Table" /* Table */, table };
16
- }
17
- Target2.Table = Table;
18
- function Join(left, right, joinType, on) {
19
- return { type: "Join" /* Join */, left, right, joinType, on };
20
- }
21
- Target2.Join = Join;
22
- function source(from) {
23
- switch (from.type) {
24
- case "Table" /* Table */:
25
- return from.table;
26
- case "Join" /* Join */:
27
- return source(from.left);
28
- default:
29
- return void 0;
30
- }
31
- }
32
- Target2.source = source;
33
- })(Target || (Target = {}));
34
- export {
35
- Target,
36
- TargetType
37
- };
@@ -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
@@ -1,2 +0,0 @@
1
- export * from './SqliteFormatter';
2
- export * from './SqliteFunctions';
@@ -1,3 +0,0 @@
1
- // src/sqlite/index.ts
2
- export * from "./SqliteFormatter.js";
3
- export * from "./SqliteFunctions.js";
@@ -1,49 +0,0 @@
1
- // src/driver/better-sqlite3.ts
2
- import { Driver } from "../lib/Driver.js";
3
- import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
- import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
- var PreparedStatement = class {
6
- constructor(stmt) {
7
- this.stmt = stmt;
8
- }
9
- all(params = []) {
10
- return this.stmt.all(...params);
11
- }
12
- run(params = []) {
13
- return { rowsAffected: this.stmt.run(...params).changes };
14
- }
15
- get(params = []) {
16
- return this.stmt.get(...params);
17
- }
18
- execute(params = []) {
19
- this.stmt.run(...params);
20
- }
21
- };
22
- var BetterSqlite3Driver = class extends Driver.Sync {
23
- constructor(db) {
24
- super(new SqliteFormatter());
25
- this.db = db;
26
- this.tableData = this.prepare(SqliteSchema.tableData);
27
- this.indexData = this.prepare(SqliteSchema.indexData);
28
- }
29
- tableData;
30
- indexData;
31
- prepareStatement(stmt) {
32
- return new PreparedStatement(this.db.prepare(stmt.sql));
33
- }
34
- schemaInstructions(tableName) {
35
- const columnData = this.tableData(tableName);
36
- const indexData = this.indexData(tableName);
37
- return SqliteSchema.createInstructions(columnData, indexData);
38
- }
39
- export() {
40
- return this.db.serialize();
41
- }
42
- };
43
- function connect(db) {
44
- return new BetterSqlite3Driver(db);
45
- }
46
- export {
47
- BetterSqlite3Driver,
48
- connect
49
- };