rado 0.1.26 → 0.1.28

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.
@@ -61,6 +61,7 @@ export declare namespace Cursor {
61
61
  orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<T>;
62
62
  groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<T>;
63
63
  first(): SelectSingle<T | undefined>;
64
+ sure(): SelectSingle<T>;
64
65
  where(...where: Array<EV<boolean>>): SelectMultiple<T>;
65
66
  toExpr(): Expr<T>;
66
67
  }
@@ -153,6 +153,13 @@ var Cursor = class {
153
153
  first() {
154
154
  return new SelectSingle({ ...this.query(), singleResult: true });
155
155
  }
156
+ sure() {
157
+ return new SelectSingle({
158
+ ...this.query(),
159
+ singleResult: true,
160
+ validate: true
161
+ });
162
+ }
156
163
  where(...where) {
157
164
  return new SelectMultiple(super.where(...where).query());
158
165
  }
@@ -113,8 +113,12 @@ var SyncDriver = class extends DriverBase {
113
113
  params = params || compiled.params();
114
114
  if ("selection" in query) {
115
115
  const res = stmt.all(params).map((row) => JSON.parse(row.result).result);
116
- if (query.singleResult)
117
- return res[0];
116
+ if (query.singleResult) {
117
+ const row = res[0];
118
+ if (query.validate && !row)
119
+ throw new Error("No row found");
120
+ return row;
121
+ }
118
122
  return res;
119
123
  } else if (query.type === QueryType.Raw) {
120
124
  switch (query.expectedReturn) {
@@ -208,8 +212,12 @@ var AsyncDriver = class extends DriverBase {
208
212
  const res = (await stmt.all(params)).map(
209
213
  (item) => JSON.parse(item.result).result
210
214
  );
211
- if (query.singleResult)
212
- return res[0];
215
+ if (query.singleResult) {
216
+ const row = res[0];
217
+ if (query.validate && !row)
218
+ throw new Error("No row found");
219
+ return row;
220
+ }
213
221
  return res;
214
222
  } else if (query.type === QueryType.Raw) {
215
223
  switch (query.expectedReturn) {
@@ -29,6 +29,7 @@ export declare namespace Query {
29
29
  having?: ExprData;
30
30
  selection?: ExprData;
31
31
  singleResult?: boolean;
32
+ validate?: boolean;
32
33
  }
33
34
  interface Insert extends QueryBase {
34
35
  type: QueryType.Insert;
@@ -53,9 +53,10 @@ export declare class Statement {
53
53
  compile(sanitizer: Sanitizer, formatInline?: boolean): CompiledStatement;
54
54
  }
55
55
  export declare class CompiledStatement {
56
+ sanitizer: Sanitizer;
56
57
  sql: string;
57
58
  private paramData;
58
- constructor(sql: string, paramData: Array<ParamData>);
59
+ constructor(sanitizer: Sanitizer, sql: string, paramData: Array<ParamData>);
59
60
  params(input?: Record<string, any>): Array<any>;
60
61
  toString(): string;
61
62
  }
@@ -148,9 +148,7 @@ var Statement = class {
148
148
  sql += sanitizer.escapeValue(token.data);
149
149
  } else {
150
150
  sql += "?";
151
- paramData.push(
152
- ParamData.Value(sanitizer.formatParamValue(token.data))
153
- );
151
+ paramData.push(ParamData.Value(token.data));
154
152
  }
155
153
  break;
156
154
  case "Param" /* Param */:
@@ -165,11 +163,12 @@ var Statement = class {
165
163
  break;
166
164
  }
167
165
  }
168
- return new CompiledStatement(sql, paramData);
166
+ return new CompiledStatement(sanitizer, sql, paramData);
169
167
  }
170
168
  };
171
169
  var CompiledStatement = class {
172
- constructor(sql, paramData) {
170
+ constructor(sanitizer, sql, paramData) {
171
+ this.sanitizer = sanitizer;
173
172
  this.sql = sql;
174
173
  this.paramData = paramData;
175
174
  }
@@ -177,10 +176,10 @@ var CompiledStatement = class {
177
176
  return this.paramData.map((param2) => {
178
177
  if (param2.type === ParamType.Named) {
179
178
  if (input && param2.name in input)
180
- return input[param2.name];
179
+ return this.sanitizer.formatParamValue(input[param2.name]);
181
180
  throw new TypeError(`Missing parameter ${param2.name}`);
182
181
  }
183
- return param2.value;
182
+ return this.sanitizer.formatParamValue(param2.value);
184
183
  });
185
184
  }
186
185
  toString() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {