![]() run a query const result = await to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW) ![]() ![]() In the JavaScript code of your main process you can now create a database: const sqlite3 = require( 'sqlite3') Ĭonst db = new sqlite3.Database( '/path/to/database/file.db') ĭb.run( "CREATE TABLE Users (name, lastName)") ĭb.run( "INSERT INTO Users VALUES (?, ?)", ) Īlso you have to set up the ipcRenderer so that message from the renderer process are handled: ipcMain.handle( 'db-query', async (event, sqlQuery) => ) node_modules/.bin/electron-rebuild -f -w sqlite3 Install them with npm install sqlite3 you can rebuild SQLite with. Also you need the package to rebuild the SQLite module against the currently installed Electron version. To install SQLite, use the SQLite3 package which is a native Node.js module. So you start up SQLite in your main process and whenever you want to read or write data, you send the SQL queries to the main process and retrieve the result back as JSON data. To communicate data operations between your main and your renderer processes, you have to use either (not recommended) or the ipcRenderer (recommended). Using SQLite in Electron is not possible in the renderer process, only in the main process. Operations are written in the SQL query language similar to the PostgreSQL syntax. SQLite is a SQL based relational database written in the C programming language that was crafted to be embed inside of applications and stores data locally. Using the Web Storage APIs is generally only recommend when you know for sure that there will be always only one rendering process and performance is not that relevant. Localstorage and WebSQL are even slower by the way. Storing and querying much data might become your performance bottleneck. IndexedDB is slow mostly because it has to go through layers of browser security and abstractions. Each browser tab could modify the database state while the others do not know of the changes and keep an outdated UI.Īnother thing is performance. If you have more then one renderer process, it becomes hard to manage database writes between them. This is easy to setup and storing small sets of data can be achieved in a short span of time.īut as soon as your application goes beyond a simple TODO-app, there are multiple obstacles that come in your way. Localstorage/IndexedDB/WebSQLīecause Electron uses a common Chrome web browser in the renderer process, you can access the common Web Storage APIs like Localstorage, IndexedDB and WebSQL. Instead you should use a database that can be bundled and run inside of Electron, either in the main or in the renderer process. In practice this is not a viable way to go because shipping the correct binaries and opening ports is way to complicated and troublesome. In theory you could ship the correct database server binaries with your electron application and start a process on the clients device which exposes a port to the database that can be consumed by Electron. Server Side Databasesīecause Electron runs on a desktop computer, you might think that it should be possible to use a common "server" database like MySQL, PostgreSQL or MongoDB. This is important to understand because choosing the right database depends on your use case and on which of these JavaScript runtimes you want to keep the data. Each renderer process represents one "browser tab". One or multiple "renderer" processes that consist of a Chrome browser engine and runs the user interface.The "main" process which is a Node.js JavaScript process that runs without a UI in the background.NOTICE: You are reading this inside of the RxDB documentation, so everything might be opinionated.Īn Electron runtime can be divided in two parts: This allows to create so called offline first apps that even work when to user has no internet connection. Electron (aka Electron.js) is a framework developed by github which is designed to create desktop applications with the Web technology stack consisting of HTML, CSS and JavaScript.īecause the desktop application runs on the clients device, it is suitable to use a database that can store and query data locally.
0 Comments
Leave a Reply. |