Skip to content

Commit 7ff905d

Browse files
authored
Sqlite Node - docs update (#869)
* Update README.md 1. Updated node readme to match node's html help. 2. Added Example clarifying the use of parameters in a msg.topic query.
1 parent f9b4d2e commit 7ff905d

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

storage/sqlite/README.md

+35-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,46 @@ Run the following command in your Node-RED user directory - typically `~/.node-r
2121
Usage
2222
-----
2323

24-
Allows basic access to a Sqlite database.
24+
Allows access to a SQLite database.
2525

26-
This node uses the **db.all** operation against the configured database.
27-
This does allow INSERTS, UPDATES and DELETES.
26+
SQL Query sets how the query is passed to the node.
2827

29-
By it's very nature it is SQL injection... so *be careful* out there...
28+
SQL Query Via msg.topic and Fixed Statement uses the db.all operation against the configured database.
29+
This does allow INSERTS, UPDATES and DELETES. By its very nature it is SQL injection... so be careful out there...
3030

31-
`msg.topic` must hold the *query* for the database, and the result is returned in `msg.payload`.
31+
SQL Type Prepared Statement also uses db.all but sanitizes parameters passed, eliminating the possibility of SQL injection.
32+
33+
SQL Type Batch without response uses db.exec which runs all SQL statements in the provided string. No result rows are returned.
34+
35+
When using Via msg.topic or Batch without response msg.topic must hold the query for the database.
36+
37+
When using Via msg.topic, parameters can be passed in the query using a msg.payload array. Ex:
38+
39+
```
40+
msg.topic = `INSERT INTO user_table (name, surname) VALUES ($name, $surname)`
41+
msg.payload = ["John", "Smith"]
42+
return msg;
43+
```
44+
45+
When using Normal or Prepared Statement, the query must be entered in the node config.
46+
47+
Pass in the parameters as an object in msg.params for Prepared Statement. Ex:
48+
```
49+
msg.params = {
50+
$id:1,
51+
$name:"John Doe"
52+
}
53+
```
54+
Parameter object names must match parameters set up in the Prepared Statement. If you get the error SQLITE_RANGE: bind or column index out of range be sure to include $ on the parameter object key.
55+
The SQL query for the example above could be: insert into user_table (user_id, user) VALUES ($id, $name);
56+
57+
Using any SQL Query, the result is returned in msg.payload
3258

3359
Typically the returned payload will be an array of the result rows, (or an error).
3460

35-
You can load sqlite extensions by inputting a `msg.extension` property containing the full path and filename.
61+
You can load SQLite extensions by inputting a msg.extension property containing the full path and filename.
62+
63+
The reconnect timeout in milliseconds can be changed by adding a line to `settings.js`
3664

37-
The reconnect timeout in milliseconds can be changed by adding a line to **settings.js**
65+
`sqliteReconnectTime: 20000,`
3866

39-
sqliteReconnectTime: 20000,

storage/sqlite/locales/en-US/sqlite.html

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<p>SQL Type <i>Prepared Statement</i> also uses <b>db.all</b> but sanitizes parameters passed, eliminating the possibility of SQL injection.</p>
77
<p>SQL Type <i>Batch without response</i> uses <b>db.exec</b> which runs all SQL statements in the provided string. No result rows are returned.</p>
88
<p>When using <i>Via msg.topic</i> or <i>Batch without response</i> <code>msg.topic</code> must hold the <i>query</i> for the database.</p>
9+
<p>When using <i>Via msg.topic</i>, parameters can be passed in the query using a <code>msg.payload</code> array. Ex:<br />
10+
<code>msg.topic = `INSERT INTO user_table (name, surname) VALUES ($name, $surname)`<br />
11+
msg.payload = ["John", "Smith"]<br />
12+
return msg;</code><br />
913
<p>When using Normal or Prepared Statement, the <i>query</i> must be entered in the node config.</p>
1014
<p>Pass in the parameters as an object in <code>msg.params</code> for Prepared Statement. Ex:<br />
1115
<code>msg.params = {<br />

0 commit comments

Comments
 (0)