Skip to content

Commit 6bf678e

Browse files
feat(chart): add support for context variables inside SQL query (#1028)
1 parent 4ea1576 commit 6bf678e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@babel/runtime": "7.15.4",
2929
"bluebird": "2.9.25",
3030
"core-js": "3.6.5",
31-
"forest-express": "10.0.0-beta.3",
31+
"forest-express": "10.0.0",
3232
"http-errors": "1.6.1",
3333
"lodash": "4.17.21",
3434
"moment": "2.29.4",

src/services/query-stat-getter.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11

22
function QueryStatGetter(params, opts) {
3-
const QUERY_OPTIONS_SELECT = { type: opts.Sequelize.QueryTypes.SELECT };
4-
53
this.perform = function perform() {
64
let rawQuery = params.query.trim();
5+
const bind = params.contextVariables || {};
76

8-
9-
if (params.record_id) {
10-
rawQuery = rawQuery.replace(new RegExp('\\?', 'g'), params.record_id);
7+
if (bind.recordId && !rawQuery.includes('$recordId')) {
8+
rawQuery = rawQuery.replace(/\?/g, '$recordId');
119
}
1210

1311
// WARNING: Choosing the first connection might generate issues if the model
1412
// does not belongs to this database.
15-
return Object.values(opts.connections)[0].query(rawQuery, QUERY_OPTIONS_SELECT);
13+
return Object.values(opts.connections)[0].query(rawQuery, {
14+
type: opts.Sequelize.QueryTypes.SELECT,
15+
bind,
16+
});
1617
};
1718
}
1819

yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,10 @@
11991199
resolved "https://registry.yarnpkg.com/@forestadmin/context/-/context-1.31.0.tgz#b4b5a3b589e52d337a1f45807db22c2860e640a7"
12001200
integrity sha512-RQkDBkq+6ySMv+YNezz9VWSyCsqD7fj/+bXrXhQ6lJ62nbRUIUheH7ApvXwfnwFR1u55oT6Yhar11t6DaiE9Ig==
12011201

1202-
"@forestadmin/[email protected]-alpha.3":
1203-
version "1.0.0-alpha.3"
1204-
resolved "https://registry.yarnpkg.com/@forestadmin/forestadmin-client/-/forestadmin-client-1.0.0-alpha.3.tgz#1dfb5beba8a201d36d218ca804f8af3e47307691"
1205-
integrity sha512-aEcIgwGRVDJbMzkI2Io3bpQqDEHp039r2jlOs5aFjvpycAc+Y2NYwBmUbepBy2L89lQ3Cw732hDsah9AvlUM/A==
1202+
"@forestadmin/[email protected]":
1203+
version "1.0.0"
1204+
resolved "https://registry.yarnpkg.com/@forestadmin/forestadmin-client/-/forestadmin-client-1.0.0.tgz#37a452b290187e415633c9ca4494a3a81457434a"
1205+
integrity sha512-o2F5ChAQ2NJbk8PrYdc7hzo04nmZwvHv/axaBASvvoer5HDMoSaQ3GZjqfw1kkdalfRDq9HnNps4Zm+8T0qUUg==
12061206
dependencies:
12071207
jsonwebtoken "^8.5.1"
12081208
lru-cache "^7.3.1"
@@ -4599,14 +4599,14 @@ for-in@^1.0.2:
45994599
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
46004600
integrity sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=
46014601

4602-
4603-
version "10.0.0-beta.3"
4604-
resolved "https://registry.yarnpkg.com/forest-express/-/forest-express-10.0.0-beta.3.tgz#3873934dd8acf06003c18ce4f01ba5da61b2596f"
4605-
integrity sha512-IJsVd4YsARTs6ix+/apHDBXUMcB5R9Sq1am8i/rI2Qi/zii2Z6JrTtHfkeNadNQXU4TZVOrXvIvPHuiMkpVLWQ==
4602+
4603+
version "10.0.0"
4604+
resolved "https://registry.yarnpkg.com/forest-express/-/forest-express-10.0.0.tgz#10f76f9617739340ffa0b3fabaddf5998d3482bd"
4605+
integrity sha512-qtrs988yfyW23Od6OSnwxGstRhVWgOO5Z6edJ42IiU4dUvrGHq8o9NbZpSd9kfv7JROzURews6gsoAvJ8IInnA==
46064606
dependencies:
46074607
"@babel/runtime" "7.19.0"
46084608
"@forestadmin/context" "1.31.0"
4609-
"@forestadmin/forestadmin-client" "1.0.0-alpha.3"
4609+
"@forestadmin/forestadmin-client" "1.0.0"
46104610
base32-encode "1.1.1"
46114611
bitwise-xor "0.0.0"
46124612
bluebird "3.7.1"

0 commit comments

Comments
 (0)