rado 0.2.17 → 0.2.19

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/README.md CHANGED
@@ -89,7 +89,7 @@ Post().select({
89
89
  ...Post,
90
90
  author: Post.author().select(User.username),
91
91
  tags: Post.tags().select({
92
- count: pt({tagId: Tag.id}).select(count()).sure(),
92
+ count: pt({tagId: Tag.id}).select(count()).first(),
93
93
  name: Tag.name
94
94
  })
95
95
  })
@@ -112,7 +112,11 @@ Person().select({
112
112
  name: Person.firstName.concat(' ').concat(Person.lastName),
113
113
  isMario: Person.firstName.is('Mario'),
114
114
  isActor: Person.id.isIn(Actor().select(Actor.personId)),
115
- email: iif(Person.email.isNotNull(), Person.email, 'its.me@mario')
115
+ email: iif(Person.email.isNotNull(), Person.email, 'its.me@mario'),
116
+ twitterHandle: Person.socialMedia
117
+ .filter(media => media.type.is('twitter'))
118
+ .map(media => media.handle)
119
+ .maybeFirst()
116
120
  })
117
121
  ```
118
122
 
@@ -189,7 +193,7 @@ const Post = table({
189
193
  content = column.string
190
194
 
191
195
  author() {
192
- return User({id: this.userId}).sure()
196
+ return User({id: this.userId}).first()
193
197
  }
194
198
 
195
199
  tags() {
@@ -70,8 +70,8 @@ export declare namespace Cursor {
70
70
  count(): SelectSingle<number>;
71
71
  orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<Row>;
72
72
  groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<Row>;
73
- first(): SelectSingle<Row | undefined>;
74
- sure(): SelectSingle<Row>;
73
+ maybeFirst(): SelectSingle<Row | undefined>;
74
+ first(): SelectSingle<Row>;
75
75
  where(...where: Array<EV<boolean>>): SelectMultiple<Row>;
76
76
  take(limit: number | undefined): SelectMultiple<Row>;
77
77
  skip(offset: number | undefined): SelectMultiple<Row>;
@@ -195,10 +195,10 @@ function addWhere(query, where) {
195
195
  groupBy: groupBy.map(ExprData.create)
196
196
  });
197
197
  }
198
- first() {
198
+ maybeFirst() {
199
199
  return new SelectSingle({ ...this[QUERY], singleResult: true });
200
200
  }
201
- sure() {
201
+ first() {
202
202
  return new SelectSingle({
203
203
  ...this[QUERY],
204
204
  singleResult: true,
@@ -274,15 +274,13 @@ var Expr = class {
274
274
  dynamic(...path) {
275
275
  return new Proxy(
276
276
  (...args) => {
277
- const method = path.pop();
278
- const e = path.length > 0 ? this.get(path.join(".")) : this;
277
+ const method = path[path.length - 1];
278
+ const e = path.length > 1 ? this.get(path.slice(0, -1).join(".")) : this;
279
279
  return e[method]?.apply(e, args);
280
280
  },
281
281
  {
282
282
  get: (_, key) => {
283
283
  const e = path.length > 0 ? this.get(path.join(".")) : this;
284
- if (key === "expr")
285
- return e[DATA];
286
284
  if (typeof key !== "string")
287
285
  return e[key];
288
286
  return this.dynamic(...path, key);
@@ -16,7 +16,8 @@ var {
16
16
  assign,
17
17
  getPrototypeOf,
18
18
  setPrototypeOf,
19
- getOwnPropertyDescriptor
19
+ getOwnPropertyDescriptor,
20
+ getOwnPropertyNames
20
21
  } = Object;
21
22
  var { ownKeys } = Reflect;
22
23
  var Table;
@@ -66,7 +67,8 @@ function createTable(data) {
66
67
  })
67
68
  );
68
69
  const toExpr = () => new Expr(row);
69
- const ownKeys2 = ["prototype", ...cols];
70
+ const funcNames = getOwnPropertyNames(call);
71
+ const ownKeys2 = Array.from(/* @__PURE__ */ new Set([...funcNames, ...cols]));
70
72
  let res;
71
73
  if (!hasKeywords) {
72
74
  res = assign(call, expressions, { [DATA]: data, [Expr.ToExpr]: toExpr });
@@ -88,10 +90,16 @@ function createTable(data) {
88
90
  return ownKeys2;
89
91
  },
90
92
  getOwnPropertyDescriptor(target2, key) {
91
- if (key === "prototype")
92
- return getOwnPropertyDescriptor(target2, key);
93
+ const value = get2(key);
94
+ const descriptor = getOwnPropertyDescriptor(call, key);
95
+ if (descriptor)
96
+ return {
97
+ ...descriptor,
98
+ enumerable: cols.includes(key),
99
+ value
100
+ };
93
101
  return {
94
- value: get2(key),
102
+ value,
95
103
  enumerable: true,
96
104
  configurable: true
97
105
  };
@@ -27,6 +27,7 @@ interface SyncDriver {
27
27
  }
28
28
  declare abstract class SyncDriver extends DriverBase {
29
29
  transactionId: number;
30
+ constructor(formatter: Formatter);
30
31
  abstract prepareStatement(stmt: Statement, discardAfter: boolean): SyncPreparedStatement;
31
32
  abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
32
33
  prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => R;
@@ -58,6 +59,7 @@ interface AsyncDriver {
58
59
  }
59
60
  declare abstract class AsyncDriver extends DriverBase {
60
61
  transactionId: number;
62
+ constructor(formatter: Formatter);
61
63
  abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
62
64
  abstract prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
63
65
  abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
@@ -46,7 +46,7 @@ var DriverBase = class {
46
46
  get(...args) {
47
47
  const [input, ...rest] = args;
48
48
  if (input instanceof Cursor.SelectMultiple)
49
- return this.executeQuery(input.first()[Cursor.Query]);
49
+ return this.executeQuery(input.maybeFirst()[Cursor.Query]);
50
50
  if (input instanceof Cursor)
51
51
  return this.executeQuery(input[Cursor.Query]);
52
52
  return this.executeTemplate("row", input, ...rest);
@@ -59,7 +59,11 @@ var DriverBase = class {
59
59
  }
60
60
  };
61
61
  var SyncDriver = class extends DriverBase {
62
- transactionId = 0;
62
+ transactionId;
63
+ constructor(formatter) {
64
+ super(formatter);
65
+ this.transactionId = 0;
66
+ }
63
67
  prepare(create) {
64
68
  const [query, compiled] = this.compile(create);
65
69
  const prepared = this.prepareStatement(compiled, false);
@@ -165,7 +169,11 @@ var SyncDriver = class extends DriverBase {
165
169
  }
166
170
  };
167
171
  var AsyncDriver = class extends DriverBase {
168
- transactionId = 0;
172
+ transactionId;
173
+ constructor(formatter) {
174
+ super(formatter);
175
+ this.transactionId = 0;
176
+ }
169
177
  prepare(create) {
170
178
  const [query, compiled] = this.compile(create);
171
179
  const prepared = this.prepareStatement(compiled, false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "better-sqlite3": "^7.5.1",
40
40
  "bun-types": "^0.5.0",
41
41
  "cross-env": "^7.0.3",
42
- "esbuild": "^0.16.16",
42
+ "esbuild": "^0.17.7",
43
43
  "glob": "^8.0.3",
44
44
  "rimraf": "^4.1.2",
45
45
  "sade": "^1.8.1",
@@ -55,6 +55,6 @@
55
55
  },
56
56
  "packageManager": "yarn@3.3.1",
57
57
  "resolutions": {
58
- "esbuild": "0.16.16"
58
+ "esbuild": "0.17.7"
59
59
  }
60
60
  }