What is arousa-table?
arousa-table is a library that allows you to manipulate data in an easy and structured way by storing the data in tables.The library is a project made for learning so there will be many things that can be improved. More functions will be added in the future such as being able to connect them to databases in mongoDB and SQL. If you find any error or want to expose an idea you can do it in our Discord
DEPENDENCIES
Basics
const { Schema, Table } = require('arousa-table');
const schema = new Schema({
name: {
overwritable: true,
unique: false,
searcheable: true,
required: true,
type: 'String'
},
age: {
overwritable: true,
unique: false,
searcheable: false,
required: true,
type: 'Number'
}
});
const table = new Table(schema);
table.create_document({
name: 'Pepe',
age: 28
});
Data types
Types |
|
String |
'Pepe' |
Number |
28 |
Array |
['Pepe', 28] |
Object |
{ name: 'Pepe', age: 28 } |
Boolean |
true/false |
any |
Any type of data (String, Object, Number...) |
Options
Options |
|
overwritable |
If it's false you won't be able to overwrite this keys values. |
unique |
If it's true, the value can not be repeated in other documents. |
searcheable |
If it's true, the document can be found with the get() and fetch() methods. |
required |
If it's true, the value must be provided when creating the document and it cannot have a null or undefined value |
type |
Indicates the data type that the key will store |
Get documents by searcheable keys
Get one document
Input
let dmt = table.get('Pepe');
Output
arousa_document{
table: [circular*],
name: 'Pepe',
age: 28
}
Get many documents
Input
let dmts = table.fetch('Pepe');
Output
[
arousa_table{
table: [circular*1],
name: 'Pepe',
age: 28
}
]
Find documents
Find one document
Input
let dmt = table.find({ name: 'Pepe' });
Output
arousa_document{
table: [circular*1],
name: 'Pepe',
age: 28
}
Find many documents
Input
let dmts = table.find_many({ age: 28 });
Output
[
arousa_document{
table: [circular*1],
name: 'Pepe',
age: 28
}
]
Delete documents
let dmt = table.get('Pepe');
dmt.delete();
Find and delete documents
table.find_and_delete({ name: 'Pepe' });
It also works with multiple documents at the same time
table.find_many_and_delete({ name: 'Pepe' });
Udpdate documents
dmt.insert({ name: 'Luis' });
You can find and update documents with just one function
table.find_and_insert({ name: 'Pepe' }, { name: 'Luis' });
It also works with multiple documents at the same time
table.find_many_and_insert({ name: 'Pepe' }, { name: 'Luis' });
Check if a documents exists
Input
let exists = table.exists({ name: 'Pepe' });
output
true
You can save table's schema and data in a JSON file
table.toJSON('./path/to/', 'table.json');
To load data you can do this
const table = new Table();
table.fromJSON('./path/to/table.json');