Skip to content

Commit

Permalink
Update giraffeql boilerplate (backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed May 19, 2021
1 parent f5b3ae8 commit edb6ec3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions backend/functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as functions from "firebase-functions";
import * as express from "express";
import * as admin from "firebase-admin";
admin.initializeApp();

import { initializeGiraffeql } from "giraffeql";
import "./schema";
Expand Down
32 changes: 22 additions & 10 deletions backend/functions/src/schema/core/helpers/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,34 @@ function applyWhere(
break;
case "in":
if (Array.isArray(whereSubObject.value)) {
whereSubstatement += ` IN (${whereSubObject.value.map(() => "?")})`;
whereSubObject.value.forEach((ele) => {
bindings.push(ele);
});
// if array is empty, is equivalent of FALSE
if (whereSubObject.value.length < 1) {
whereSubstatement = "FALSE";
} else {
whereSubstatement += ` IN (${whereSubObject.value.map(
() => "?"
)})`;
whereSubObject.value.forEach((ele) => {
bindings.push(ele);
});
}
} else {
throw new Error("Must provide array for in/nin operators");
}
break;
case "nin":
if (Array.isArray(whereSubObject.value)) {
whereSubstatement += ` NOT IN (${whereSubObject.value.map(
() => "?"
)})`;
whereSubObject.value.forEach((ele) => {
bindings.push(ele);
});
// if array is empty, is equivalent of TRUE
if (whereSubObject.value.length < 1) {
whereSubstatement = "TRUE";
} else {
whereSubstatement += ` NOT IN (${whereSubObject.value.map(
() => "?"
)})`;
whereSubObject.value.forEach((ele) => {
bindings.push(ele);
});
}
} else {
throw new Error("Must provide array for in/nin operators");
}
Expand Down

0 comments on commit edb6ec3

Please sign in to comment.