nv-facutil-simple-db
v1.0.1
Published
nv-facutil-simple-db ======================== - just a array of fixed size(default 1000000) - insert-method on array - delete /update /left-pend right-pend/ commit/ rollback on element - suitable for 10w ~ 20w small in-memory datas(just saved in a array)
Downloads
2
Readme
nv-facutil-simple-db
- just a array of fixed size(default 1000000)
- insert-method on array
- delete /update /left-pend right-pend/ commit/ rollback on element
- suitable for 10w ~ 20w small in-memory datas(just saved in a array)
install
- npm install nv-facutil-simple-db
usage
const {creat_db,ERRORS} = require("nv-facutil-simple-db")
example
var db = creat_db(1000000);
var data = db.insert_and_commit([1,2])
/*
> data
Data(7) [2 %VbWFgVDA:2% ] [
Forest {
fid: 'VbWFgVDALYLhKTDjKZbFeTfaXvoDLkezRSFp',
max_size: 1000001,
idpool: { minid_: 1, maxid_: 1000001, used_: 2, lefted_: 999999 }
},
2,
false,
4,
Symbol(empty),
[ 1, 2 ],
Symbol(empty)
]
>
*/
data.curr_;
/*
> data.curr_;
[ 1, 2 ]
>
*/
data.update_and_commit({k:"value"})
/*
> data.prev_
[ 1, 2 ]
> data.curr_
{ k: 'value' }
>
*/
var data2 = data.rpend("string")
/*
> data2
Data(7) [3 %VbWFgVDA:3% ] [
Forest {
fid: 'VbWFgVDALYLhKTDjKZbFeTfaXvoDLkezRSFp',
max_size: 1000001,
idpool: { minid_: 1, maxid_: 1000001, used_: 3, lefted_: 999998 }
},
3,
false,
1,
Symbol(empty),
Symbol(empty),
'string'
]
>
> data2.is_pending()
true
>
> data2.commit()
> data2.is_pending()
false
> data2.curr_
'string'
> data2.is_new_stable()
true
> data2.is_stable()
true
>
> data2
Data(7) [3 %VbWFgVDA:3% ] [
Forest {
fid: 'VbWFgVDALYLhKTDjKZbFeTfaXvoDLkezRSFp',
max_size: 1000001,
idpool: { minid_: 1, maxid_: 1000001, used_: 3, lefted_: 999998 }
},
3,
false,
4,
Symbol(empty),
'string',
Symbol(empty)
]
>
*/
db.search((prev,curr,next)=>typeof(curr)==='string')
/*
[
Data(7) [3 %VbWFgVDA:3% ] [
Forest {
fid: 'VbWFgVDALYLhKTDjKZbFeTfaXvoDLkezRSFp',
max_size: 1000001,
idpool: { minid_: 1, maxid_: 1000001, used_: 3, lefted_: 999998 }
},
3,
false,
1,
Symbol(empty),
Symbol(empty),
'string'
]
]
*/
dump
var v8_dumped = db.slow_dump()
/*
{
fid: 'LGKweecBeNjtfAFlrVbaXUwpadGMeYSaJpHJ',
maxid: 1000001,
struct: {
ids: [ 1, 2, 3 ],
fc: [ 2, 0, 0 ],
pr: [ 0, 1, 1 ],
rb: [ 0, 3, 0 ],
lb: [ 0, 0, 2 ],
lc: [ 3, 0, 0 ]
},
data: [
null,
'ÿ\rA\x03I\nA\x02I\x02I\x04$\x00\x02o"\x01k"\x05value{\x01$\x00\x03',
'ÿ\rA\x02I\b"\x06string$\x00\x02'
]
}
*/
var jdumped = db.fast_dump()
/*
{
fid: 'LGKweecBeNjtfAFlrVbaXUwpadGMeYSaJpHJ',
maxid: 1000001,
struct: {
ids: [ 1, 2, 3 ],
fc: [ 2, 0, 0 ],
pr: [ 0, 1, 1 ],
rb: [ 0, 3, 0 ],
lb: [ 0, 0, 2 ],
lc: [ 3, 0, 0 ]
},
data: [ null, [ 5, [Array], [Object] ], [ 4, 'string' ] ]
}
*/
load
var db_x = load_from_slow_dumped(v8_dumped);
var db_y = load_from_fast_dumped(jdumped)
APIS
- creat_db(max_size=1000000) -> DbRoot
- load_from_slow_dumped(v8j) -> DbRoot
- load_from_fast_dumped(jj) -> DbRoot
- load_from_slow_file(fn) -> DbRoot
- load_from_fast_file(fn) -> DbRoot
METHODS
db
db.capacity_
db.insert db.insert_and_commit
db.search db.size_
db.fast_dump() //only support data-which-can-be-json.stringified
db.slow_dump() //support data-can-be-structure-cloned
db.fast_dump_to_file(file_name);
db.slow_dump_to_file(file_name);
data
data.commit
data.curr_ data.delete
data.delete_and_commit data.is_curr_empty
data.is_deleting data.is_init
data.is_new_stable data.is_next_empty
data.is_pending data.is_prev_empty
data.is_stable data.is_updating
data.lpend data.lpend_and_commit
data.next_ data.prev_
data.rollback data.rpend
data.rpend_and_commit data.search
data.search_aft_self data.search_bfr_self
data.state_ data.update
data.update_and_commit
LICENSE
- ISC