string
string The string to check
Returns boolean Return wether the string is valid JSON
obj
Object The Object to check
Returns boolean Return wether the string is valid DBON
Creates a valid mode 1 database for Databasetify
name
string Name you want to give to the databasepath
string 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
path
string Path of the json file to databasetify.mode
number 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.
name
string Name of the table.columns
Array<column> Array of columns. Check the right structure in the documentation.
Adds a value to an existent table.
tableName
string Name of the table where you want to insert valueskey
string Name of the key.value
Object<string, any> Object of values, with columns' names as keys
Set a different value given the table, the key and the column names.
tableName
string Name of the table where you want to insert valueskey
string Name of the key to modifycolumn
string Name of the columnvalue
any 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
tableName
string Table of the value you want to getkey
string Key of the value you want to getcolumn
string 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
tableName
string Name of the table where you want to searchfinder
finder 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
tableName
string Name of the table where you want to searchfinder
finder 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.