How to save user data in electron.js app? - sql

I seek to save user data for my electron.js app. The app has a graph with adjustable values, which disappear when relaunching the app. Demo:
https://puu.sh/Bx5Or/ffb0382d0c.gif
How do I preserve these values? Can (and should) it be done with SQL?

You have a lot of modules to store data in an Electron app :
http://lokijs.org
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
https://github.com/agershun/alasql
https://github.com/amark/gun
https://github.com/google/leveldb
https://github.com/google/lovefield
https://github.com/jakearchibald/idb
https://github.com/jakearchibald/idb-keyval
https://github.com/sql-js/sql.js
https://github.com/localForage/localForage
https://github.com/louischatriot/nedb
https://github.com/pouchdb/pouchdb
https://github.com/pubkey/rxdb
https://github.com/typicode/lowdb
https://github.com/w3c/IndexedDB
https://github.com/yathit/ydn-db
https://github.com/TomPrograms/stormdb
I would suggest nedb which is pure JS and cross platform compatible.
The simplest is localStorage, which is browser native.
Or more simply, you can read/write data in a JSON file.
So, in your case, when the values are changed, save the data.
On start, get them from the database and put them in your adjustable values.

Related

How to dynamically load localization resource data without rebilding the application?

I'm using localization in my Blazor Server app. I need to add key, value pairs to localization resource file programmatically. I have inputs in my UI. User will able to add key, value pairs through the application UI. But after that I need that inserted data to be available with localization(After refreshing the browser) without re-building the application. Is there a way to dynamically load .resx resource file data without rebuilding the application in Blazor Server app after it get changed while running?
If I understand your request:
You can store the resource strings to database and create a Cache to store the last updated data of resources.
It's work fine if your resource less than 4MB.

How do I update persistent data after publishing the app?

As of now, my app contains an array and the user can manipulate the order of items in it by dispatching actions. I'm using redux persist and even if I directly change the array elements by editing the source file, the array does not update unless I clear the app cache.
What are my options to update this kind of persistent data after I publish it to the store without forcing users to clear the cache?
What are you looking for is migrations.
How it works:
Load user's previous state from local storage on app start
Update fields you need
Here is a setup example

How do we store variables for each user on a shopify app?

I'm building a simple app where that shows product recommendations.
I want to make it possible for the client to choose how many products he'd like to display, like from 5 or 20 with a liquid variable called {{NofProducts}}
I'm using the shopify app example, there are two important pages:
pages/index.js <- here the client can write inputs
theme-app-extension/block.liquid <- here we write a liquid code that will be appended to the page.
How do I pass the inputs from index.js to the block.liquid?
Do I have to store it elsewhere in a database for each user?
Do I have to create a file using graphQL inside each theme with the user choices using "createScriptTag"?
Ok, unfortunately every Shopify tutorial is extremely confusing for beginners.
They way you pass the store owner inputs to the app is using a database, I did it using Redis, but you can use MongoDB or maybe even a local file, but that's not ideal.
You should not store the user inputs inside their theme, because each time you access or modify a file in the customer's store, you need to use their getSessionToken function and make a new request using the token, while using your database you just need to get the session ID using SESSION_STORAGE.

load, save and reload ajax api-responses with vuex

I have a vue3-app that serves as the frontend of an asp.net core 2 api.
Much of the requested data gets used by multiple components. And in order not to make multiple identical requests, i want to store the response-data in my vuex-store if it's not in there already.
The problem is, that most of that data changes a lot, so i need to be able to tell vuex to refresh the data after some time.
But i don't want to refresh all of the requested data, since some of it doesn't need to be refreshed as often and some not at all (for example a list of countries).
So what I need is a way to tell vuex wheter i want to save the response of a specific axios request forever, or to re-request it after a set amount of time.
My questions are: Is there a plugin for this that I couldn't find? And if not, how could i implement the described functionality without rewriting it for every request?
There are some axios cache projects available:
axios-extensions (LRUCache)
axios-cache-adapter (localforage)
cachios (node-cache)
The 2 most popular currently are axios-extensions and axios-cache-adapter
Source of the chart
There is a library axios-cache-adapter that is a plugin for axios, to allow caching responses.
It is a great solution for implementing caching layer that takes care of validating cache outside of application's data storage logic and leverages it to requets library instead.
It can be used with both localstorage and indexedDB (via localforage library)

Sencha Touch LOcal Storage on Mobile Apps

I am planning to use Sencha Touch for an application of my company. I read that local storage stores data on client's browser. MY problem is when I build the code to native app using Sencha CMD how does the local storage work? What is the alternative of local storage to keep some data suppose user details (so that user doesn't need to login always).
Advance Thanks
localStorage
Is a very easy to use interface that works synchronous. It stores strings (you can JSON.stringify other Javascript objects) as key-value pairs and you just set the value with a key in this way:
localStorage.setItem('key', 'value');
To read:
var value = localStorage.getItem('key');
which returns value or null if key wasn't found in the storage.
You can use it as an object:
localStorage['key'] = 'value';
var value = localStorage['key'];
however, this is not the recommended approach. In this case undefined will be returned for non-existing items.
More details:
http://www.w3.org/TR/2013/PR-webstorage-20130409/
http://diveintohtml5.info/storage.html
IndexedDB
Database that sort of replaces the now deprecated Web SQL. It works asynchronous and is a bit harder to understand as it uses stores, requests and transactions to deal with the data.
You can store any kind of objects in IndexedDB (Javascript objects, Blobs (files)).
You can also request storage space. User will be alerted if you need more than 5 mb (5 mb is not defined, but seem to be the limit most browsers set before asking user for permission).
See here for details on how you can use it:
http://www.w3.org/TR/IndexedDB/
http://www.html5rocks.com/en/tutorials/indexeddb/todo/
Web SQL
Although, as mentioned, deprecated it is still supported in browsers such as Safari. Is a database that works with SQL-queries and request, and works asynchronous.
Here are more details:
http://www.w3.org/TR/webdatabase/
http://html5doctor.com/introducing-web-sql-databases/
File API
Currently only supported in Chrome. Is a virtual file-system that works asynchronous as IndexedDB but is intended for large files (video and audio files etc.) but can just as easily be used for storing other data.
You can store any kind of objects in File API as Blobs (files). As it is a virtual file system you can navigate using folders.
You can also request storage space here as well (quota).
For details:
http://www.html5rocks.com/en/tutorials/file/dndfiles/
http://www.w3.org/TR/FileAPI/
And of course there is cookies and for IE UserData, but these are very limited.
This example demonstrates how to use local storage with Sencha Touch model objects:
http://www.mysamplecode.com/2012/06/sencha-touch-local-storage-example.html
If you're wanting to switch & sync data from online to offline you might also be interested in this example:
https://www.robertkehoe.com/2012/11/sencha-touch-2-localstorage-example/