rado 1.0.0-preview.2 → 1.0.0-preview.3

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.
@@ -3,45 +3,38 @@ import {
3
3
  getField,
4
4
  getSql,
5
5
  hasField,
6
- hasSql,
7
6
  internalSql
8
7
  } from "./Internal.js";
9
8
  import { sql } from "./Sql.js";
10
9
  import { virtual } from "./Virtual.js";
11
- var Selection = class {
12
- #input;
13
- #nullable;
14
- constructor(input, nullable) {
15
- this.#input = input;
16
- this.#nullable = nullable;
10
+ var SqlColumn = class {
11
+ constructor(sql2, targetName) {
12
+ this.sql = sql2;
13
+ this.targetName = targetName;
17
14
  }
18
- makeVirtual(name) {
19
- return virtual(name, this.#input);
15
+ result(ctx) {
16
+ const value = ctx.values[ctx.index++];
17
+ if (value === null)
18
+ return value;
19
+ return this.sql.mapFromDriverValue?.(value) ?? value;
20
20
  }
21
- mapRow = (values) => {
22
- return this.#mapResult(this.#input, values);
23
- };
24
- get [internalSql]() {
25
- return this.#selectionToSql(this.#input, /* @__PURE__ */ new Set());
21
+ };
22
+ var ObjectColumn = class {
23
+ constructor(nullable, entries) {
24
+ this.nullable = nullable;
25
+ this.entries = entries;
26
26
  }
27
- #mapResult(input, values) {
28
- const expr = this.#exprOf(input);
29
- if (expr) {
30
- const value = values.shift();
31
- if (value !== null && expr.mapFromDriverValue)
32
- return expr.mapFromDriverValue(value);
33
- return value;
34
- }
27
+ result(ctx) {
35
28
  const result = {};
36
- let isNullable = this.#nullable.size > 0;
37
- for (const name in input) {
38
- const expr2 = input[name];
39
- const value = this.#mapResult(expr2, values);
29
+ let isNullable = this.nullable.size > 0;
30
+ for (const entry of this.entries) {
31
+ const name = entry[0];
32
+ const col = entry[1];
33
+ const value = col.result(ctx);
40
34
  result[name] = value;
41
35
  if (isNullable) {
42
36
  if (value === null) {
43
- const field = getField(expr2);
44
- if (field && !this.#nullable.has(field.targetName))
37
+ if (col.targetName && !this.nullable.has(col.targetName))
45
38
  isNullable = false;
46
39
  } else {
47
40
  isNullable = false;
@@ -52,8 +45,37 @@ var Selection = class {
52
45
  return null;
53
46
  return result;
54
47
  }
48
+ };
49
+ var Selection = class {
50
+ #input;
51
+ #root;
52
+ constructor(input, nullable) {
53
+ this.#input = input;
54
+ this.#root = this.#defineColumn(nullable, input);
55
+ }
56
+ makeVirtual(name) {
57
+ return virtual(name, this.#input);
58
+ }
59
+ #defineColumn(nullable, input) {
60
+ const expr = getSql(input);
61
+ if (expr)
62
+ return new SqlColumn(expr, getField(input)?.targetName);
63
+ return new ObjectColumn(
64
+ nullable,
65
+ Object.entries(input).map(([name, value]) => [
66
+ name,
67
+ this.#defineColumn(nullable, value)
68
+ ])
69
+ );
70
+ }
71
+ mapRow = (values) => {
72
+ return this.#root.result({ values, index: 0 });
73
+ };
74
+ get [internalSql]() {
75
+ return this.#selectionToSql(this.#input, /* @__PURE__ */ new Set());
76
+ }
55
77
  #selectionToSql(input, names, name) {
56
- const expr = this.#exprOf(input);
78
+ const expr = getSql(input);
57
79
  if (expr) {
58
80
  let exprName = name ?? expr.alias;
59
81
  if (exprName) {
@@ -76,9 +98,6 @@ var Selection = class {
76
98
  sql`, `
77
99
  );
78
100
  }
79
- #exprOf(input) {
80
- return hasSql(input) ? getSql(input) : void 0;
81
- }
82
101
  };
83
102
  function selection(input, nullable = /* @__PURE__ */ new Set()) {
84
103
  return new Selection(input, nullable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "1.0.0-preview.2",
3
+ "version": "1.0.0-preview.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {