electron-angular-sqlite-bootstrap-webpack
electron-angular-sqlite-bootstrap-webpack copied to clipboard
An Electron application using Angular 8+, Electron 6+, Sqlite3 4+, Bootstrap 4+ and WebPack 4+
Deprecated
This repo is no longer maintained and has been archived. I have created a new starter using angular-cli: https://github.com/pamtbaau/electron-angular-cli-sqlite-bootstrap.
Until a few releases ago, angular-cli could not be used in combination with custom webpack configurations. Things have changed for the good...
Sample application using Angular 8+, Electron 6+, SQLite3 4+, Bootstrap 4+ and Webpack 4+
For a similar application using Angular CLI see starter electron-angular-cli-sqlite-bootstrap
It took me quite some time to figure out how to use SQLite database in an Electron application. Because of the difficulties I've encountered, I've been using sql.js and Lovefield as alternatives.
- sql.js is SQLite compiled to javascript and therefore easy to integrated.
The disadvantage is that it loads the entire database in memory at startup and needs to be written back to disk when the app finishes. - lovefield is also build in Javascript, but stores the data in the browser's IndexedDb. It does not use SQL, but its own api.
My main issues with lovefield are that I needed more complex sql statements and needed to be able to store the database anywhere on disk.
None of the above was satisfactory, so I continued the search to bundle SQLite and finally found a way to access SQLite from Electron/node and overcome bundling issues with webpack.
This repository is a stripped down Electron application using Angular 5, SQLite, Bootstrap 4 and WebPack.
Note Since I develop solely on Windows 10, I have not tested the application on any unix version.
Prerequisites (Windows 10)
Both Visual C++ Build Tools and Python 2.7 are required for node-gyp to rebuild native SQLite library for node.
For installation instructions see node-gyp.
Quickstart
- git clone https://github.com/pamtbaau/angular7-electron3-sqlite3-bootstrap4-webpack4.git
- npm install
- npm run build:once
- npm start
- Enter new database name in file dialog.
Karma tests
- npm run test
Building installable exe
- npm run package
Notes
- Application can switch between a fixed database location or allow the end-user to select a location at first startup.
See src/app/model/Settings.hasFixedDbLocation - When allowing the user to choose location/name of database, a
settings.json(points to database location) is located inc:/users/yourname/AppData/Roaming/$productName}-dev
When running packaged executable,settings.jsonis located inc:/users/yourname/AppData/Roaming/$productName}. This way development will not override production data. - TheDb provides a Promise-ified wrapper around bare sqlite3 API.