0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::db::txn: Add template value-returning getters.

This commit is contained in:
Jason Volk 2019-05-09 19:02:06 -07:00
parent d81612a724
commit 6bf50ecb28
2 changed files with 35 additions and 0 deletions

View file

@ -47,6 +47,8 @@ struct ircd::db::txn
explicit operator rocksdb::WriteBatch &();
explicit operator database &();
template<class T = string_view> T val(const op &, const string_view &col, const string_view &key, T def = {}) const;
template<class T = string_view> T at(const op &, const string_view &col, const string_view &key) const;
bool get(const op &, const string_view &col, const string_view &key, const value_closure &) const;
void at(const op &, const string_view &col, const string_view &key, const value_closure &) const;
bool has(const op &, const string_view &col, const string_view &key) const;
@ -104,3 +106,35 @@ struct ircd::db::txn::opts
size_t reserve_bytes = 0;
size_t max_bytes = 0;
};
template<class T>
T
ircd::db::txn::at(const op &op,
const string_view &col,
const string_view &key)
const
{
T ret;
at(op, col, key, [&ret](const string_view &val)
{
ret = byte_view<T>(val);
});
return ret;
}
template<class T>
T
ircd::db::txn::val(const op &op,
const string_view &col,
const string_view &key,
T ret)
const
{
get(op, col, key, value_closure{[&ret](const string_view &val)
{
ret = byte_view<T>(val);
}});
return ret;
}

View file

@ -893,6 +893,7 @@ ircd::m::dbs::_index_event_horizon_resolve(db::txn &txn,
_opts.appendix.set(appendix::EVENT);
_opts.appendix.set(appendix::EVENT_REFS);
_opts.event_refs = opts.horizon_resolve;
_opts.interpose = &txn;
write(txn, _event, _opts);
// Delete the event_horizon entry after resolving.