Skip to content

Commit

Permalink
feat: allow nullable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Forrester committed Dec 24, 2019
1 parent 7029261 commit 4f35342
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"ajv": "^6.10.2",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"esqlate-lib": "^1.0.6",
"esqlate-lib": "^1.0.8",
"esqlate-promise-returning-function-to-generator": "^1.0.0",
"esqlate-queue": "^2.0.0",
"express": "^4.17.1",
Expand Down
9 changes: 8 additions & 1 deletion src/QueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export function pgQuery(statement: EsqlateStatementNormalized, inputValues: {[k:
knownValues: string[];
}

function getSqlValue(p: EsqlateParameter) {
if (p.empty_string_is_null && (inputValues[p.name] == "")) {
return null;
}
return inputValues[p.name];
}

function reducer(acc: PgQueryExtra, ed: string | EsqlateParameter): PgQueryExtra {

if (typeof ed === "string") {
Expand All @@ -75,7 +82,7 @@ export function pgQuery(statement: EsqlateStatementNormalized, inputValues: {[k:
}

if (acc.knownValues.indexOf(ed.name) === -1) {
acc.values = acc.values.concat(inputValues[ed.name]);
acc.values = acc.values.concat(getSqlValue(ed));
acc.knownValues = acc.knownValues.concat([ed.name]);
}

Expand Down

0 comments on commit 4f35342

Please sign in to comment.