mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-01-25 22:20:58 +00:00
增加测试用例
This commit is contained in:
parent
9ba15a92ed
commit
f54a618f0d
63
demo/test.js
63
demo/test.js
@ -1,26 +1,51 @@
|
||||
|
||||
const fs = require('fs')
|
||||
|
||||
const invodb = require('..')
|
||||
|
||||
invodb.database('zzz.invodb')
|
||||
invodb.database('hr.invodb')
|
||||
|
||||
let col = invodb.collection('blog')
|
||||
if(!col.exist()) col.create();
|
||||
let person = invodb.collection('persons')
|
||||
if(!person.exist()) person.create();
|
||||
|
||||
for(let json of col.query({})) col.remove(json)
|
||||
person.insert({
|
||||
name: "张三",
|
||||
age: 22,
|
||||
salary: 3000,
|
||||
kpi: 0.6
|
||||
})
|
||||
|
||||
let list = fs.readFileSync(__dirname + "/list.txt").toString().split("\n")
|
||||
for(let json of list) {
|
||||
col.insert(JSON.parse(json))
|
||||
}
|
||||
person.insert({
|
||||
name: "李四",
|
||||
age: 35,
|
||||
salary: 6000,
|
||||
kpi: 0.8
|
||||
})
|
||||
|
||||
let result = col.query(
|
||||
{
|
||||
"title": {
|
||||
"$gte": "数据库设计(1)",
|
||||
"$lte": "数据库设计(5)",
|
||||
person.insert({
|
||||
name: "王五",
|
||||
age: 37,
|
||||
salary: 20000,
|
||||
kpi: 0.95
|
||||
})
|
||||
|
||||
person.insert({
|
||||
name: "李雷",
|
||||
age: 32,
|
||||
salary: 15000,
|
||||
kpi: 0.35
|
||||
})
|
||||
|
||||
|
||||
console.log("优化互联网人力资源结构专项名单:")
|
||||
let hr = person.query({
|
||||
$or: [
|
||||
{
|
||||
age: { $gte: 35 },
|
||||
salary: { $lt: 10000 }
|
||||
},
|
||||
{
|
||||
kpi: { $lt: 0.4 },
|
||||
salary: { $gte: 10000 }
|
||||
}
|
||||
}
|
||||
)
|
||||
console.log(result)
|
||||
]
|
||||
})
|
||||
console.log(hr)
|
||||
|
||||
|
47
demo/test2.js
Normal file
47
demo/test2.js
Normal file
@ -0,0 +1,47 @@
|
||||
const invodb = require('..')
|
||||
|
||||
invodb.database('db.invodb')
|
||||
|
||||
let person = invodb.collection('persons')
|
||||
if(!person.exist()) person.create();
|
||||
|
||||
person.insert({
|
||||
name: "张三",
|
||||
age: 19,
|
||||
courses: ["数据库", "计组", "编译原理", "操作系统"]
|
||||
})
|
||||
|
||||
person.insert({
|
||||
name: "李四",
|
||||
age: 18,
|
||||
courses: ["数据库", "线代", "数学分析", "操作系统", "数电"]
|
||||
})
|
||||
|
||||
person.insert({
|
||||
name: "王五",
|
||||
age: 21,
|
||||
courses: ["数据库", "嵌入式", "微机", "计网", "STP"]
|
||||
})
|
||||
|
||||
person.insert({
|
||||
name: "李雷",
|
||||
age: 22,
|
||||
courses: ["吃", "喝", "玩", "乐"]
|
||||
})
|
||||
|
||||
|
||||
console.log("看看谁学习 数据库 和 操作系统:")
|
||||
let good = person.query({
|
||||
courses: ["数据库", "操作系统"]
|
||||
})
|
||||
console.log(good)
|
||||
|
||||
|
||||
console.log("看看谁姓李:")
|
||||
let li = person.query({
|
||||
name: {
|
||||
$gte: "李",
|
||||
$lt: "杏"
|
||||
}
|
||||
})
|
||||
console.log(li)
|
3
index.js
3
index.js
@ -31,7 +31,8 @@ function collection(collectionName) {
|
||||
create: create,
|
||||
insert: insert,
|
||||
remove: remove,
|
||||
query: query
|
||||
query: query,
|
||||
update: insert
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,14 +160,14 @@ std::set<nlohmann::json> Collection::queryRange(const std::string &prefix, nlohm
|
||||
else set = tmp, init = true;
|
||||
}
|
||||
|
||||
printf(">> %d queryRange prefix: %s query: %s\n", init, prefix.c_str(), json.dump().c_str());
|
||||
//printf(">> %d queryRange prefix: %s query: %s\n", init, prefix.c_str(), json.dump().c_str());
|
||||
|
||||
if(!init) set = queryAllByField(prefix);
|
||||
|
||||
printf("result: \n");
|
||||
for(auto it=set.begin(); it!=set.end(); it++) {
|
||||
printf(" - %s\n", it->dump().c_str());
|
||||
}
|
||||
// printf("result: \n");
|
||||
// for(auto it=set.begin(); it!=set.end(); it++) {
|
||||
// printf(" - %s\n", it->dump().c_str());
|
||||
// }
|
||||
|
||||
if(json.contains("$ne")) {
|
||||
if(json["$ne"].is_null()) {
|
||||
@ -312,11 +312,11 @@ std::set<nlohmann::json> Collection::innerQuery(const std::string &prefix, const
|
||||
}
|
||||
|
||||
auto str = json.dump();
|
||||
printf("query: %s prefix: %s\n", str.c_str(), prefix.c_str());
|
||||
printf("result: \n");
|
||||
for(auto it=res.begin(); it!=res.end(); it++) {
|
||||
printf(" - %s\n", it->dump().c_str());
|
||||
}
|
||||
// printf("query: %s prefix: %s\n", str.c_str(), prefix.c_str());
|
||||
// printf("result: \n");
|
||||
// for(auto it=res.begin(); it!=res.end(); it++) {
|
||||
// printf(" - %s\n", it->dump().c_str());
|
||||
// }
|
||||
|
||||
if (init) return queryAllByField(prefix == "" ? prefix : prefix.substr(0, prefix.size()-1));
|
||||
|
||||
@ -484,7 +484,7 @@ std::set<nlohmann::json>
|
||||
Collection::queryNumber(const std::string &prefix, const double &minValue, const double &maxValue, const int &mod) {
|
||||
std::set<nlohmann::json> res;
|
||||
auto treeName = prefix + "$number";
|
||||
printf(">>>> %s %f %f %d\n", prefix.c_str(), minValue, maxValue, mod);
|
||||
//printf(">>>> %s %f %f %d\n", prefix.c_str(), minValue, maxValue, mod);
|
||||
|
||||
if(!index->exists(treeName)) {
|
||||
return res;
|
||||
|
Loading…
x
Reference in New Issue
Block a user