@saltcorn/sql 0.1.0 → 0.1.1
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/README.md +1 -1
- package/index.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,5 +10,5 @@ Use this view to create HTML code views of the results of arbitrary SQL queries
|
|
|
10
10
|
2. Set output type = Table or JSON to begin with
|
|
11
11
|
3. Start by creating your SQL query with no qualifiers (which will come from the URL query state). The preview table should update as you type
|
|
12
12
|
4. When you are happy with the SQL query, switch to output type = HTML
|
|
13
|
-
5. Create your HTML
|
|
13
|
+
5. Create your HTML code, use `{{ rows }}` to access rows. For instance if your query is an aggregation with a single row result (e.g. `SELECT COUNT(*) FROM...`), access this with `{{ rows[0].count }}`, for example `<h2>{{ rows[0].count }}</h2>`. You can also loop, e.g. `{{# for(const row of rows) { }}`
|
|
14
14
|
6. When you are happy with both you are SQL and HTML code, Think about whether you need any parameters from the state. List these comma-separated, in order and use in the SQL code as `$1`, `$2` etc. Example SQL code: `select * from _sc_config where key = $1;`
|
package/index.js
CHANGED
|
@@ -40,7 +40,7 @@ const configuration_workflow = () =>
|
|
|
40
40
|
name: "state_parameters",
|
|
41
41
|
label: "State parameters",
|
|
42
42
|
sublabel:
|
|
43
|
-
"Comma separated list of state variables from URL querystring to use as SQL query parameters",
|
|
43
|
+
"Comma separated list of state variables from URL querystring to use as SQL query parameters. User variables can be used as <code>user.id</code> etc",
|
|
44
44
|
type: "String",
|
|
45
45
|
},
|
|
46
46
|
{
|
|
@@ -79,7 +79,7 @@ const run = async (
|
|
|
79
79
|
viewname,
|
|
80
80
|
{ sql, output_type, state_parameters, html_code },
|
|
81
81
|
state,
|
|
82
|
-
|
|
82
|
+
{ req }
|
|
83
83
|
) => {
|
|
84
84
|
const is_sqlite = db.isSQLite;
|
|
85
85
|
|
|
@@ -89,7 +89,9 @@ const run = async (
|
|
|
89
89
|
.filter((s) => s)
|
|
90
90
|
.forEach((sp0) => {
|
|
91
91
|
const sp = sp0.trim();
|
|
92
|
-
if (
|
|
92
|
+
if (sp.startsWith("user.")) {
|
|
93
|
+
phValues.push(eval_expression(sp, {}, req.user));
|
|
94
|
+
} else if (typeof state[sp] === "undefined") phValues.push(null);
|
|
93
95
|
else phValues.push(state[sp]);
|
|
94
96
|
});
|
|
95
97
|
|