diff --git a/.gitignore b/.gitignore index 387fbac..ab376d6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ package-lock.json .vscode node_modules build -yarn.lock \ No newline at end of file +yarn.lock +.DS_Store diff --git a/demo/test.js b/demo/test.js index a0ca08c..6f9bc68 100644 --- a/demo/test.js +++ b/demo/test.js @@ -8,22 +8,15 @@ invodb.database('zzz.invodb') let col = invodb.colection('blog') if(!col.exist()) col.create(); -for(let json of col.query({})) col.remove(json) +// for(let json of col.query({})) col.remove(json) -let list = fs.readFileSync(__dirname + "/list.txt").toString().split("\n") -for(let json of list) { - col.insert(JSON.parse(json)) -} +// let list = fs.readFileSync(__dirname + "/list.txt").toString().split("\n") +// for(let json of list) { +// col.insert(JSON.parse(json)) +// } let result = col.query({ - id: { - $gte: 1, - $lte: 8, - $or: [ - { $ne: 2 }, - { $ne: 3 } - ] - } + __INVO_ID__: 'oev3yzmydgdvtxg82zbzmrl6gbu73ax7' }) console.log(">>>>>>>>>>>>>>>>>>>>") diff --git a/docs/invodb使用文档.md b/docs/invodb使用文档.md new file mode 100644 index 0000000..dd08c1d --- /dev/null +++ b/docs/invodb使用文档.md @@ -0,0 +1,32 @@ +# 简明 invoDB 使用教程 + + +## 前置知识 + +### 什么是 JSON 格式 + +是一种轻量级资料交换格式,其内容由属性和值所组成。 + +`json` 可以同样被看作 `JavaScript` 对象的一个子集。 + +#### 一个典型的 JSON 对象 + +```json +{ + "id": 7, + "title": "这是一篇文章", + "content": "这是文章内容", + "author": "YuhangQ", + "category": "数据库", + "tags": ["数据库", "C++", "数据结构"], + "parameters": { + "hidden": true, + "like": 25565, + }, + "comment": [ + {"username": "YuhangQ", "content": "文章写的真不错!"}, + {"username": "TechCiel", "content": "能提供下打赏渠道吗?"}, + ] +} +``` + diff --git a/package.json b/package.json index e2b4114..21897a8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "clear && node-gyp build && node demo/test.js", - "install": "node-gyp rebuild" + "install": "node-gyp rebuild", + "build": "node-gyp build" }, "repository": { "type": "git", diff --git a/src/collection/query.cpp b/src/collection/query.cpp index 02a9631..c61d231 100644 --- a/src/collection/query.cpp +++ b/src/collection/query.cpp @@ -228,7 +228,13 @@ std::set Collection::innerQuery(const std::string &prefix, const std::set tmp; std::string tPrefix = prefix + key; - if(key == "$or") { + if(key == "__INVO_ID__") { + int add = uuid->find(value); + if(add != -1) { + tmp.insert(PageManager::readJSONFromFile(add)); + } + } + else if(key == "$or") { nlohmann::json line = json[key].get(); for(auto& obj : line) { tmp = setUnion(tmp, innerQuery(prefix, obj.get())); diff --git a/src/test/test.h b/src/test/test.h index 987b47f..6a0f725 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -8,6 +8,14 @@ Collection *col; void terminal() { + + PageManager::loadDatabase("test.invodb"); + Collection::loadCollections(); + + if (!Collection::existsCollection("test")) + Collection::createCollection("test"); + col = &Collection::getCollection("test"); + printf("--------INVODB TERMINAL--------\n"); printf("insert\t\tinsert a one line json to database.\n"); printf("query\t\tquery all jsons satisfying the query json.\n");