Do reconnect node-red-node-sqlite by event

Hallo,
when I connect to a sqlite-database and I want to change the databasefile (same filename), I can not reconnect to the new file content. Is there a way to reconnect without restart nodered?

Thank You

Welcome to the forum @buschhardtt

Can you explain what you mean by "change the databasefile (same filename)"?
Are you actually replacing the db file while Node-red is connected to it?

Will it reconnect if you do a full redeploy?

Hello jbudd,

I use the calibre database (sqlite: metadata.db). After I synchronize calibre files, I want to reconnect the database-connection to use the new datas.
The correct way would be: close db-connection, synchronize, connect db-connection
But I dont find close and connect/reconnect

Yes after a full redeploy the db is reconnected.

Bye

I tried closing the db connection using node-red-node-sqlite but could not make it work.

Your best approach might be to access the database via an external program such as Python.

The sqlite library for python 3 does have access to database connect and close.

You could start the python process via Node-red's daemon node, which allows you to pass data backwards and forwards.

Why don’t you just use two SQLite nodes? You could add the name of the db to the msg as msg.database. That will indicate which node to go to, so you add a switch node look at the msg.database and use that to route the msg to the correct SQLite node.

Calibre is mainly written in Python. It keeps an in-memory cache of the db when it is running so it isn't really safe to do anything with the db while Calibre is running. However, they do provide an API. Details here:

https://manual.calibre-ebook.com/develop.html

Better still though would be to run the calibre-server and access the data using the REST API.

Oh, and I didn't realise that there is a 3rd method. It provides a command-line tool calibredb.

Thank you for the tip about calibredb. Here's a simple workflow using calibredb for anyone interested in this topic.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.