sql-typechecker 0.0.24 → 0.0.27

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/out/cli.js CHANGED
@@ -242309,7 +242309,7 @@ function doCreateFunction(g, c, s) {
242309
242309
  type: "null"
242310
242310
  };
242311
242311
  if (returnType.kind === "void") {
242312
- if (!s.returns) {
242312
+ if (!s.returns || s.returns.type.kind === void 0 && s.returns.type.name === "void") {
242313
242313
  return {kind: "void"};
242314
242314
  } else if (s.returns.type.kind === "table") {
242315
242315
  throw new Error("RETURNS TABLE is not supported yet");
@@ -242905,7 +242905,7 @@ function elabCall(g, c, e) {
242905
242905
  return unifyOverloadedCall(e, argTypes, allNumericBuiltinTypes.map((t) => ({expectedArgs: [t], returnT: t})));
242906
242906
  }
242907
242907
  if (eqQNames(e.function, {name: "count"})) {
242908
- return unifyCallGeneral(e, argTypes, [BuiltinTypes.AnyScalar], BuiltinTypes.Boolean);
242908
+ return unifyCallGeneral(e, argTypes, [BuiltinTypes.AnyScalar], BuiltinTypes.Bigint);
242909
242909
  }
242910
242910
  if (eqQNames(e.function, {name: "coalesce"}) || eqQNames(e.function, {name: "nullif"})) {
242911
242911
  if (e.args.length === 0) {
@@ -243302,7 +243302,7 @@ return ${genDeserializeSimpleT(returnType, "cells[0]")};
243302
243302
  }
243303
243303
  }
243304
243304
  function functionToTypescript(f) {
243305
- const returnTypeAsString = f.returns.kind === "void" ? "void" : showTypeAsTypescriptType(f.returns) + (f.multipleRows ? "[]" : " | undefined");
243305
+ const returnTypeAsString = f.returns.kind === "void" ? "void" : showTypeAsTypescriptType(f.returns) + (f.multipleRows ? "[]" : " | null");
243306
243306
  const argsType = "{" + f.inputs.map((k) => {
243307
243307
  const paramTypeAsString = showTypeAsTypescriptType(k.type);
243308
243308
  return k.name.name + ": " + paramTypeAsString;
@@ -243335,7 +243335,7 @@ const row = res.rows[0];
243335
243335
  if (row.some(f => f !== null)){
243336
243336
  return ${genDeserialization(f.returns, "row")}
243337
243337
  } else {
243338
- return undefined;
243338
+ return null;
243339
243339
  }`;
243340
243340
  return `
243341
243341
  export async function ${f.name.name}(pool: Pool, args: ${argsType})
@@ -243405,6 +243405,20 @@ export async function insert(pool: Pool, row: {${inputRow}}): Promise<{${primary
243405
243405
  } else {
243406
243406
  return null;
243407
243407
  }
243408
+ }`;
243409
+ const selectOne = `
243410
+ export async function getOne(pool: Pool, pk: {${primaryKeySingleCol.name.name}: ${showTypeAsTypescriptType(primaryKeySingleCol.type)}}): Promise<${showTypeAsTypescriptType(table.rel)} | null>{
243411
+
243412
+ const res = await pool.query({
243413
+ text: "SELECT * FROM ${showQName(table.name)} WHERE ${primaryKeySingleCol.name.name} = $1",
243414
+ values: [pk.${primaryKeySingleCol.name.name}] as any[],
243415
+ rowMode: "array",
243416
+ });
243417
+ if (res.rows[0]){
243418
+ return ${genDeserialization(table.rel, "res.rows[0]")};
243419
+ } else {
243420
+ return null;
243421
+ }
243408
243422
  }`;
243409
243423
  const inputRowForUpdate = relWithoutPrim.map((f) => `
243410
243424
  ${f.name?.name}?: ${showTypeAsTypescriptType(f.type)}`).join(",");
@@ -243433,6 +243447,7 @@ return null;
243433
243447
  }`;
243434
243448
  return `
243435
243449
  ${selectAll}
243450
+ ${selectOne}
243436
243451
  ${insert}
243437
243452
  ${update}
243438
243453
  ${del}