stringstring The string to check
Returns boolean Return wether the string is valid JSON
objObject The Object to check
Returns boolean Return wether the string is valid DBON
Creates a valid mode 1 database for Databasetify
namestring Name you want to give to the databasepathstring Path of the JSON file for the database
Main databasetify class. Opens a file as a database, performs operations on it adding or deleting elements and finding for data
pathstring Path of the json file to databasetify.modenumber 0 or 1. 0 opens the file in simple mode, 1 opens the file in strict mode.
Adds a table to the currently open database.
namestring Name of the table.columnsArray<column> Array of columns. Check the right structure in the documentation.
Adds a value to an existent table.
tableNamestring Name of the table where you want to insert valueskeystring Name of the key.valueObject<string, any> Object of values, with columns' names as keys
Set a different value given the table, the key and the column names.
tableNamestring Name of the table where you want to insert valueskeystring Name of the key to modifycolumnstring Name of the columnvalueany Value to set at given table, key and column
Removes the specified key in the specified table
Get a value from the database, given the table name, the key and the column
tableNamestring Table of the value you want to getkeystring Key of the value you want to getcolumnstring Column of the value you want to get
Returns any? Value at specified Table, Key and Column, if it exists. If not, returns null
Returns the first element that makes the finder function true
tableNamestring Name of the table where you want to searchfinderfinder The function to filter all the values
Returns foundValue Object with the value, the key, the column and the counter relatives to the value
Returns all the elements that makes the finder function true
tableNamestring Name of the table where you want to searchfinderfinder The function to filter all the values
Returns Array<foundValue> Array of Objects with the value, the key, the column and the counter relatives to the value
Mode 0
A simple, empty JSON file is valid for mode 0. Every table is a key in the JSON root and its value is an object. For each key of the table, there is a corresponding object, with as keys the columns of the tables and as values the corresponding values. It does not check for eventual errors, it just works.
{
"table1": {
"key1": {
"col1": "value1",
"col2": "value2",
"col3": "value3"
},
"key2": {
"col2": "value2",
"col4": "value3"
}
}
}Mode 1
For mode 1, you need a Databasetify structured object. This is the structure:
{
"name": "databaseName",
"tableCount": 1,
"tables": [
{
"name": "tableName",
"cols": ["col1", "col2"]
"numOfCols": 2,
"keys": ["key1", "key2"],
"numOfKeys": 2,
"values" [
["value1", "value2"],
["value1", "value2"]
]
"isRelational": false,
"relations": [
null,
null
]
}
]
}It may seem very complex, but you can create an empty mode 1 database writing:
{
"name": "databaseName",
"tableCount: 0,
"tables": []
}Or simply using the function newDatabase (for this, you can use the Node console)
const databasetify = require("databasetify");
databasetify.newDatabase("name", "path/to/db.json");This mode checks for eventual structure errors.