rado 0.1.10 → 0.1.12

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.
package/dist/Fields.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { Column } from './Column';
2
2
  import { Expr } from './Expr';
3
- type RecordField<T> = Expr<T> & FieldsOf<T>;
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>>;
4
7
  type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.Primary<infer K, infer V>] ? Expr<string extends K ? V : V & {
5
8
  [Column.isPrimary]: K;
6
9
  }> : [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>;
@@ -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
  }
package/dist/Formatter.js CHANGED
@@ -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
  }
package/dist/Table.js CHANGED
@@ -87,9 +87,14 @@ function table(options) {
87
87
  new Expr(ExprData.Row(Target.Table(schema)))
88
88
  ) : {}
89
89
  ).map(([key, index]) => {
90
+ const indexName = `${schema.name}.${key}`;
90
91
  return [
91
- key,
92
- { name: key, on: index.on.map(ExprData.create), where: index.where?.expr }
92
+ indexName,
93
+ {
94
+ name: indexName,
95
+ on: index.on.map(ExprData.create),
96
+ where: index.where?.expr
97
+ }
93
98
  ];
94
99
  })
95
100
  );
@@ -0,0 +1,2 @@
1
+ export * from './sqlite/SqliteFormatter';
2
+ export * from './sqlite/SqliteFunctions';
package/dist/sqlite.js ADDED
@@ -0,0 +1,3 @@
1
+ // src/sqlite.ts
2
+ export * from "./sqlite/SqliteFormatter.js";
3
+ export * from "./sqlite/SqliteFunctions.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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";