forestdb: Support more api calls.
parent
3359e9716b
commit
0b72a51cb3
|
@ -5,6 +5,8 @@ alien.libraries.finder alien.syntax classes.struct kernel
|
||||||
unix.types ;
|
unix.types ;
|
||||||
IN: forestdb.ffi
|
IN: forestdb.ffi
|
||||||
|
|
||||||
|
! Functions with LIBFDB_API are exported.
|
||||||
|
|
||||||
<< "forestdb" dup find-library cdecl add-library >>
|
<< "forestdb" dup find-library cdecl add-library >>
|
||||||
|
|
||||||
LIBRARY: forestdb
|
LIBRARY: forestdb
|
||||||
|
@ -87,6 +89,7 @@ ENUM: fdb_status
|
||||||
{ FDB_RESULT_IN_USE_BY_COMPACTOR -30 }
|
{ FDB_RESULT_IN_USE_BY_COMPACTOR -30 }
|
||||||
{ FDB_RESULT_FAIL -100 } ;
|
{ FDB_RESULT_FAIL -100 } ;
|
||||||
|
|
||||||
|
! cmp_fixed and cmp_variable have their own open() functions
|
||||||
STRUCT: fdb_config
|
STRUCT: fdb_config
|
||||||
{ chunksize uint16_t }
|
{ chunksize uint16_t }
|
||||||
{ blocksize uint32_t }
|
{ blocksize uint32_t }
|
||||||
|
@ -119,6 +122,9 @@ STRUCT: fdb_doc
|
||||||
{ body void* }
|
{ body void* }
|
||||||
{ deleted bool } ;
|
{ deleted bool } ;
|
||||||
|
|
||||||
|
! filename is a pointer to the handle's filename
|
||||||
|
! new_filename is a pointer to the handle's new_file
|
||||||
|
|
||||||
STRUCT: fdb_info
|
STRUCT: fdb_info
|
||||||
{ filename char* }
|
{ filename char* }
|
||||||
{ new_filename char* }
|
{ new_filename char* }
|
||||||
|
@ -128,26 +134,35 @@ STRUCT: fdb_info
|
||||||
{ file_size uint64_t } ;
|
{ file_size uint64_t } ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_init ( fdb_config* config ) ;
|
FUNCTION: fdb_status fdb_init ( fdb_config* config ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_open ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
FUNCTION: fdb_status fdb_open ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
||||||
FUNCTION: fdb_status fdb_open_cmp_fixed ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
FUNCTION: fdb_status fdb_open_cmp_fixed ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
||||||
FUNCTION: fdb_status fdb_open_cmp_variable ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
FUNCTION: fdb_status fdb_open_cmp_variable ( fdb_handle** ptr_handle, c-string filename, fdb_config* fconfig ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_set_log_callback ( fdb_handle* handle, fdb_log_callback log_callback, void* ctx_data ) ;
|
FUNCTION: fdb_status fdb_set_log_callback ( fdb_handle* handle, fdb_log_callback log_callback, void* ctx_data ) ;
|
||||||
|
|
||||||
|
! doc is calloc'd
|
||||||
FUNCTION: fdb_status fdb_doc_create ( fdb_doc** doc, c-string key, size_t keylen, c-string meta, size_t metalen, c-string body, size_t bodylen ) ;
|
FUNCTION: fdb_status fdb_doc_create ( fdb_doc** doc, c-string key, size_t keylen, c-string meta, size_t metalen, c-string body, size_t bodylen ) ;
|
||||||
FUNCTION: fdb_status fdb_doc_update ( fdb_doc** doc, c-string meta, size_t metalen, c-string body, size_t bodylen ) ;
|
FUNCTION: fdb_status fdb_doc_update ( fdb_doc** doc, c-string meta, size_t metalen, c-string body, size_t bodylen ) ;
|
||||||
FUNCTION: fdb_status fdb_doc_free ( fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_doc_free ( fdb_doc* doc ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_get ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_get ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
FUNCTION: fdb_status fdb_get_metaonly ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_get_metaonly ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
FUNCTION: fdb_status fdb_get_byseq ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_get_byseq ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
FUNCTION: fdb_status fdb_get_metaonly_byseq ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_get_metaonly_byseq ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
FUNCTION: fdb_status fdb_get_byoffset ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_get_byoffset ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_set ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_set ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
FUNCTION: fdb_status fdb_del ( fdb_handle* handle, fdb_doc* doc ) ;
|
FUNCTION: fdb_status fdb_del ( fdb_handle* handle, fdb_doc* doc ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_get_kv ( fdb_handle* handle, c-string key, size_t keylen, void** value_out, size_t* valuelen_out ) ;
|
FUNCTION: fdb_status fdb_get_kv ( fdb_handle* handle, c-string key, size_t keylen, void** value_out, size_t* valuelen_out ) ;
|
||||||
FUNCTION: fdb_status fdb_set_kv ( fdb_handle* handle, c-string key, size_t keylen, c-string value, size_t valuelen ) ;
|
FUNCTION: fdb_status fdb_set_kv ( fdb_handle* handle, c-string key, size_t keylen, c-string value, size_t valuelen ) ;
|
||||||
FUNCTION: fdb_status fdb_del_kv ( fdb_handle* handle, c-string key, size_t keylen ) ;
|
FUNCTION: fdb_status fdb_del_kv ( fdb_handle* handle, c-string key, size_t keylen ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_commit ( fdb_handle* handle, fdb_commit_opt_t opt ) ;
|
FUNCTION: fdb_status fdb_commit ( fdb_handle* handle, fdb_commit_opt_t opt ) ;
|
||||||
FUNCTION: fdb_status fdb_snapshot_open ( fdb_handle* handle_in, fdb_handle** handle_out, fdb_seqnum_t snapshot_seqnum ) ;
|
FUNCTION: fdb_status fdb_snapshot_open ( fdb_handle* handle_in, fdb_handle** handle_out, fdb_seqnum_t snapshot_seqnum ) ;
|
||||||
FUNCTION: fdb_status fdb_rollback ( fdb_handle** handle_ptr, fdb_seqnum_t rollback_seqnum ) ;
|
FUNCTION: fdb_status fdb_rollback ( fdb_handle** handle_ptr, fdb_seqnum_t rollback_seqnum ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_iterator_init ( fdb_handle* handle, fdb_iterator** iterator, c-string start_key, size_t start_keylen, c-string end_key, size_t end_keylen, fdb_iterator_opt_t opt ) ;
|
FUNCTION: fdb_status fdb_iterator_init ( fdb_handle* handle, fdb_iterator** iterator, c-string start_key, size_t start_keylen, c-string end_key, size_t end_keylen, fdb_iterator_opt_t opt ) ;
|
||||||
FUNCTION: fdb_status fdb_iterator_sequence_init ( fdb_handle* handle, fdb_iterator** iterator, fdb_seqnum_t start_seq, fdb_seqnum_t end_seq, fdb_iterator_opt_t opt ) ;
|
FUNCTION: fdb_status fdb_iterator_sequence_init ( fdb_handle* handle, fdb_iterator** iterator, fdb_seqnum_t start_seq, fdb_seqnum_t end_seq, fdb_iterator_opt_t opt ) ;
|
||||||
FUNCTION: fdb_status fdb_iterator_prev ( fdb_iterator* iterator, fdb_doc** doc ) ;
|
FUNCTION: fdb_status fdb_iterator_prev ( fdb_iterator* iterator, fdb_doc** doc ) ;
|
||||||
|
@ -155,12 +170,15 @@ FUNCTION: fdb_status fdb_iterator_next ( fdb_iterator* iterator, fdb_doc** doc )
|
||||||
FUNCTION: fdb_status fdb_iterator_next_metaonly ( fdb_iterator* iterator, fdb_doc** doc ) ;
|
FUNCTION: fdb_status fdb_iterator_next_metaonly ( fdb_iterator* iterator, fdb_doc** doc ) ;
|
||||||
FUNCTION: fdb_status fdb_iterator_seek ( fdb_iterator* iterator, c-string seek_key, size_t seek_keylen ) ;
|
FUNCTION: fdb_status fdb_iterator_seek ( fdb_iterator* iterator, c-string seek_key, size_t seek_keylen ) ;
|
||||||
FUNCTION: fdb_status fdb_iterator_close ( fdb_iterator* iterator ) ;
|
FUNCTION: fdb_status fdb_iterator_close ( fdb_iterator* iterator ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_compact ( fdb_handle* handle, c-string new_filename ) ;
|
FUNCTION: fdb_status fdb_compact ( fdb_handle* handle, c-string new_filename ) ;
|
||||||
FUNCTION: fdb_status fdb_get_dbinfo ( fdb_handle* handle, fdb_info* info ) ;
|
FUNCTION: fdb_status fdb_get_dbinfo ( fdb_handle* handle, fdb_info* info ) ;
|
||||||
FUNCTION: fdb_status fdb_switch_compaction_mode ( fdb_handle* handle, fdb_compaction_mode_t mode, size_t new_threshold ) ;
|
FUNCTION: fdb_status fdb_switch_compaction_mode ( fdb_handle* handle, fdb_compaction_mode_t mode, size_t new_threshold ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_close ( fdb_handle* handle ) ;
|
FUNCTION: fdb_status fdb_close ( fdb_handle* handle ) ;
|
||||||
FUNCTION: fdb_status fdb_destroy ( c-string filename, fdb_compaction_mode_t mode, size_t new_threshold ) ;
|
FUNCTION: fdb_status fdb_destroy ( c-string filename, fdb_compaction_mode_t mode, size_t new_threshold ) ;
|
||||||
FUNCTION: fdb_status fdb_shutdown ( ) ;
|
FUNCTION: fdb_status fdb_shutdown ( ) ;
|
||||||
|
|
||||||
FUNCTION: fdb_status fdb_begin_transaction ( fdb_handle* handle, fdb_isolation_level_t isolation_level ) ;
|
FUNCTION: fdb_status fdb_begin_transaction ( fdb_handle* handle, fdb_isolation_level_t isolation_level ) ;
|
||||||
FUNCTION: fdb_status fdb_end_transaction ( fdb_handle* handle, fdb_commit_opt_t opt ) ;
|
FUNCTION: fdb_status fdb_end_transaction ( fdb_handle* handle, fdb_commit_opt_t opt ) ;
|
||||||
FUNCTION: fdb_status fdb_abort_transaction ( fdb_handle* handle ) ;
|
FUNCTION: fdb_status fdb_abort_transaction ( fdb_handle* handle ) ;
|
||||||
|
|
|
@ -10,14 +10,37 @@ IN: forestdb.lib
|
||||||
|
|
||||||
{ "val123" } [
|
{ "val123" } [
|
||||||
forestdb-test-path [
|
forestdb-test-path [
|
||||||
"key123" "val123" fdb-set
|
"key123" "val123" fdb-set-kv
|
||||||
"key123" fdb-get
|
"key123" fdb-get-kv
|
||||||
] with-forestdb
|
] with-forestdb
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
{ "val12345" } [
|
{ "val12345" } [
|
||||||
forestdb-test-path [
|
forestdb-test-path [
|
||||||
"key123" "val12345" fdb-set
|
"key123" "val12345" fdb-set-kv
|
||||||
"key123" fdb-get
|
"key123" fdb-get-kv
|
||||||
|
] with-forestdb
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
{ f } [
|
||||||
|
! Filename is only valid inside with-forestdb
|
||||||
|
forestdb-test-path [
|
||||||
|
get-current-db-info filename>> alien>native-string empty?
|
||||||
|
] with-forestdb
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ 6 9 9 } [
|
||||||
|
forestdb-test-path [
|
||||||
|
"key123" "meta blah" "some body" fdb-doc-create
|
||||||
|
[ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
|
||||||
|
] with-forestdb
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
{ 7 8 15 } [
|
||||||
|
forestdb-test-path [
|
||||||
|
"key1234" "meta blah" "some body" fdb-doc-create
|
||||||
|
dup "new meta" "some other body" fdb-doc-update
|
||||||
|
[ keylen>> ] [ metalen>> ] [ bodylen>> ] tri
|
||||||
] with-forestdb
|
] with-forestdb
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
! Copyright (C) 2014 Doug Coleman.
|
! Copyright (C) 2014 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types alien.data alien.strings
|
USING: accessors alien.c-types alien.data alien.strings
|
||||||
combinators destructors forestdb.ffi fry io.encodings.string
|
classes.struct combinators destructors forestdb.ffi fry
|
||||||
io.encodings.utf8 io.pathnames kernel libc namespaces sequences ;
|
generalizations io.encodings.string io.encodings.utf8
|
||||||
|
io.pathnames kernel libc namespaces sequences ;
|
||||||
IN: forestdb.lib
|
IN: forestdb.lib
|
||||||
|
|
||||||
ERROR: fdb-error error ;
|
ERROR: fdb-error error ;
|
||||||
|
@ -22,25 +23,37 @@ TUPLE: fdb-handle < disposable handle ;
|
||||||
M: fdb-handle dispose*
|
M: fdb-handle dispose*
|
||||||
handle>> fdb_close check-forestdb-error ;
|
handle>> fdb_close check-forestdb-error ;
|
||||||
|
|
||||||
|
|
||||||
|
TUPLE: fdb-doc < disposable doc ;
|
||||||
|
M: fdb-doc dispose*
|
||||||
|
fdb_doc_free check-forestdb-error ;
|
||||||
|
|
||||||
|
|
||||||
: open-default-forestdb ( path -- handle )
|
: open-default-forestdb ( path -- handle )
|
||||||
[ f void* <ref> ] dip
|
[ f void* <ref> ] dip
|
||||||
absolute-path f
|
absolute-path f
|
||||||
[ fdb_open check-forestdb-error ] 3keep 2drop void* deref <fdb-handle> ;
|
[ fdb_open check-forestdb-error ] 3keep 2drop void* deref <fdb-handle> ;
|
||||||
|
|
||||||
|
: ret>string ( void** len -- string )
|
||||||
|
[ void* deref ] [ size_t deref ] bi*
|
||||||
|
[ memory>byte-array utf8 decode ] [ drop (free) ] 2bi ;
|
||||||
|
|
||||||
SYMBOL: current-forestdb
|
SYMBOL: current-forestdb
|
||||||
|
|
||||||
: get-handle ( -- handle )
|
: get-handle ( -- handle )
|
||||||
current-forestdb get handle>> ;
|
current-forestdb get handle>> ;
|
||||||
|
|
||||||
: fdb-set ( key value -- )
|
: fdb-set-kv ( key value -- )
|
||||||
[ get-handle ] 2dip
|
[ get-handle ] 2dip
|
||||||
[ dup length ] bi@ fdb_set_kv check-forestdb-error ;
|
[ dup length ] bi@ fdb_set_kv check-forestdb-error ;
|
||||||
|
|
||||||
: ret>string ( void** len -- string )
|
: fdb-set ( doc -- )
|
||||||
[ void* deref ] [ size_t deref ] bi*
|
[ get-handle ] dip fdb_set check-forestdb-error ;
|
||||||
[ memory>byte-array utf8 decode ] [ drop (free) ] 2bi ;
|
|
||||||
|
|
||||||
: fdb-get ( key -- value/f )
|
: fdb-del ( doc -- )
|
||||||
|
[ get-handle ] dip fdb_del check-forestdb-error ;
|
||||||
|
|
||||||
|
: fdb-get-kv ( key -- value/f )
|
||||||
[ get-handle ] dip
|
[ get-handle ] dip
|
||||||
dup length f void* <ref> 0 size_t <ref>
|
dup length f void* <ref> 0 size_t <ref>
|
||||||
[ fdb_get_kv ] 2keep
|
[ fdb_get_kv ] 2keep
|
||||||
|
@ -50,6 +63,28 @@ SYMBOL: current-forestdb
|
||||||
[ fdb-error ]
|
[ fdb-error ]
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
|
: fdb-del-kv ( key -- )
|
||||||
|
[ get-handle ] dip dup length fdb_del_kv check-forestdb-error ;
|
||||||
|
|
||||||
|
: fdb-doc-create ( key meta body -- doc )
|
||||||
|
[ f void* <ref> ] 3dip
|
||||||
|
[ dup length ] tri@
|
||||||
|
[ fdb_doc_create check-forestdb-error ] 7 nkeep 6 ndrop
|
||||||
|
void* deref fdb_doc memory>struct ;
|
||||||
|
|
||||||
|
: fdb-doc-update ( doc meta body -- )
|
||||||
|
[ void* <ref> ] 2dip
|
||||||
|
[ dup length ] bi@
|
||||||
|
fdb_doc_update check-forestdb-error ;
|
||||||
|
|
||||||
|
: fdb-doc-free ( doc -- )
|
||||||
|
fdb_doc_free check-forestdb-error ;
|
||||||
|
|
||||||
|
|
||||||
|
: get-current-db-info ( -- info )
|
||||||
|
get-handle
|
||||||
|
fdb_info <struct> [ fdb_get_dbinfo check-forestdb-error ] keep ;
|
||||||
|
|
||||||
: commit-forestdb ( -- )
|
: commit-forestdb ( -- )
|
||||||
get-handle FDB_COMMIT_NORMAL fdb_commit check-forestdb-error ;
|
get-handle FDB_COMMIT_NORMAL fdb_commit check-forestdb-error ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue