saveData
Save data in the database
To save data you need the server object from getLocalServer, a schema and the data you want to save.
Firstly create the schema:
Create new folder named 'Schemas'. You can use any name you want.
Create new file named 'example.js' in the new folder. You can use any name you want.
Paste the schema code inside (below this list)
const schema = {
name: String,
lastname: String,
age: Number,
};
const props = {
name: 'example', // Schema Name
schema: schema // Schema Object
};
module.exports = props;
Now you created your own schema. You can now import the schema and save the data.
const { LocalServer, getLocalServer, saveData } = require('naturesaving');
const ExampleSchema = require('path-to-schema') // The path to your schema
const server = new LocalServer({ name: 'Example', path: './database' });
const localServer = getLocalServer({ name: 'Example' });
const data = {
name: 'Max',
lastname: 'Mustermann',
age: 50
};
saveData({ server: localServer, schema: ExampleSchema, data: data }); // Save the data
Last updated