diff --git a/invodb/main.cpp b/invodb/main.cpp index 64a7bd3..3740796 100644 --- a/invodb/main.cpp +++ b/invodb/main.cpp @@ -13,7 +13,7 @@ int main() { srand(t); printf("seed: %d\n", t); - //system("rm -rf test.invodb && touch test.invodb"); + system("rm -rf test.invodb && touch test.invodb"); PageManager::loadDatabase("test.invodb"); @@ -29,24 +29,31 @@ int main() { col = &Collection::getCollection("hello"); } - testAndBenchmark(10000); + //testAndBenchmark(10000); -// nlohmann::json j = nlohmann::json::parse(R"( -//{ -// "string": "this is a string!", -// "double": 3.1415, -// "int": 25565, -// "bool": true, -// "child": { -// "id": 3 -// }, -// "array": ["1", "2", "3"] -// )"); -// -// col->insert(j); -// -// col->remove(j); + nlohmann::json j = nlohmann::json::parse(R"( +{ + "string": "this is a string!", + "double": 3.1415, + "int": 25565, + "bool": true, + "child": { + "id": 3 + }, + "array": ["1", "2", "3"] + )"); + + + try { + col->insert(j); + }catch(const char * s ){ + puts(s); + } + + printf("?"); + + col->remove(j); return 0; } diff --git a/invodb/models/collection.cpp b/invodb/models/collection.cpp index 27673cf..9b0cafe 100644 --- a/invodb/models/collection.cpp +++ b/invodb/models/collection.cpp @@ -77,6 +77,8 @@ Collection::Collection(const std::string &name, const int &firstPage) { } void Collection::insert(nlohmann::json &json) { + + if(json["__INVO_ID__"].empty()) { json["__INVO_ID__"] = generateUUID(); } else {