sql-typechecker 0.0.38 → 0.0.44
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 +14 -11
- package/out/cli.js.map +3 -3
- package/package.json +2 -2
package/out/cli.js
CHANGED
|
@@ -6387,7 +6387,7 @@ var require_nearley = __commonJS((exports2, module2) => {
|
|
|
6387
6387
|
});
|
|
6388
6388
|
});
|
|
6389
6389
|
|
|
6390
|
-
// node_modules/pgsql-ast-parser/lib/index.js
|
|
6390
|
+
// node_modules/trader-pgsql-ast-parser/lib/index.js
|
|
6391
6391
|
var require_lib = __commonJS((exports2) => {
|
|
6392
6392
|
(function(e, a) {
|
|
6393
6393
|
for (var i in a)
|
|
@@ -235932,13 +235932,13 @@ ${text}`;
|
|
|
235932
235932
|
var fs = __toModule(require("fs/promises"));
|
|
235933
235933
|
var import_lodash2 = __toModule(require_lodash());
|
|
235934
235934
|
var path = __toModule(require("path"));
|
|
235935
|
-
var
|
|
235935
|
+
var import_trader_pgsql_ast_parser2 = __toModule(require_lib());
|
|
235936
235936
|
var prettier = __toModule(require_prettier());
|
|
235937
235937
|
|
|
235938
235938
|
// src/typecheck.ts
|
|
235939
235939
|
var import_assert = __toModule(require("assert"));
|
|
235940
235940
|
var import_lodash = __toModule(require_lodash());
|
|
235941
|
-
var
|
|
235941
|
+
var import_trader_pgsql_ast_parser = __toModule(require_lib());
|
|
235942
235942
|
|
|
235943
235943
|
// src/normalize.ts
|
|
235944
235944
|
function normalizeTypeName(s) {
|
|
@@ -242341,7 +242341,7 @@ function doCreateFunction(g, c, s) {
|
|
|
242341
242341
|
froms: c.froms,
|
|
242342
242342
|
decls: c.decls.concat(inputs)
|
|
242343
242343
|
};
|
|
242344
|
-
const body =
|
|
242344
|
+
const body = import_trader_pgsql_ast_parser.parse(s.code, {locationTracking: true});
|
|
242345
242345
|
if (body.length === 0) {
|
|
242346
242346
|
return {
|
|
242347
242347
|
name,
|
|
@@ -242545,7 +242545,7 @@ var KindMismatch = class extends ErrorWithLocation {
|
|
|
242545
242545
|
constructor(e, type, errormsg) {
|
|
242546
242546
|
super(e._location, `
|
|
242547
242547
|
KindMismatch:
|
|
242548
|
-
${
|
|
242548
|
+
${import_trader_pgsql_ast_parser.toSql.expr(e)}
|
|
242549
242549
|
|
|
242550
242550
|
${errormsg}}
|
|
242551
242551
|
|
|
@@ -242558,7 +242558,7 @@ var DuplicateFieldNames = class extends ErrorWithLocation {
|
|
|
242558
242558
|
constructor(e, name) {
|
|
242559
242559
|
super(e._location, `Duplicate column names: expression:
|
|
242560
242560
|
|
|
242561
|
-
${
|
|
242561
|
+
${import_trader_pgsql_ast_parser.toSql.expr(e)}
|
|
242562
242562
|
|
|
242563
242563
|
has field name
|
|
242564
242564
|
|
|
@@ -242573,7 +242573,7 @@ var TypeMismatch = class extends ErrorWithLocation {
|
|
|
242573
242573
|
constructor(e, ts, mess) {
|
|
242574
242574
|
super(e._location, `
|
|
242575
242575
|
TypeMismatch:
|
|
242576
|
-
${
|
|
242576
|
+
${import_trader_pgsql_ast_parser.toSql.expr(e)}
|
|
242577
242577
|
|
|
242578
242578
|
${mess ? mess : ""}
|
|
242579
242579
|
|
|
@@ -242598,7 +242598,7 @@ to
|
|
|
242598
242598
|
${JSON.stringify(ts.to)}}
|
|
242599
242599
|
|
|
242600
242600
|
in expr:
|
|
242601
|
-
${
|
|
242601
|
+
${import_trader_pgsql_ast_parser.toSql.expr(e)}
|
|
242602
242602
|
`);
|
|
242603
242603
|
this.from = ts.from;
|
|
242604
242604
|
this.to = ts.to;
|
|
@@ -243490,12 +243490,15 @@ import type { Pool } from "pg";
|
|
|
243490
243490
|
import { Instant, LocalDate, LocalTime, LocalDateTime} from "@js-joda/core";
|
|
243491
243491
|
`;
|
|
243492
243492
|
}
|
|
243493
|
+
function genSelectColumnsFromTable(t) {
|
|
243494
|
+
return t.fields.map((f) => f.name?.name || "?").join(", ");
|
|
243495
|
+
}
|
|
243493
243496
|
function genCrudOperations(table) {
|
|
243494
243497
|
const selectAll = `
|
|
243495
243498
|
export async function getAll(pool: Pool): Promise<${showTypeAsTypescriptType(table.rel)}[]>{
|
|
243496
243499
|
|
|
243497
243500
|
const res = await pool.query({
|
|
243498
|
-
text: "SELECT
|
|
243501
|
+
text: "SELECT ${genSelectColumnsFromTable(table.rel)} FROM ${showQName(table.name)}",
|
|
243499
243502
|
values: [],
|
|
243500
243503
|
rowMode: "array",
|
|
243501
243504
|
});
|
|
@@ -243541,7 +243544,7 @@ export async function insert(pool: Pool, row: {${inputRow}}): Promise<{${primary
|
|
|
243541
243544
|
export async function getOne(pool: Pool, pk: {${primaryKeySingleCol.name.name}: ${showTypeAsTypescriptType(primaryKeySingleCol.type)}}): Promise<${showTypeAsTypescriptType(table.rel)} | null>{
|
|
243542
243545
|
|
|
243543
243546
|
const res = await pool.query({
|
|
243544
|
-
text: "SELECT
|
|
243547
|
+
text: "SELECT ${genSelectColumnsFromTable(table.rel)} FROM ${showQName(table.name)} WHERE ${primaryKeySingleCol.name.name} = $1",
|
|
243545
243548
|
values: [pk.${primaryKeySingleCol.name.name}] as any[],
|
|
243546
243549
|
rowMode: "array",
|
|
243547
243550
|
});
|
|
@@ -243625,7 +243628,7 @@ async function go() {
|
|
|
243625
243628
|
for (let sqlFile of allSqlFiles) {
|
|
243626
243629
|
console.log(`Processing file ${sqlFile}`);
|
|
243627
243630
|
const fileContents = await fs.readFile(sqlFile, "utf-8");
|
|
243628
|
-
const statements =
|
|
243631
|
+
const statements = import_trader_pgsql_ast_parser2.parse(fileContents, {
|
|
243629
243632
|
locationTracking: true
|
|
243630
243633
|
});
|
|
243631
243634
|
allStatements.push({fileName: sqlFile, statements});
|