rado 0.1.11 → 0.1.13

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 (56) hide show
  1. package/dist/driver/better-sqlite3.d.ts +3 -3
  2. package/dist/driver/better-sqlite3.js +1 -1
  3. package/dist/driver/sql.js.d.ts +3 -3
  4. package/dist/driver/sql.js.js +1 -1
  5. package/dist/driver/sqlite3.d.ts +4 -4
  6. package/dist/driver/sqlite3.js +1 -1
  7. package/dist/index.d.ts +20 -19
  8. package/dist/index.js +20 -19
  9. package/dist/{Column.d.ts → lib/Column.d.ts} +9 -6
  10. package/dist/{Column.js → lib/Column.js} +1 -1
  11. package/dist/{Cursor.d.ts → lib/Cursor.d.ts} +0 -0
  12. package/dist/{Cursor.js → lib/Cursor.js} +1 -1
  13. package/dist/{Driver.d.ts → lib/Driver.d.ts} +0 -0
  14. package/dist/{Driver.js → lib/Driver.js} +1 -1
  15. package/dist/{Expr.d.ts → lib/Expr.d.ts} +0 -0
  16. package/dist/{Expr.js → lib/Expr.js} +1 -1
  17. package/dist/lib/Fields.d.ts +13 -0
  18. package/dist/{Fields.js → lib/Fields.js} +0 -0
  19. package/dist/{Formatter.d.ts → lib/Formatter.d.ts} +2 -1
  20. package/dist/{Formatter.js → lib/Formatter.js} +16 -5
  21. package/dist/{Functions.d.ts → lib/Functions.d.ts} +0 -0
  22. package/dist/{Functions.js → lib/Functions.js} +1 -1
  23. package/dist/{Id.d.ts → lib/Id.d.ts} +0 -0
  24. package/dist/{Id.js → lib/Id.js} +0 -0
  25. package/dist/lib/Index.d.ts +15 -0
  26. package/dist/lib/Index.js +17 -0
  27. package/dist/{Ops.d.ts → lib/Ops.d.ts} +0 -0
  28. package/dist/{Ops.js → lib/Ops.js} +1 -1
  29. package/dist/{OrderBy.d.ts → lib/OrderBy.d.ts} +0 -0
  30. package/dist/{OrderBy.js → lib/OrderBy.js} +1 -1
  31. package/dist/{Param.d.ts → lib/Param.d.ts} +0 -0
  32. package/dist/{Param.js → lib/Param.js} +1 -1
  33. package/dist/{Query.d.ts → lib/Query.d.ts} +3 -2
  34. package/dist/{Query.js → lib/Query.js} +1 -1
  35. package/dist/{Sanitizer.d.ts → lib/Sanitizer.d.ts} +0 -0
  36. package/dist/{Sanitizer.js → lib/Sanitizer.js} +0 -0
  37. package/dist/{Schema.d.ts → lib/Schema.d.ts} +2 -7
  38. package/dist/{Schema.js → lib/Schema.js} +1 -1
  39. package/dist/{Selection.d.ts → lib/Selection.d.ts} +0 -0
  40. package/dist/{Selection.js → lib/Selection.js} +1 -1
  41. package/dist/{Statement.d.ts → lib/Statement.d.ts} +0 -0
  42. package/dist/{Statement.js → lib/Statement.js} +1 -1
  43. package/dist/{Table.d.ts → lib/Table.d.ts} +7 -11
  44. package/dist/{Table.js → lib/Table.js} +2 -3
  45. package/dist/{Target.d.ts → lib/Target.d.ts} +0 -0
  46. package/dist/{Target.js → lib/Target.js} +1 -1
  47. package/dist/{Update.d.ts → lib/Update.d.ts} +0 -0
  48. package/dist/{Update.js → lib/Update.js} +0 -0
  49. package/dist/sqlite/SqliteFormatter.d.ts +3 -3
  50. package/dist/sqlite/SqliteFormatter.js +4 -4
  51. package/dist/sqlite/SqliteFunctions.d.ts +2 -2
  52. package/dist/sqlite/SqliteFunctions.js +1 -1
  53. package/dist/sqlite/SqliteSchema.d.ts +2 -2
  54. package/dist/sqlite/SqliteSchema.js +1 -1
  55. package/package.json +1 -1
  56. package/dist/Fields.d.ts +0 -16
@@ -1,7 +1,7 @@
1
1
  import type { Database } from 'better-sqlite3';
2
- import { Driver } from '../Driver';
3
- import { SchemaInstructions } from '../Schema';
4
- import { Statement } from '../Statement';
2
+ import { Driver } from '../lib/Driver';
3
+ import { SchemaInstructions } from '../lib/Schema';
4
+ import { Statement } from '../lib/Statement';
5
5
  export declare class BetterSqlite3Driver extends Driver.Sync {
6
6
  db: Database;
7
7
  constructor(db: Database);
@@ -1,5 +1,5 @@
1
1
  // src/driver/better-sqlite3.ts
2
- import { Driver } from "../Driver.js";
2
+ import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
5
  var BetterSqlite3Driver = class extends Driver.Sync {
@@ -1,7 +1,7 @@
1
1
  import type { Database } from 'sql.js';
2
- import { Driver } from '../Driver';
3
- import { SchemaInstructions } from '../Schema';
4
- import { Statement } from '../Statement';
2
+ import { Driver } from '../lib/Driver';
3
+ import { SchemaInstructions } from '../lib/Schema';
4
+ import { Statement } from '../lib/Statement';
5
5
  export declare class SqlJsDriver extends Driver.Sync {
6
6
  db: Database;
7
7
  constructor(db: Database);
@@ -1,5 +1,5 @@
1
1
  // src/driver/sql.js.ts
2
- import { Driver } from "../Driver.js";
2
+ import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
5
  var SqlJsDriver = class extends Driver.Sync {
@@ -1,8 +1,8 @@
1
1
  import type { Database } from 'sqlite3';
2
- import { Driver } from '../Driver';
3
- import { Query } from '../Query';
4
- import { SchemaInstructions } from '../Schema';
5
- import { Statement } from '../Statement';
2
+ import { Driver } from '../lib/Driver';
3
+ import { Query } from '../lib/Query';
4
+ import { SchemaInstructions } from '../lib/Schema';
5
+ import { Statement } from '../lib/Statement';
6
6
  export declare class Sqlite3Driver extends Driver.Async {
7
7
  private db;
8
8
  lock: Promise<void> | undefined;
@@ -1,5 +1,5 @@
1
1
  // src/driver/sqlite3.ts
2
- import { Driver } from "../Driver.js";
2
+ import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
5
  var Sqlite3Driver = class extends Driver.Async {
package/dist/index.d.ts CHANGED
@@ -1,19 +1,20 @@
1
- export * from './Column';
2
- export * from './Cursor';
3
- export * from './Driver';
4
- export * from './Expr';
5
- export * from './Fields';
6
- export * from './Formatter';
7
- export * from './Functions';
8
- export * from './Id';
9
- export * from './Ops';
10
- export * from './OrderBy';
11
- export * from './Param';
12
- export * from './Query';
13
- export * from './Sanitizer';
14
- export * from './Schema';
15
- export * from './Selection';
16
- export * from './Statement';
17
- export * from './Table';
18
- export * from './Target';
19
- export * from './Update';
1
+ export * from './lib/Column';
2
+ export * from './lib/Cursor';
3
+ export * from './lib/Driver';
4
+ export * from './lib/Expr';
5
+ export * from './lib/Fields';
6
+ export * from './lib/Formatter';
7
+ export * from './lib/Functions';
8
+ export * from './lib/Id';
9
+ export * from './lib/Index';
10
+ export * from './lib/Ops';
11
+ export * from './lib/OrderBy';
12
+ export * from './lib/Param';
13
+ export * from './lib/Query';
14
+ export * from './lib/Sanitizer';
15
+ export * from './lib/Schema';
16
+ export * from './lib/Selection';
17
+ export * from './lib/Statement';
18
+ export * from './lib/Table';
19
+ export * from './lib/Target';
20
+ export * from './lib/Update';
package/dist/index.js CHANGED
@@ -1,20 +1,21 @@
1
1
  // src/index.ts
2
- export * from "./Column.js";
3
- export * from "./Cursor.js";
4
- export * from "./Driver.js";
5
- export * from "./Expr.js";
6
- export * from "./Fields.js";
7
- export * from "./Formatter.js";
8
- export * from "./Functions.js";
9
- export * from "./Id.js";
10
- export * from "./Ops.js";
11
- export * from "./OrderBy.js";
12
- export * from "./Param.js";
13
- export * from "./Query.js";
14
- export * from "./Sanitizer.js";
15
- export * from "./Schema.js";
16
- export * from "./Selection.js";
17
- export * from "./Statement.js";
18
- export * from "./Table.js";
19
- export * from "./Target.js";
20
- export * from "./Update.js";
2
+ export * from "./lib/Column.js";
3
+ export * from "./lib/Cursor.js";
4
+ export * from "./lib/Driver.js";
5
+ export * from "./lib/Expr.js";
6
+ export * from "./lib/Fields.js";
7
+ export * from "./lib/Formatter.js";
8
+ export * from "./lib/Functions.js";
9
+ export * from "./lib/Id.js";
10
+ export * from "./lib/Index.js";
11
+ export * from "./lib/Ops.js";
12
+ export * from "./lib/OrderBy.js";
13
+ export * from "./lib/Param.js";
14
+ export * from "./lib/Query.js";
15
+ export * from "./lib/Sanitizer.js";
16
+ export * from "./lib/Schema.js";
17
+ export * from "./lib/Selection.js";
18
+ export * from "./lib/Statement.js";
19
+ export * from "./lib/Table.js";
20
+ export * from "./lib/Target.js";
21
+ export * from "./lib/Update.js";
@@ -25,21 +25,24 @@ export declare class Column<T> {
25
25
  constructor(data: PartialColumnData);
26
26
  name(name: string): Column<T>;
27
27
  nullable(): Column<T | null>;
28
- autoIncrement(): Column<Column.Optional<T>>;
29
- primaryKey<K extends string>(): Column<Column.Primary<K, T>>;
28
+ autoIncrement(): Column<Column.IsOptional<T>>;
29
+ primaryKey<K extends string>(): Column<Column.IsPrimary<T, K>>;
30
30
  references(column: Expr<T>): Column<T>;
31
31
  unique(): Column<T>;
32
- defaultValue(value: T): Column<Column.Optional<T>>;
32
+ defaultValue(value: T): Column<Column.IsOptional<T>>;
33
33
  }
34
+ export type PrimaryKey<T, K> = string extends K ? T : T & {
35
+ [Column.isPrimary]: K;
36
+ };
34
37
  export declare namespace Column {
35
38
  const isOptional: unique symbol;
36
- type Optional<T> = {
39
+ type IsOptional<T> = {
37
40
  [isOptional]: true;
38
41
  __t: T;
39
42
  };
40
43
  const isPrimary: unique symbol;
41
- type Primary<Of, T> = {
42
- [isPrimary]: Of;
44
+ type IsPrimary<T, K> = {
45
+ [isPrimary]: K;
43
46
  __t: T;
44
47
  };
45
48
  }
@@ -1,4 +1,4 @@
1
- // src/Column.ts
1
+ // src/lib/Column.ts
2
2
  import { ExprData } from "./Expr.js";
3
3
  var ColumnType = /* @__PURE__ */ ((ColumnType2) => {
4
4
  ColumnType2["String"] = "String";
File without changes
@@ -1,4 +1,4 @@
1
- // src/Cursor.ts
1
+ // src/lib/Cursor.ts
2
2
  import { Expr, ExprData } from "./Expr.js";
3
3
  import { Functions } from "./Functions.js";
4
4
  import { Query } from "./Query.js";
File without changes
@@ -1,4 +1,4 @@
1
- // src/Driver.ts
1
+ // src/lib/Driver.ts
2
2
  import { Cursor } from "./Cursor.js";
3
3
  import { Query, QueryType } from "./Query.js";
4
4
  import { Schema } from "./Schema.js";
File without changes
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
 
8
- // src/Expr.ts
8
+ // src/lib/Expr.ts
9
9
  import { OrderDirection } from "./OrderBy.js";
10
10
  import { ParamData, ParamType } from "./Param.js";
11
11
  import { Target } from "./Target.js";
@@ -0,0 +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 {};
File without changes
@@ -8,6 +8,7 @@ import { Target } from './Target';
8
8
  export interface FormatContext {
9
9
  nameResult?: string;
10
10
  skipTableName?: boolean;
11
+ forceInline?: boolean;
11
12
  formatAsJson?: boolean;
12
13
  formatSubject?: (subject: Statement) => Statement;
13
14
  }
@@ -50,6 +51,6 @@ export declare abstract class Formatter implements Sanitizer {
50
51
  formatField(expr: ExprData, field: string, ctx: FormatContext): Statement;
51
52
  formatString(input: string): Statement;
52
53
  formatInlineValue(rawValue: any): Statement;
53
- formatValue(rawValue: any, formatAsJson?: boolean): Statement;
54
+ formatValue(rawValue: any, ctx: FormatContext): Statement;
54
55
  formatExpr(expr: ExprData, ctx: FormatContext): Statement;
55
56
  }
@@ -1,4 +1,4 @@
1
- // src/Formatter.ts
1
+ // src/lib/Formatter.ts
2
2
  import { ColumnType } from "./Column.js";
3
3
  import { BinOp, ExprData, ExprType, UnOp } from "./Expr.js";
4
4
  import { OrderDirection } from "./OrderBy.js";
@@ -124,7 +124,11 @@ var Formatter = class {
124
124
  return raw("create index").addIf(query.ifNotExists, "if not exists").addIdentifier(query.index.name).add("on").addIdentifier(query.table.name).parenthesis(
125
125
  separated(
126
126
  query.index.on.map(
127
- (expr) => this.formatExprValue(expr, { ...ctx, skipTableName: true })
127
+ (expr) => this.formatExprValue(expr, {
128
+ ...ctx,
129
+ skipTableName: true,
130
+ forceInline: true
131
+ })
128
132
  )
129
133
  )
130
134
  ).add(this.formatWhere(query.where, ctx));
@@ -349,7 +353,8 @@ var Formatter = class {
349
353
  return this.formatString(JSON.stringify(rawValue));
350
354
  }
351
355
  }
352
- formatValue(rawValue, formatAsJson) {
356
+ formatValue(rawValue, ctx) {
357
+ const { formatAsJson, forceInline } = ctx;
353
358
  switch (true) {
354
359
  case (rawValue === null || rawValue === void 0):
355
360
  return raw("null");
@@ -357,10 +362,16 @@ var Formatter = class {
357
362
  return rawValue ? raw("1") : raw("0");
358
363
  case Array.isArray(rawValue):
359
364
  const res = parenthesis(
360
- separated(rawValue.map((v) => this.formatValue(v, false)))
365
+ separated(
366
+ rawValue.map(
367
+ (v) => this.formatValue(v, { ...ctx, formatAsJson: false })
368
+ )
369
+ )
361
370
  );
362
371
  return formatAsJson ? raw("json_array").concat(res) : res;
363
372
  case (typeof rawValue === "string" || typeof rawValue === "number"):
373
+ if (forceInline)
374
+ return raw(this.escapeValue(rawValue));
364
375
  return value(rawValue);
365
376
  default:
366
377
  const expr = this.formatString(JSON.stringify(rawValue));
@@ -389,7 +400,7 @@ var Formatter = class {
389
400
  case ExprType.Param:
390
401
  switch (expr.param.type) {
391
402
  case ParamType.Value:
392
- return this.formatValue(expr.param.value, ctx.formatAsJson);
403
+ return this.formatValue(expr.param.value, ctx);
393
404
  case ParamType.Named:
394
405
  throw new Error("todo");
395
406
  }
File without changes
@@ -1,4 +1,4 @@
1
- // src/Functions.ts
1
+ // src/lib/Functions.ts
2
2
  import { Expr, ExprData } from "./Expr.js";
3
3
  function get(_, method) {
4
4
  return (...args) => {
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ import { Expr, ExprData } from './Expr';
2
+ interface PartialIndexData {
3
+ on: Array<ExprData>;
4
+ where?: ExprData;
5
+ }
6
+ export interface IndexData extends PartialIndexData {
7
+ name: string;
8
+ }
9
+ export declare class Index {
10
+ data: PartialIndexData;
11
+ constructor(data: PartialIndexData);
12
+ where(where: Expr<boolean>): Index;
13
+ }
14
+ export declare function index(...on: Array<Expr<any>>): Index;
15
+ export {};
@@ -0,0 +1,17 @@
1
+ // src/lib/Index.ts
2
+ import { ExprData } from "./Expr.js";
3
+ var Index = class {
4
+ constructor(data) {
5
+ this.data = data;
6
+ }
7
+ where(where) {
8
+ return new Index({ ...this.data, where: ExprData.create(where) });
9
+ }
10
+ };
11
+ function index(...on) {
12
+ return new Index({ on: on.map(ExprData.create) });
13
+ }
14
+ export {
15
+ Index,
16
+ index
17
+ };
File without changes
@@ -1,4 +1,4 @@
1
- // src/Ops.ts
1
+ // src/lib/Ops.ts
2
2
  import { Cursor } from "./Cursor.js";
3
3
  import { ExprData } from "./Expr.js";
4
4
  import { Query } from "./Query.js";
File without changes
@@ -1,4 +1,4 @@
1
- // src/OrderBy.ts
1
+ // src/lib/OrderBy.ts
2
2
  var OrderDirection = /* @__PURE__ */ ((OrderDirection2) => {
3
3
  OrderDirection2["Asc"] = "Asc";
4
4
  OrderDirection2["Desc"] = "Desc";
File without changes
@@ -1,4 +1,4 @@
1
- // src/Param.ts
1
+ // src/lib/Param.ts
2
2
  var ParamType = /* @__PURE__ */ ((ParamType2) => {
3
3
  ParamType2["Value"] = "Value";
4
4
  ParamType2["Named"] = "Named";
@@ -1,7 +1,8 @@
1
1
  import { ColumnData } from './Column';
2
2
  import { ExprData } from './Expr';
3
+ import { IndexData } from './Index';
3
4
  import { OrderBy } from './OrderBy';
4
- import { Index, Schema } from './Schema';
5
+ import { Schema } from './Schema';
5
6
  import { Target } from './Target';
6
7
  export declare enum QueryType {
7
8
  Insert = "Insert",
@@ -61,7 +62,7 @@ export declare namespace Query {
61
62
  interface CreateIndex extends QueryBase {
62
63
  type: QueryType.CreateIndex;
63
64
  table: Schema;
64
- index: Index;
65
+ index: IndexData;
65
66
  ifNotExists?: boolean;
66
67
  }
67
68
  function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
@@ -1,4 +1,4 @@
1
- // src/Query.ts
1
+ // src/lib/Query.ts
2
2
  var QueryType = /* @__PURE__ */ ((QueryType2) => {
3
3
  QueryType2["Insert"] = "Insert";
4
4
  QueryType2["Select"] = "Select";
File without changes
File without changes
@@ -1,17 +1,12 @@
1
1
  import { ColumnData } from './Column';
2
- import { ExprData } from './Expr';
3
2
  import { Formatter } from './Formatter';
3
+ import { IndexData } from './Index';
4
4
  import { Query } from './Query';
5
- export interface Index {
6
- name: string;
7
- on: Array<ExprData>;
8
- where?: ExprData;
9
- }
10
5
  export interface Schema {
11
6
  name: string;
12
7
  alias?: string;
13
8
  columns: Record<string, ColumnData>;
14
- indexes: Record<string, Index>;
9
+ indexes: Record<string, IndexData>;
15
10
  }
16
11
  export interface SchemaInstructions {
17
12
  columns: Record<string, string>;
@@ -1,4 +1,4 @@
1
- // src/Schema.ts
1
+ // src/lib/Schema.ts
2
2
  import { Query } from "./Query.js";
3
3
  var Schema;
4
4
  ((Schema2) => {
File without changes
@@ -1,4 +1,4 @@
1
- // src/Selection.ts
1
+ // src/lib/Selection.ts
2
2
  var Selection;
3
3
  ((Selection2) => {
4
4
  })(Selection || (Selection = {}));
File without changes
@@ -1,4 +1,4 @@
1
- // src/Statement.ts
1
+ // src/lib/Statement.ts
2
2
  var Token = class {
3
3
  constructor(type, data) {
4
4
  this.type = type;
@@ -1,7 +1,8 @@
1
- import { Column } from './Column';
1
+ import { Column, PrimaryKey } from './Column';
2
2
  import { Cursor } from './Cursor';
3
3
  import { Expr } from './Expr';
4
4
  import { Fields } from './Fields';
5
+ import { Index } from './Index';
5
6
  import { Schema } from './Schema';
6
7
  import { Selection } from './Selection';
7
8
  import { Update } from './Update';
@@ -22,19 +23,17 @@ export declare namespace Table {
22
23
  [P in keyof U]: U[P];
23
24
  } : never;
24
25
  type OptionalKeys<T> = {
25
- [K in keyof T]: null extends T[K] ? K : T[K] extends Column.Primary<any, any> ? K : T[K] extends Column.Optional<any> ? K : never;
26
+ [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;
26
27
  }[keyof T];
27
28
  type RequiredKeys<T> = {
28
- [K in keyof T]: null extends T[K] ? never : T[K] extends Column.Primary<any, any> ? never : T[K] extends Column.Optional<any> ? never : K;
29
+ [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;
29
30
  }[keyof T];
30
31
  type Optionals<T> = {
31
- [K in keyof T]?: T[K] extends Column.Optional<infer V> ? V : T[K];
32
+ [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];
32
33
  };
33
34
  export type Insert<T> = Intersection<Optionals<Pick<T, OptionalKeys<T>>>, Pick<T, RequiredKeys<T>>>;
34
35
  export type Normalize<T> = {
35
- [K in keyof T]: T[K] extends Column.Optional<infer V> ? V : T[K] extends Column.Primary<infer K, infer V> ? string extends K ? V : V & {
36
- [Column.isPrimary]: K;
37
- } : T[K];
36
+ [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
37
  };
39
38
  export type Infer<T> = T extends Table<infer U> ? Normalize<U> : never;
40
39
  export {};
@@ -45,10 +44,7 @@ export interface TableOptions<T> {
45
44
  columns: {
46
45
  [K in keyof T]: Column<T[K]>;
47
46
  };
48
- indexes?: (this: Fields<T>) => Record<string, {
49
- on: Array<Expr<any>>;
50
- where?: Expr<boolean>;
51
- }>;
47
+ indexes?: (this: Fields<T>) => Record<string, Index>;
52
48
  }
53
49
  export declare function table<T extends {}>(options: TableOptions<T>): Table<T> & Fields<T>;
54
50
  export declare namespace table {
@@ -1,4 +1,4 @@
1
- // src/Table.ts
1
+ // src/lib/Table.ts
2
2
  import { Cursor } from "./Cursor.js";
3
3
  import { Expr, ExprData } from "./Expr.js";
4
4
  import { Query } from "./Query.js";
@@ -92,8 +92,7 @@ function table(options) {
92
92
  indexName,
93
93
  {
94
94
  name: indexName,
95
- on: index.on.map(ExprData.create),
96
- where: index.where?.expr
95
+ ...index.data
97
96
  }
98
97
  ];
99
98
  })
File without changes
@@ -1,4 +1,4 @@
1
- // src/Target.ts
1
+ // src/lib/Target.ts
2
2
  var TargetType = /* @__PURE__ */ ((TargetType2) => {
3
3
  TargetType2["Each"] = "Each";
4
4
  TargetType2["Table"] = "Table";
File without changes
File without changes
@@ -1,6 +1,6 @@
1
- import { ExprData } from '../Expr';
2
- import { FormatContext, Formatter } from '../Formatter';
3
- import { Statement } from '../Statement';
1
+ import { ExprData } from '../lib/Expr';
2
+ import { FormatContext, Formatter } from '../lib/Formatter';
3
+ import { Statement } from '../lib/Statement';
4
4
  export declare class SqliteFormatter extends Formatter {
5
5
  escapeValue(value: any): string;
6
6
  escapeIdentifier(input: string): string;
@@ -1,8 +1,8 @@
1
1
  // src/sqlite/SqliteFormatter.ts
2
- import { ExprType } from "../Expr.js";
3
- import { Formatter } from "../Formatter.js";
4
- import { identifier } from "../Statement.js";
5
- import { TargetType } from "../Target.js";
2
+ import { ExprType } from "../lib/Expr.js";
3
+ import { Formatter } from "../lib/Formatter.js";
4
+ import { identifier } from "../lib/Statement.js";
5
+ import { TargetType } from "../lib/Target.js";
6
6
  function escapeWithin(input, outer) {
7
7
  let buf = outer;
8
8
  for (const char of input) {
@@ -1,5 +1,5 @@
1
- import { EV, Expr } from '../Expr';
2
- import { Table } from '../Table';
1
+ import { EV, Expr } from '../lib/Expr';
2
+ import { Table } from '../lib/Table';
3
3
  export declare const SqliteFunctions: SqliteFunctions;
4
4
  export type SqliteFunctions = {
5
5
  /** Use the match operator for the FTS5 module */
@@ -1,5 +1,5 @@
1
1
  // src/sqlite/SqliteFunctions.ts
2
- import { Functions } from "../Functions.js";
2
+ import { Functions } from "../lib/Functions.js";
3
3
  var SqliteFunctions = Functions;
4
4
  export {
5
5
  SqliteFunctions
@@ -1,5 +1,5 @@
1
- import { SchemaInstructions } from '../Schema';
2
- import { Statement } from '../Statement';
1
+ import { SchemaInstructions } from '../lib/Schema';
2
+ import { Statement } from '../lib/Statement';
3
3
  export declare namespace SqliteSchema {
4
4
  type Column = {
5
5
  cid: number;
@@ -1,5 +1,5 @@
1
1
  // src/sqlite/SqliteSchema.ts
2
- import { Statement, identifier, raw } from "../Statement.js";
2
+ import { Statement, identifier, raw } from "../lib/Statement.js";
3
3
  import { SqliteFormatter } from "./SqliteFormatter.js";
4
4
  var SqliteSchema;
5
5
  ((SqliteSchema2) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
package/dist/Fields.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { Column } from './Column';
2
- import { Expr } from './Expr';
3
- type GetKeys<U> = U extends Record<infer K, any> ? K : never;
4
- type UnionToIntersection<U> = {
5
- [K in GetKeys<U>]: U extends Record<K, infer T> ? T : never;
6
- };
7
- type RecordField<T> = Expr<T> & FieldsOf<UnionToIntersection<T>>;
8
- type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.Primary<infer K, infer V>] ? Expr<string extends K ? V : V & {
9
- [Column.isPrimary]: K;
10
- }> : [T] extends [Column.Optional<infer V>] ? Field<V> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
11
- type FieldsOf<Row> = Row extends Record<string, any> ? {
12
- [K in keyof Row]-?: Field<Row[K]>;
13
- } : never;
14
- type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
15
- export type Fields<T> = IsStrictlyAny<T> extends true ? any : T extends object ? FieldsOf<T> : Field<T>;
16
- export {};