mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-26 06:30:57 +00:00
sync
This commit is contained in:
parent
56075f3a15
commit
0c05c4424c
@ -11,4 +11,4 @@ include_directories(./invodb)
|
||||
|
||||
add_executable(InvoDB
|
||||
invodb/main.cpp
|
||||
invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h invodb/btree/node.h invodb/btree/btree.h invodb/index/index.cpp invodb/index/index.h invodb/btree/list.h)
|
||||
invodb/main.h invodb/file/page_manager.cpp invodb/file/page_manager.h invodb/models/collection.cpp invodb/models/collection.h invodb/file/storage_page.cpp invodb/file/storage_page.h invodb/utils/logger.h invodb/utils/uuid.h invodb/btree/node.h invodb/btree/btree.h invodb/index/index.cpp invodb/index/index.h invodb/btree/list.h invodb/index/query.cpp invodb/index/query.h)
|
||||
|
9
invodb/index/query.cpp
Normal file
9
invodb/index/query.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by projector-user on 11/1/21.
|
||||
//
|
||||
|
||||
#include "query.h"
|
||||
|
||||
std::vector<nlohmann::json> Query::find(const nlohmann::json &json) {
|
||||
return std::vector<nlohmann::json>();
|
||||
}
|
16
invodb/index/query.h
Normal file
16
invodb/index/query.h
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by projector-user on 11/1/21.
|
||||
//
|
||||
|
||||
#ifndef INVODB_QUERY_H
|
||||
#define INVODB_QUERY_H
|
||||
|
||||
#include "json/json.hpp"
|
||||
|
||||
class Query {
|
||||
std::vector<nlohmann::json> find(const nlohmann::json &json);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif //INVODB_QUERY_H
|
@ -29,26 +29,24 @@ int main() {
|
||||
col = &Collection::getCollection("hello");
|
||||
}
|
||||
|
||||
std::string test;
|
||||
for(int i=0; i<100; i++) {
|
||||
test += generateUUID();
|
||||
}
|
||||
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"]
|
||||
}
|
||||
)");
|
||||
testAndBenchmark(10000);
|
||||
|
||||
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"]
|
||||
// )");
|
||||
//
|
||||
// col->insert(j);
|
||||
//
|
||||
// col->remove(j);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ Collection &Collection::getCollection(const std::string &name) {
|
||||
Collection::Collection(const std::string &name, const int &firstPage) {
|
||||
Logger::info<std::string, std::string>("load Collection: ", name);
|
||||
index = new BTree<std::string, 128>(firstPage);
|
||||
|
||||
|
||||
if(!index->exists("__INVO_ID__")) {
|
||||
index->insert("__INVO_ID__", PageManager::Instance().allocate());
|
||||
}
|
||||
@ -80,6 +82,9 @@ void Collection::insert(nlohmann::json &json) {
|
||||
} else {
|
||||
remove(json);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string id = json["__INVO_ID__"].get<std::string>();
|
||||
int add = PageManager::Instance().saveJSONToFile(json);
|
||||
uuid->insert(id, add);
|
||||
@ -94,9 +99,10 @@ void Collection::remove(const nlohmann::json &json) {
|
||||
throw "no invo_id";
|
||||
}
|
||||
std::string id = json["__INVO_ID__"].get<std::string>();
|
||||
uuid->remove(id);
|
||||
|
||||
|
||||
int address = uuid->find(id);
|
||||
uuid->remove(id);
|
||||
|
||||
nlohmann::json jsonInDisk = PageManager::Instance().readJSONFromFile(address);
|
||||
|
||||
@ -105,6 +111,7 @@ void Collection::remove(const nlohmann::json &json) {
|
||||
PageManager::Instance().release(address);
|
||||
}
|
||||
|
||||
// age=1 age=“hello”
|
||||
void Collection::indexJSON(const std::string prefix, const nlohmann::json &json, const int& address) {
|
||||
// even easier with structured bindings (C++17)
|
||||
for (auto& [key, value] : json.items()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user