26
loading...
This website collects cookies to deliver better user experience
initDB()
, this function accepts a configuration object with 2 properties:string
(not required)
: the encryption key must be 32 characters longstring
(not required)
: The path to the folder where you want to store the JSON files.
const { initDB } = require('electron-data-holder');
// the encryption key must be 32 characters long.
initDB({ key: 'the-encryption-key', customPath: 'the-path-to-the-folder' });
app.getPath('userData')
.storeDB()
, this function accepts 2 parameters :object
(required)
: The data must be an object.(not required)
: accepts 2 properties :
string
: The name is a string and without the .json
part the default is data.json
.boolean
: whether you want the data to be encrypted or not, the default is false
.
const { storeDB } = require('electron-data-holder');
// This function will returns a proxy with your data in it in order to watch the changes and update the JSON file.
const data = storeDB(
{
user: {
firstName: 'Elon',
lastName: 'Mask',
},
hobbies: ['learning', 'codding'],
},
{
fileName: 'dataFile',
encryption: true,
}
);
// you can create multiple files by giving each one a different name
const config = storeDB(
{
darkMode: true,
fontSize: 16,
fontFamily: ['Courier', 'Courier', 'Everson Mono'],
},
{ fileName: 'config' }
);
const { storeDB } = require('electron-data-holder');
const data = storeDB(
{
user: {
firstName: 'Elon',
lastName: 'Mask',
},
hobbies: ['learning', 'coding'],
},
{
fileName: 'dataFile',
encryption: true,
}
);
console.log(data.hobbies[0]); // 'learning'
data.hobbies.push('gaming');
console.log(data.hobbies); // Proxy {0: "learning", 1: "coding", 2: "gaming"}
data.user.age = 47;
console.log(data.user); // Proxy {firstName: "Elon", lastName: "Mask", age: 47}
storeDB()
function returns a proxy with your data in it in order to watch the changes and update the JSON file.