可索引 invo_id

This commit is contained in:
YuhangQ 2021-11-22 14:34:31 +08:00
parent a7f8ee9951
commit 7b550e4a71
6 changed files with 57 additions and 16 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ package-lock.json
.vscode
node_modules
build
yarn.lock
yarn.lock
.DS_Store

View File

@ -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(">>>>>>>>>>>>>>>>>>>>")

View File

@ -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": "能提供下打赏渠道吗?"},
]
}
```

View File

@ -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",

View File

@ -228,7 +228,13 @@ std::set<nlohmann::json> Collection::innerQuery(const std::string &prefix, const
std::set<nlohmann::json> 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<nlohmann::json>();
for(auto& obj : line) {
tmp = setUnion(tmp, innerQuery(prefix, obj.get<nlohmann::json>()));

View File

@ -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<JSON>\tinsert a one line json to database.\n");
printf("query\t<JSON>\tquery all jsons satisfying the query json.\n");