|
|
|
|
|
## Datastore
|
|
## Datastore
|
|
|
|
|
|
The purpose of the Datastore is to contain an array of table of data but you can store anything you want.
|
|
The purpose of the Datastore is to contain an array of table of data but you can store anything you want.
|
... | @@ -37,3 +38,77 @@ query.skip(1).limit(4).launch([&] (laldb::Datastore::Error err, laldb::DataRepre |
... | @@ -37,3 +38,77 @@ query.skip(1).limit(4).launch([&] (laldb::Datastore::Error err, laldb::DataRepre |
|
});
|
|
});
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## insert
|
|
|
|
|
|
|
|
You can insert an <b>object</b> or an <b>array</b> (insert many objects at the same time).
|
|
|
|
The callback's arguments :
|
|
|
|
- err : true if the insert failed
|
|
|
|
- doc : it's an error message if <i>err</i> is true or it's the inserted object.
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
ds.insert(laldb::makeObject{
|
|
|
|
{ "name", "Clement" },
|
|
|
|
{ "lastName", "A" },
|
|
|
|
{ "age", 16 }}, [&] (laldb::Datastore::Error err, laldb::DataRepresentation doc) {
|
|
|
|
if (err) {
|
|
|
|
/* return or throw */
|
|
|
|
}
|
|
|
|
/* doc is the object inserted */
|
|
|
|
});
|
|
|
|
|
|
|
|
ds.insert(laldb::makeArray{
|
|
|
|
laldb::makeObject{ { "name", "Clement" }, { "lastName", "A" }, { "age", 16 } },
|
|
|
|
laldb::makeObject { { "name", "Paul" }, { "lastName", "A" }, { "age", 32 } },
|
|
|
|
}, [&] (laldb::Datastore::Error err, laldb::DataRepresentation doc) {
|
|
|
|
if (err) {
|
|
|
|
std::cerr << doc.value<laldb::String>() << std::endl;
|
|
|
|
/* return or throw */
|
|
|
|
}
|
|
|
|
/* doc is the array inserted */
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## find
|
|
|
|
|
|
|
|
You can find objects in your Datastore with a matching patern.
|
|
|
|
The callback's arguments :
|
|
|
|
- err : boolean
|
|
|
|
- docs : it's an error message if <i>err</i> is true or it's the inserted object.
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
ds.find(laldb::makeObject { { "name", "paul" } },
|
|
|
|
[&] (laldb::Datastore::Error err, laldb::DataRepresentation docs) {
|
|
|
|
if (err) {
|
|
|
|
std::cerr << doc.value<laldb::String>() << std::endl;
|
|
|
|
/* return or throw */
|
|
|
|
}
|
|
|
|
/* docs is an array with all object which have a field "name" equal to "paul" */
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## findOne
|
|
|
|
|
|
|
|
|
|
|
|
You can find objects in your Datastore with a matching patern.
|
|
|
|
The callback's arguments :
|
|
|
|
- err : boolean
|
|
|
|
- docs : it's an error message if <i>err</i> is true or it's the inserted object.
|
|
|
|
<b>/!\ if the findOne match with nothing, the callback isn't called.</b>
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
ds.findOne(laldb::makeObject { { "name", "paul" } },
|
|
|
|
[&] (laldb::Datastore::Error err, laldb::DataRepresentation doc) {
|
|
|
|
if (err) {
|
|
|
|
std::cerr << doc.value<laldb::String>() << std::endl;
|
|
|
|
/* return or throw */
|
|
|
|
}
|
|
|
|
/* doc is the first object to match */
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
## update |