1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/storage/sqlite
Dave Conway-Jones 8e2f8b60e0
bump sqlite3 libs and package
to include css bugfix
2023-09-16 19:16:35 +01:00
..
ext sqlite - add test extension - half.c 2018-08-23 08:55:51 +01:00
icons Realign sqlite files to be similar to other nodes 2014-07-25 10:10:06 +01:00
locales Sqlite Node - docs update (#869) 2022-01-05 16:20:06 +00:00
LICENSE Update licenses and packages for all nodes 2016-11-06 20:26:19 +00:00
package.json bump sqlite3 libs and package 2023-09-16 19:16:35 +01:00
README.md Sqlite Node - docs update (#869) 2022-01-05 16:20:06 +00:00
sqlite.html Fix height of description editor in sqlite node (#1030) 2023-09-16 19:12:20 +01:00
sqlite.js Sqlite3 fix (#872) 2022-01-05 11:43:16 +00:00

node-red-node-sqlite

A Node-Red node to read and write a local sqlite database.

Install

Run the following command in your Node-RED user directory - typically ~/.node-red

npm i --unsafe-perm node-red-node-sqlite

Notes:

  • Version 1.x requires nodejs v12 or greater.

  • The install process requires a compile of native code. This can take 15-20 minutes on devices like a Raspberry Pi - please be prepared to wait a long time. Also if node.js is upgraded at any point you will need to rebuild the native part manually, for example.

    cd ~/.node-red npm rebuild

Usage

Allows access to a SQLite database.

SQL Query sets how the query is passed to the node.

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

SQL Type Prepared Statement also uses db.all but sanitizes parameters passed, eliminating the possibility of SQL injection.

SQL Type Batch without response uses db.exec which runs all SQL statements in the provided string. No result rows are returned.

When using Via msg.topic or Batch without response msg.topic must hold the query for the database.

When using Via msg.topic, parameters can be passed in the query using a msg.payload array. Ex:

msg.topic = `INSERT INTO user_table (name, surname) VALUES ($name, $surname)`
msg.payload = ["John", "Smith"]
return msg;

When using Normal or Prepared Statement, the query must be entered in the node config.

Pass in the parameters as an object in msg.params for Prepared Statement. Ex:

msg.params = {
    $id:1,
    $name:"John Doe"
}

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. The SQL query for the example above could be: insert into user_table (user_id, user) VALUES ($id, $name);

Using any SQL Query, the result is returned in msg.payload

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

You can load SQLite extensions by inputting a msg.extension property containing the full path and filename.

The reconnect timeout in milliseconds can be changed by adding a line to settings.js

sqliteReconnectTime: 20000,