mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::db: Add convenience read(column) nothrow overloads.
This commit is contained in:
parent
e6fe7805c1
commit
f34ebec1cf
2 changed files with 40 additions and 0 deletions
|
@ -38,6 +38,11 @@ namespace ircd::db
|
|||
string_view read(column &, const string_view &key, const mutable_buffer &, const gopts & = {});
|
||||
std::string read(column &, const string_view &key, const gopts & = {});
|
||||
|
||||
// [GET] Nothrow convenience functions to copy data into your buffer; since
|
||||
// a key can exist with an empty value we must overload on this bool here.
|
||||
string_view read(column &, const string_view &key, bool &found, const mutable_buffer &, const gopts & = {});
|
||||
std::string read(column &, const string_view &key, bool &found, const gopts & = {});
|
||||
|
||||
// [SET] Write data to the db
|
||||
void write(column &, const string_view &key, const const_buffer &value, const sopts & = {});
|
||||
|
||||
|
|
35
ircd/db.cc
35
ircd/db.cc
|
@ -3863,6 +3863,41 @@ ircd::db::read(column &column,
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string
|
||||
ircd::db::read(column &column,
|
||||
const string_view &key,
|
||||
bool &found,
|
||||
const gopts &gopts)
|
||||
{
|
||||
std::string ret;
|
||||
const auto closure([&ret]
|
||||
(const string_view &src)
|
||||
{
|
||||
ret.assign(begin(src), end(src));
|
||||
});
|
||||
|
||||
found = column(key, std::nothrow, closure, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::db::read(column &column,
|
||||
const string_view &key,
|
||||
bool &found,
|
||||
const mutable_buffer &buf,
|
||||
const gopts &gopts)
|
||||
{
|
||||
string_view ret;
|
||||
const auto closure([&buf, &ret]
|
||||
(const string_view &src)
|
||||
{
|
||||
ret = { data(buf), copy(buf, src) };
|
||||
});
|
||||
|
||||
found = column(key, std::nothrow, closure, gopts);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<>
|
||||
ircd::db::prop_str
|
||||
ircd::db::property(const column &column,
|
||||
|
|
Loading…
Reference in a new issue