mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +01:00
ircd:Ⓜ️ Add single-property getter interface for event.
This commit is contained in:
parent
b2badad065
commit
a1c3788c38
2 changed files with 134 additions and 0 deletions
|
@ -201,6 +201,17 @@ struct ircd::m::event::fetch
|
||||||
friend void seek(fetch &, const idx &);
|
friend void seek(fetch &, const idx &);
|
||||||
friend bool seek(fetch &, const id &, std::nothrow_t);
|
friend bool seek(fetch &, const id &, std::nothrow_t);
|
||||||
friend void seek(fetch &, const id &);
|
friend void seek(fetch &, const id &);
|
||||||
|
|
||||||
|
using view_closure = std::function<void (const string_view &)>;
|
||||||
|
friend bool get(std::nothrow_t, const idx &, const string_view &key, const view_closure &);
|
||||||
|
friend bool get(std::nothrow_t, const id &, const string_view &key, const view_closure &);
|
||||||
|
friend void get(const idx &, const string_view &key, const view_closure &);
|
||||||
|
friend void get(const id &, const string_view &key, const view_closure &);
|
||||||
|
|
||||||
|
friend const_buffer get(std::nothrow_t, const idx &, const string_view &key, const mutable_buffer &out);
|
||||||
|
friend const_buffer get(std::nothrow_t, const id &, const string_view &key, const mutable_buffer &out);
|
||||||
|
friend const_buffer get(const idx &, const string_view &key, const mutable_buffer &out);
|
||||||
|
friend const_buffer get(const id &, const string_view &key, const mutable_buffer &out);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Device to evaluate the conformity of an event object. This is an 'in vitro'
|
/// Device to evaluate the conformity of an event object. This is an 'in vitro'
|
||||||
|
|
123
ircd/m/event.cc
123
ircd/m/event.cc
|
@ -1204,6 +1204,129 @@ const
|
||||||
// event::fetch
|
// event::fetch
|
||||||
//
|
//
|
||||||
|
|
||||||
|
ircd::const_buffer
|
||||||
|
ircd::m::get(const event::id &event_id,
|
||||||
|
const string_view &key,
|
||||||
|
const mutable_buffer &out)
|
||||||
|
{
|
||||||
|
const auto &ret
|
||||||
|
{
|
||||||
|
get(std::nothrow, index(event_id), key, out)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!ret)
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"%s for %s not found in database",
|
||||||
|
key,
|
||||||
|
string_view{event_id}
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::const_buffer
|
||||||
|
ircd::m::get(const event::idx &event_idx,
|
||||||
|
const string_view &key,
|
||||||
|
const mutable_buffer &out)
|
||||||
|
{
|
||||||
|
const const_buffer ret
|
||||||
|
{
|
||||||
|
get(std::nothrow, event_idx, key, out)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!ret)
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"%s for event_idx[%lu] not found in database",
|
||||||
|
key,
|
||||||
|
event_idx
|
||||||
|
};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::const_buffer
|
||||||
|
ircd::m::get(std::nothrow_t,
|
||||||
|
const event::id &event_id,
|
||||||
|
const string_view &key,
|
||||||
|
const mutable_buffer &buf)
|
||||||
|
{
|
||||||
|
return get(std::nothrow, index(event_id), key, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
ircd::const_buffer
|
||||||
|
ircd::m::get(std::nothrow_t,
|
||||||
|
const event::idx &event_idx,
|
||||||
|
const string_view &key,
|
||||||
|
const mutable_buffer &buf)
|
||||||
|
{
|
||||||
|
const_buffer ret;
|
||||||
|
get(std::nothrow, event_idx, key, [&buf, &ret]
|
||||||
|
(const string_view &value)
|
||||||
|
{
|
||||||
|
ret = { data(buf), copy(buf, value) };
|
||||||
|
});
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::get(const event::id &event_id,
|
||||||
|
const string_view &key,
|
||||||
|
const event::fetch::view_closure &closure)
|
||||||
|
{
|
||||||
|
if(!get(std::nothrow, index(event_id), key, closure))
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"%s for %s not found in database",
|
||||||
|
key,
|
||||||
|
string_view{event_id}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ircd::m::get(const event::idx &event_idx,
|
||||||
|
const string_view &key,
|
||||||
|
const event::fetch::view_closure &closure)
|
||||||
|
{
|
||||||
|
if(!get(std::nothrow, event_idx, key, closure))
|
||||||
|
throw m::NOT_FOUND
|
||||||
|
{
|
||||||
|
"%s for event_idx[%lu] not found in database",
|
||||||
|
key,
|
||||||
|
event_idx
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::get(std::nothrow_t,
|
||||||
|
const event::id &event_id,
|
||||||
|
const string_view &key,
|
||||||
|
const event::fetch::view_closure &closure)
|
||||||
|
{
|
||||||
|
return get(std::nothrow, index(event_id), key, closure);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::get(std::nothrow_t,
|
||||||
|
const event::idx &event_idx,
|
||||||
|
const string_view &key,
|
||||||
|
const event::fetch::view_closure &closure)
|
||||||
|
{
|
||||||
|
const auto &column_idx
|
||||||
|
{
|
||||||
|
json::indexof<event>(key)
|
||||||
|
};
|
||||||
|
|
||||||
|
auto &column
|
||||||
|
{
|
||||||
|
dbs::event_column.at(column_idx)
|
||||||
|
};
|
||||||
|
|
||||||
|
return column(byte_view<string_view>{event_idx}, std::nothrow, closure);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::m::seek(event::fetch &fetch,
|
ircd::m::seek(event::fetch &fetch,
|
||||||
const event::id &event_id)
|
const event::id &event_id)
|
||||||
|
|
Loading…
Reference in a new issue