Tkrzw
|
Interface of database manager. More...
#include <tkrzw_dbm.h>
Classes | |
class | FileProcessor |
Interface of processor for a record. More... | |
class | FileProcessorCopyFile |
File processor to implement DBM::CopyFile. More... | |
class | Iterator |
Interface of iterator for each record. More... | |
class | RecordProcessor |
Interface of processor for a record. More... | |
class | RecordProcessorAppend |
Record processor to implement DBM::Append. More... | |
class | RecordProcessorCompareExchange |
Record processor to implement DBM::CompareExchange. More... | |
class | RecordProcessorExport |
Record processor to implement DBM::Export. More... | |
class | RecordProcessorGet |
Record processor to implement DBM::Get. More... | |
class | RecordProcessorIncrement |
Record processor to implement DBM::Increment. More... | |
class | RecordProcessorIteratorGet |
Record processor to implement DBM::Iterator::Get. More... | |
class | RecordProcessorIteratorRemove |
Record processor to implement DBM::Iterator::Remove. More... | |
class | RecordProcessorIteratorSet |
Record processor to implement DBM::Iterator::Set. More... | |
class | RecordProcessorRemove |
Record processor to implement DBM::Remove. More... | |
class | RecordProcessorSet |
Record processor to implement DBM::Set. More... | |
Public Member Functions | |
virtual | ~DBM ()=default |
Destructor. More... | |
virtual Status | Open (const std::string &path, bool writable, int32_t options=File::OPEN_DEFAULT)=0 |
Opens a database file. More... | |
virtual Status | Close ()=0 |
Closes the database file. More... | |
virtual Status | Process (std::string_view key, RecordProcessor *proc, bool writable)=0 |
Processes a record with a processor. More... | |
virtual Status | Get (std::string_view key, std::string *value=nullptr) |
Gets the value of a record of a key. More... | |
virtual std::string | GetSimple (std::string_view key, std::string_view default_value="") |
Gets the value of a record of a key, in a simple way. More... | |
virtual std::map< std::string, std::string > | GetMulti (const std::initializer_list< std::string > &keys) |
Gets the values of multiple records of keys. More... | |
virtual std::map< std::string, std::string > | GetMulti (const std::vector< std::string > &keys) |
Gets the values of multiple records of keys, with a vector. More... | |
virtual Status | Set (std::string_view key, std::string_view value, bool overwrite=true) |
Sets a record of a key and a value. More... | |
virtual Status | SetMulti (const std::initializer_list< std::pair< std::string, std::string >> &records, bool overwrite=true) |
Sets multiple records. More... | |
virtual Status | SetMulti (const std::map< std::string, std::string > &records, bool overwrite=true) |
Sets multiple records, with a map of strings. More... | |
virtual Status | Remove (std::string_view key) |
Removes a record of a key. More... | |
virtual Status | Append (std::string_view key, std::string_view value, std::string_view delim="") |
Appends data at the end of a record of a key. More... | |
virtual Status | CompareExchange (std::string_view key, std::string_view expected, std::string_view desired, std::string *actual=nullptr) |
Compares the value of a record and exchanges if the condition meets. More... | |
virtual Status | Increment (std::string_view key, int64_t increment=1, int64_t *current=nullptr, int64_t initial=0) |
Increments the numeric value of a record. More... | |
int64_t | IncrementSimple (std::string_view key, int64_t increment=1, int64_t initial=0) |
Increments the numeric value of a record, in a simple way. More... | |
virtual Status | ProcessEach (RecordProcessor *proc, bool writable)=0 |
Processes each and every record in the database with a processor. More... | |
virtual Status | Count (int64_t *count)=0 |
Gets the number of records. More... | |
virtual int64_t | CountSimple () |
Gets the number of records, in a simple way. More... | |
virtual Status | GetFileSize (int64_t *size)=0 |
Gets the current file size of the database. More... | |
virtual int64_t | GetFileSizeSimple () |
Gets the current file size of the database, in a simple way. More... | |
virtual Status | GetFilePath (std::string *path)=0 |
Gets the path of the database file. More... | |
virtual std::string | GetFilePathSimple () |
Gets the path of the database file, in a simple way. More... | |
virtual Status | Clear ()=0 |
Removes all records. More... | |
virtual Status | Rebuild ()=0 |
Rebuilds the entire database. More... | |
virtual Status | ShouldBeRebuilt (bool *tobe)=0 |
Checks whether the database should be rebuilt. More... | |
virtual bool | ShouldBeRebuiltSimple () |
Checks whether the database should be rebuilt, in a simple way. More... | |
virtual Status | Synchronize (bool hard, FileProcessor *proc=nullptr)=0 |
Synchronizes the content of the database to the file system. More... | |
virtual Status | CopyFile (const std::string &dest_path) |
Copies the content of the database file to another file. More... | |
virtual Status | Export (DBM *dbm) |
Exports all records to another database. More... | |
virtual std::vector< std::pair< std::string, std::string > > | Inspect ()=0 |
Inspects the database. More... | |
virtual bool | IsOpen () const =0 |
Checks whether the database is open. More... | |
virtual bool | IsWritable () const =0 |
Checks whether the database is writable. More... | |
virtual bool | IsHealthy () const =0 |
Checks whether the database condition is healthy. More... | |
virtual bool | IsOrdered () const =0 |
Checks whether ordered operations are supported. More... | |
virtual std::unique_ptr< Iterator > | MakeIterator ()=0 |
Makes an iterator for each record. More... | |
virtual std::unique_ptr< DBM > | MakeDBM () const =0 |
Make a new DBM object of the same concrete class. More... | |
Interface of database manager.
|
virtualdefault |
Destructor.
|
pure virtual |
Opens a database file.
path | A path of the file. |
writable | If true, the file is writable. If false, it is read-only. |
options | Bit-sum options for opening the file. |
Implemented in tkrzw::StdTreeDBM, tkrzw::SkipDBM, tkrzw::HashDBM, tkrzw::PolyDBM, tkrzw::TreeDBM, tkrzw::ShardDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Closes the database file.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::ShardDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Processes a record with a processor.
key | The key of the record. |
proc | The pointer to the processor object. |
writable | True if the processor can edit the record. |
If the specified record exists, the ProcessFull of the processor is called. Otherwise, the ProcessEmpty of the processor is called.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::ShardDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Gets the value of a record of a key.
key | The key of the record. |
value | The pointer to a string object to contain the result value. If it is nullptr, the value data is ignored. |
Reimplemented in tkrzw::PolyDBM, and tkrzw::ShardDBM.
|
virtual |
Gets the value of a record of a key, in a simple way.
key | The key of the record. |
default_value | The value to be returned on failure. |
|
virtual |
Gets the values of multiple records of keys.
keys | The keys of records to retrieve. |
|
virtual |
Gets the values of multiple records of keys, with a vector.
keys | The keys of records to retrieve. |
|
virtual |
Sets a record of a key and a value.
key | The key of the record. |
value | The value of the record. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned. |
Reimplemented in tkrzw::PolyDBM, tkrzw::SkipDBM, and tkrzw::ShardDBM.
|
virtual |
Sets multiple records.
records | The records to store. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned. |
|
virtual |
Sets multiple records, with a map of strings.
records | The records to store. |
overwrite | Whether to overwrite the existing value if there's a record with the same key. If true, the existing value is overwritten by the new value. If false, the operation is given up and an error status is returned. |
|
virtual |
Removes a record of a key.
key | The key of the record. |
Reimplemented in tkrzw::PolyDBM, tkrzw::SkipDBM, and tkrzw::ShardDBM.
|
virtual |
Appends data at the end of a record of a key.
key | The key of the record. |
value | The value to append. |
delim | The delimiter to put after the existing record. |
If there's no existing record, the value is set without the delimiter.
Reimplemented in tkrzw::PolyDBM, tkrzw::ShardDBM, tkrzw::TinyDBM, and tkrzw::BabyDBM.
|
virtual |
Compares the value of a record and exchanges if the condition meets.
key | The key of the record. |
expected | The expected value. |
desired | The desired value. If the data is nullptr, the record is to be removed. |
actual | The pointer to a string object to contain the result value. If it is nullptr, it is ignored. |
If the record doesn't exist, NOT_FOUND_ERROR is returned. If the existing value is different from the expected value, DUPLICATION_ERROR is returned. Otherwise, the desired value is set.
|
virtual |
Increments the numeric value of a record.
key | The key of the record. |
increment | The incremental value. If it is INT64MIN, the current value is not changed and a new record is not created. |
current | The pointer to an integer to contain the current value. If it is nullptr, it is ignored. |
initial | The initial value. |
The record value is stored as an 8-byte big-endian integer. Negative is also supported.
int64_t tkrzw::DBM::IncrementSimple | ( | std::string_view | key, |
int64_t | increment = 1 , |
||
int64_t | initial = 0 |
||
) |
Increments the numeric value of a record, in a simple way.
key | The key of the record. |
increment | The incremental value. |
initial | The initial value. |
The record value is treated as a decimal integer. Negative is also supported.
|
pure virtual |
Processes each and every record in the database with a processor.
proc | The pointer to the processor object. |
writable | True if the processor can edit the record. |
The ProcessFull of the processor is called repeatedly for each record. The ProcessEmpty of the processor is called once before the iteration and once after the iteration.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Gets the number of records.
count | The pointer to an integer object to contain the result count. |
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Gets the number of records, in a simple way.
|
pure virtual |
Gets the current file size of the database.
size | The pointer to an integer object to contain the result size. |
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Gets the current file size of the database, in a simple way.
|
pure virtual |
Gets the path of the database file.
path | The pointer to a string object to contain the result path. |
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Gets the path of the database file, in a simple way.
|
pure virtual |
Removes all records.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Rebuilds the entire database.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Checks whether the database should be rebuilt.
tobe | The pointer to a boolean object to contain the result decision. |
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::HashDBM, tkrzw::ShardDBM, tkrzw::TreeDBM, tkrzw::TinyDBM, tkrzw::CacheDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Checks whether the database should be rebuilt, in a simple way.
|
pure virtual |
Synchronizes the content of the database to the file system.
hard | True to do physical synchronization with the hardware or false to do only logical synchronization with the file system. |
proc | The pointer to the file processor object, whose Process method is called while the content of the file is synchronized. If it is nullptr, it is ignored. |
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::HashDBM, tkrzw::ShardDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
virtual |
Copies the content of the database file to another file.
dest_path | A path to the destination file. |
Copying is done while the content is synchronized and stable. So, this method is suitable for making a backup file while running a database service.
Reimplemented in tkrzw::ShardDBM.
Exports all records to another database.
dbm | The pointer to the destination database. |
|
pure virtual |
Inspects the database.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Checks whether the database is open.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Checks whether the database is writable.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Checks whether the database condition is healthy.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Checks whether ordered operations are supported.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Makes an iterator for each record.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.
|
pure virtual |
Make a new DBM object of the same concrete class.
Implemented in tkrzw::StdTreeDBM, tkrzw::PolyDBM, tkrzw::SkipDBM, tkrzw::ShardDBM, tkrzw::HashDBM, tkrzw::TreeDBM, tkrzw::CacheDBM, tkrzw::TinyDBM, tkrzw::BabyDBM, and tkrzw::StdHashDBM.