Behaviours: gen_server
.
compression_method() = snappy | lz4 | gzip | {deflate, Level::integer()} | none
cow_mfa() = {local, Name::atom()} | {global, GlobalName::term()} | {via, ViaName::term()}
db() = #db{} | pid()
fold_options() = [{dir, fwd | rev} | {start_key, term()} | {end_key, term()} | {end_key_gt, term()} | {key_group_fun, function()}]
fsync_options() = [before_header | after_header | on_file_open]
open_options() = [{compression, compression_method()} | {fsync_options, fsync_options()} | auto_compact | {auto_compact, boolean()} | {compact_limit, integer()} | {reduce, function()} | {less, function()} | {init_func, function()}]
transact_fn() = {module(), function(), [any()]} | {module(), function()} | function()
transact_id() = integer() | tx_end
transact_ops() = [{add, term(), any()} | {remove, term()} | {fn, transact_fn()}]
cancel_compact/1 | cancel compaction. |
close/1 | Close the file. |
compact/1 | compact the database file. |
count/1 | get the number of objects stored in the database. |
data_size/1 | get the total size of the objects stored in the database. |
database_info/1 | returns database info. |
delete/2 | delete one object from the store. |
drop_db/1 | delete a database. |
drop_db/2 | delete a database asynchronously or not. |
fold/3 | fold all objects form the database. |
fold/4 | fold all objects form the database with range options. |
fold_reduce/4 | fold the reduce function over the results. |
full_reduce/1 | return the full reduced value. |
get/2 | get an object by the specified key. |
get_snapshot/2 | get a snapshot of the database at some point. |
log/4 | fold the transaction log. |
log/5 | fold the transaction log
Args:
|
lookup/2 | deprecated: use mget/2 instead. |
mdelete/2 | delete multiple object at once. |
mget/2 | get a list of objects by the specified key. |
mput/2 | add multiple objects to a store. |
open/1 | open a cowdb database, pass a function to initialise the stores and indexes. |
open/2 | open a cowdb database, pass a function to initialise the stores and indexes. |
open/3 | Create or open a cowdb store with a registered name. |
open_link/1 | open a cowdb database as part of the supervision tree, pass a function to initialise the stores and indexes. |
open_link/2 | open a cowdb database as part of the supervision tree. |
open_link/3 | open a cowdb database as part of the supervision tree with a registered name. |
put/2 | add one object to a store. |
put/3 | add one object to a store. |
transact/2 | execute a transaction
A transaction received operations to execute as a list:
|
transact/3 |
cancel_compact(Ref::db()) -> ok
close(DbPid::pid()) -> ok
compact(Ref::db()) -> ok | {error, term()}
count(DbPid::db()) -> {ok, integer()} | {error, term()}
get the number of objects stored in the database.
data_size(DbPid::db()) -> {ok, integer()} | {error, term()}
get the total size of the objects stored in the database.
database_info(DbPid::db()) -> {ok, list()}
delete(Db::db(), Key::term()) -> {ok, transact_id()} | {error, term()}
delete one object from the store
drop_db(DbPid::db()) -> ok | {error, term()}
drop_db(DbPid::db(), Async::boolean()) -> ok | {error, term()}
delete a database asynchronously or not
fold(DbPid::db(), Fun::function(), Acc::any()) -> {ok, any(), any()} | {error, term()}
fold all objects form the database
fold(DbPid::db(), Fun::function(), Acc::any(), Options::fold_options()) -> {ok, any()} | {error, term()}
fold all objects form the database with range options
fold_reduce(DbPid, Fun, Acc, Options) -> any()
fold the reduce function over the results.
full_reduce(DbPid::db()) -> {ok, any()}
get(Db::db(), Key::any()) -> {ok, any()} | {error, term()}
get an object by the specified key
get_snapshot(DbPid::db(), TransactId::transact_id()) -> {ok, db()} | {error, term()}
get a snapshot of the database at some point.
log(Db::db(), StartT::transact_id(), Function::function(), Acc::any()) -> {ok, NbTransactions::integer(), Acc2::any()} | {error, term()}
log(Db::db(), StartT::transact_id(), EndT::transact_id(), Function::function(), Acc::any()) -> {ok, NbTransactions::integer(), Acc2::any()} | {error, term()}
fold the transaction log Args:
-
Db
: the db value (in transaction function) or pid -
StartT
: transaction ID to start from -
EndT
: transaction ID to stop -
Fun
: function collection log result:
fun({TransactId, Op, {K,V}, Ts}, Acc) ->
{ok, Acc2} | {stop, Acc2}
end
where TransactId is the transaction ID Transactid
where the OP
(add
or remove
) on the Key/Value pair {K, V}
has been run on
the unix time Ts
.
Acc
: initial value to pass to the function.
The function return the total number of transactions in the range and the values collected during folding.
lookup(Db::db(), Keys::[any()]) -> {ok, any()} | {error, term()}
deprecated: use mget/2 instead.
mdelete(Db::db(), Keys::[term()]) -> {ok, transact_id()} | {error, term()}
delete multiple object at once
mget(Db::db(), Keys::[any()]) -> {ok, any()} | {error, term()}
get a list of objects by the specified key
mput(Db::db(), KVs::[{term(), any()}]) -> {ok, transact_id()} | {error, term()}
add multiple objects to a store
open(FilePath::string()) -> {ok, Db::pid()} | {error, term()}
open a cowdb database, pass a function to initialise the stores and indexes.
open(FilePath::string(), Option::open_options()) -> {ok, Db::pid()} | {error, term()}
open a cowdb database, pass a function to initialise the stores and indexes.
open(Name::cow_mfa(), FilePath::string(), Option::open_options()) -> {ok, Db::pid()} | {error, term()}
Create or open a cowdb store with a registered name.
open_link(FilePath::string()) -> {ok, Db::pid()} | {error, term()}
open a cowdb database as part of the supervision tree, pass a function to initialise the stores and indexes.
open_link(FilePath::string(), Option::open_options()) -> {ok, Db::pid()} | {error, term()}
open a cowdb database as part of the supervision tree
open_link(Name::cow_mfa(), FilePath::string(), Option::open_options()) -> {ok, Db::pid()} | {error, term()}
open a cowdb database as part of the supervision tree with a registered name
put(DbPid::db(), X2::{term(), any()}) -> {ok, transact_id()} | {error, term()}
put(DbPid::db(), Key::term(), Value::any()) -> {ok, transact_id()} | {error, term()}
transact(Ref::db(), OPs::transact_ops()) -> {ok, transact_id()} | {error, term()}
execute a transaction A transaction received operations to execute as a list:
-
{add, Key, Value}
to add an object -
{remove, Key}
to remove a value -
{fn, Func}
a transaction function. A transaction function received the db value like it was at the beginning of the transaction as an argument. It's possible to pass arguments to it. A transaction function return a list of operations and can query/manipulate function. The list of operations returned can also contain a function.
transact(Ref::db(), OPs::transact_ops(), Timeout::timeout()) -> {ok, transact_id()} | {error, term()}