mirror of
https://github.com/YuhangQ/InvoDB.git
synced 2025-04-20 04:33:10 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
dd90616a66 | |||
f49837dbfa | |||
516fb18c82 | |||
801c9c510b |
@ -1,7 +1,7 @@
|
|||||||
include_directories(./src)
|
include_directories(./src)
|
||||||
|
|
||||||
project (invodb)
|
project (invodb)
|
||||||
cmake_minimum_required(VERSION 3.15)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
|
Binary file not shown.
@ -3,7 +3,6 @@ const { execSync } = require("child_process")
|
|||||||
|
|
||||||
execSync("rm -rf benchmark.invodb")
|
execSync("rm -rf benchmark.invodb")
|
||||||
|
|
||||||
|
|
||||||
let time = 0
|
let time = 0
|
||||||
function clock() {
|
function clock() {
|
||||||
let last = time
|
let last = time
|
||||||
|
130004
benchmark/test.log
130004
benchmark/test.log
File diff suppressed because it is too large
Load Diff
270004
benchmark/test2.log
270004
benchmark/test2.log
File diff suppressed because it is too large
Load Diff
27
docs/test.js
Normal file
27
docs/test.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
const invodb = require('..')
|
||||||
|
|
||||||
|
invodb.database('test.invodb')
|
||||||
|
|
||||||
|
let col = invodb.collection('blog')
|
||||||
|
if(!col.exist()) col.create();
|
||||||
|
|
||||||
|
col.insert({
|
||||||
|
"id": 7,
|
||||||
|
"title": "这是一篇文章",
|
||||||
|
"content": "这是文章内容",
|
||||||
|
"author": "YuhangQ",
|
||||||
|
"category": "数据库",
|
||||||
|
"original-url": null,
|
||||||
|
"tags": ["数据库", "C++", "数据结构"],
|
||||||
|
"parameters": {
|
||||||
|
"hidden": true,
|
||||||
|
"like": 25565,
|
||||||
|
},
|
||||||
|
"comment": [
|
||||||
|
{"username": "YuhangQ", "content": "文章写的真不错!"},
|
||||||
|
{"username": "TechCiel", "content": "能提供下打赏渠道吗?"},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
let result = col.query({})
|
||||||
|
console.log(result)
|
10
index.js
10
index.js
@ -17,7 +17,7 @@ function collection(collectionName) {
|
|||||||
let json = JSON.stringify(object);
|
let json = JSON.stringify(object);
|
||||||
core.remove(collectionName, json);
|
core.remove(collectionName, json);
|
||||||
}
|
}
|
||||||
function query(object) {
|
function find(object) {
|
||||||
if(!core.exists(collectionName)) throw `Collection ${collectionName} doesn't exists!`;
|
if(!core.exists(collectionName)) throw `Collection ${collectionName} doesn't exists!`;
|
||||||
let json = JSON.stringify(object);
|
let json = JSON.stringify(object);
|
||||||
let res = [];
|
let res = [];
|
||||||
@ -26,12 +26,18 @@ function collection(collectionName) {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
function findOne(object) {
|
||||||
|
let res = find(object);
|
||||||
|
if(res.length >= 1) return res[0];
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
exist: exist,
|
exist: exist,
|
||||||
create: create,
|
create: create,
|
||||||
insert: insert,
|
insert: insert,
|
||||||
remove: remove,
|
remove: remove,
|
||||||
query: query,
|
find: find,
|
||||||
|
findOne: findOne,
|
||||||
update: insert
|
update: insert
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "invodb",
|
"name": "invodb",
|
||||||
"version": "1.0.23",
|
"version": "1.1.1",
|
||||||
"description": "a nosql json document database",
|
"description": "a nosql json document database",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -10,6 +10,7 @@ std::fstream PageManager::stream;
|
|||||||
int PageManager::loadDatabase(const char *filename) {
|
int PageManager::loadDatabase(const char *filename) {
|
||||||
Instance().stream.open(filename);
|
Instance().stream.open(filename);
|
||||||
Instance().stream.seekp(0, std::ios::end);
|
Instance().stream.seekp(0, std::ios::end);
|
||||||
|
|
||||||
if(!Instance().stream.is_open()) {
|
if(!Instance().stream.is_open()) {
|
||||||
std::ofstream file(filename, std::fstream::out);
|
std::ofstream file(filename, std::fstream::out);
|
||||||
file.close();
|
file.close();
|
||||||
@ -68,12 +69,13 @@ int PageManager::allocate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
index = page.getIntStartFrom(4);
|
index = page.getIntStartFrom(4);
|
||||||
|
|
||||||
//printf("2allocate: %d\n", index);
|
//printf("2allocate: %d\n", index);
|
||||||
|
|
||||||
page.setIntStartFrom(4, index + 1);
|
page.setIntStartFrom(4, index + 1);
|
||||||
page.save();
|
page.save();
|
||||||
// allocate block at the end
|
// allocate block at the end
|
||||||
// stream.seekp(0, std::ios::end);
|
// stream.seekp(0, std::ios::end);
|
||||||
// index = stream.tellp() / 1024;
|
// index = stream.tellp() / 1024;
|
||||||
setPage(index, StoragePage(index));
|
setPage(index, StoragePage(index));
|
||||||
return index;
|
return index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user