20#include "ignite/client/detail/type_mapping_utils.h"
21#include "ignite/client/table/ignite_tuple.h"
22#include "ignite/client/transaction/transaction.h"
23#include "ignite/client/type_mapping.h"
25#include "ignite/common/detail/config.h"
26#include "ignite/common/ignite_result.h"
41template<
typename K,
typename V>
56 key_value_view(
const key_value_view &) =
delete;
57 key_value_view &operator=(
const key_value_view &) =
delete;
60 key_value_view() =
default;
61 key_value_view(key_value_view &&)
noexcept =
default;
62 key_value_view &operator=(key_value_view &&)
noexcept =
default;
74 transaction *tx,
const key_type &key, ignite_callback<std::optional<value_type>> callback);
84 [[nodiscard]] IGNITE_API std::optional<value_type>
get(
transaction *tx,
const key_type &key) {
85 return sync<std::optional<value_type>>(
86 [
this, tx, &key](
auto callback) {
get_async(tx, key, std::move(callback)); });
102 transaction *tx, std::vector<key_type> keys, ignite_callback<std::vector<std::optional<value_type>>> callback);
115 [[nodiscard]] IGNITE_API std::vector<std::optional<value_type>>
get_all(
117 return sync<std::vector<std::optional<value_type>>>([
this, tx, keys = std::move(keys)](
auto callback)
mutable {
142 return sync<bool>([
this, tx, &key](
auto callback) {
contains_async(tx, key, std::move(callback)); });
155 transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<void> callback);
165 IGNITE_API
void put(
transaction *tx,
const key_type &key,
const value_type &value) {
166 sync<void>([
this, tx, &key, &value](
auto callback) {
put_async(tx, key, value, std::move(callback)); });
178 transaction *tx,
const std::vector<std::pair<key_type, value_type>> &pairs, ignite_callback<void> callback);
187 IGNITE_API
void put_all(
transaction *tx,
const std::vector<std::pair<key_type, value_type>> &pairs) {
188 sync<void>([
this, tx, pairs](
auto callback)
mutable {
put_all_async(tx, pairs, std::move(callback)); });
202 ignite_callback<std::optional<value_type>> callback);
214 transaction *tx,
const key_type &key,
const value_type &value) {
215 return sync<std::optional<value_type>>(
216 [
this, tx, &key, &value](
auto callback) {
get_and_put_async(tx, key, value, std::move(callback)); });
231 transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<bool> callback);
243 [
this, tx, &key, &value](
auto callback) {
put_if_absent_async(tx, key, value, std::move(callback)); });
266 return sync<bool>([
this, tx, &key](
auto callback) {
remove_async(tx, key, std::move(callback)); });
280 transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<bool> callback);
294 [
this, tx, &key, &value](
auto callback) {
remove_async(tx, key, value, std::move(callback)); });
308 transaction *tx, std::vector<key_type> keys, ignite_callback<std::vector<key_type>> callback);
320 return sync<std::vector<key_type>>([
this, tx, keys = std::move(keys)](
auto callback)
mutable {
336 ignite_callback<std::vector<key_type>> callback);
348 return sync<std::vector<key_type>>([
this, tx, pairs = std::move(pairs)](
auto callback)
mutable {
363 transaction *tx,
const key_type &key, ignite_callback<std::optional<value_type>> callback);
374 return sync<std::optional<value_type>>(
390 transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<bool> callback);
405 [
this, tx, &key, &value](
auto callback) {
replace_async(tx, key, value, std::move(callback)); });
421 const value_type &new_value, ignite_callback<bool> callback);
435 transaction *tx,
const key_type &key,
const value_type &old_value,
const value_type &new_value) {
436 return sync<bool>([
this, tx, &key, &old_value, &new_value](
437 auto callback) {
replace_async(tx, key, old_value, new_value, std::move(callback)); });
452 ignite_callback<std::optional<value_type>> callback);
466 transaction *tx,
const key_type &key,
const value_type &value) {
467 return sync<std::optional<value_type>>(
468 [
this, tx, &key, &value](
auto callback) {
get_and_replace_async(tx, key, value, std::move(callback)); });
478 : m_impl(std::move(impl)) {}
481 std::shared_ptr<detail::table_impl> m_impl;
487template<
typename K,
typename V>
488class key_value_view {
492 typedef typename std::decay<K>::type key_type;
493 typedef typename std::decay<V>::type value_type;
496 key_value_view(
const key_value_view &) =
delete;
497 key_value_view &operator=(
const key_value_view &) =
delete;
500 key_value_view() =
default;
501 key_value_view(key_value_view &&)
noexcept =
default;
502 key_value_view &operator=(key_value_view &&)
noexcept =
default;
514 m_delegate.get_async(tx, convert_to_tuple(key),
515 [callback = std::move(callback)](
auto res) { callback(convert_result<value_type>(std::move(res))); });
526 [[nodiscard]] std::optional<value_type>
get(
transaction *tx,
const key_type &key) {
527 return sync<std::optional<value_type>>(
528 [
this, tx, &key](
auto callback) {
get_async(tx, key, std::move(callback)); });
544 transaction *tx, std::vector<key_type> keys, ignite_callback<std::vector<std::optional<value_type>>> callback) {
545 m_delegate.get_all_async(tx, values_to_tuples<key_type>(std::move(keys)),
546 [callback = std::move(callback)](
auto res) { callback(convert_result<value_type>(std::move(res))); });
560 [[nodiscard]] std::vector<std::optional<value_type>>
get_all(
transaction *tx, std::vector<key_type> keys) {
561 return sync<std::vector<std::optional<value_type>>>([
this, tx, keys = std::move(keys)](
auto callback)
mutable {
576 m_delegate.contains_async(tx, convert_to_tuple(key), std::move(callback));
588 return sync<bool>([
this, tx, &key](
auto callback) {
contains_async(tx, key, std::move(callback)); });
600 void put_async(
transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<void> callback) {
601 m_delegate.put_async(tx, convert_to_tuple(key), convert_to_tuple(value), std::move(callback));
613 sync<void>([
this, tx, &key, &value](
auto callback) {
put_async(tx, key, value, std::move(callback)); });
625 transaction *tx,
const std::vector<std::pair<key_type, value_type>> &pairs, ignite_callback<void> callback) {
626 m_delegate.put_all_async(tx, values_to_tuples<key_type, value_type>(std::move(pairs)), std::move(callback));
637 sync<void>([
this, tx, pairs](
auto callback)
mutable {
put_all_async(tx, pairs, std::move(callback)); });
651 ignite_callback<std::optional<value_type>> callback) {
652 m_delegate.get_and_put_async(tx, convert_to_tuple(key), convert_to_tuple(value),
653 [callback = std::move(callback)](
auto res) { callback(convert_result<value_type>(std::move(res))); });
666 return sync<std::optional<value_type>>(
667 [
this, tx, &key, &value](
auto callback) {
get_and_put_async(tx, key, value, std::move(callback)); });
682 transaction *tx,
const key_type &key,
const value_type &value, ignite_callback<bool> callback) {
683 m_delegate.put_if_absent_async(tx, convert_to_tuple(key), convert_to_tuple(value), std::move(callback));
696 [
this, tx, &key, &value](
auto callback) {
put_if_absent_async(tx, key, value, std::move(callback)); });
709 m_delegate.remove_async(tx, convert_to_tuple(key), std::move(callback));
721 return sync<bool>([
this, tx, &key](
auto callback) {
remove_async(tx, key, std::move(callback)); });
735 m_delegate.remove_async(tx, convert_to_tuple(key), convert_to_tuple(value), std::move(callback));
750 [
this, tx, &key, &value](
auto callback) {
remove_async(tx, key, value, std::move(callback)); });
764 transaction *tx, std::vector<key_type> keys, ignite_callback<std::vector<key_type>> callback) {
765 m_delegate.remove_all_async(tx, values_to_tuples<key_type>(std::move(keys)),
766 [callback = std::move(callback)](
auto res) { callback(convert_result<key_type>(std::move(res))); });
779 return sync<std::vector<key_type>>([
this, tx, keys = std::move(keys)](
auto callback)
mutable {
795 ignite_callback<std::vector<key_type>> callback) {
796 m_delegate.remove_all_async(tx, values_to_tuples<key_type, value_type>(std::move(pairs)),
797 [callback = std::move(callback)](
auto res) { callback(convert_result<key_type>(std::move(res))); });
810 return sync<std::vector<key_type>>([
this, tx, pairs = std::move(pairs)](
auto callback)
mutable {
825 transaction *tx,
const key_type &key, ignite_callback<std::optional<value_type>> callback) {
826 m_delegate.get_and_remove_async(tx, convert_to_tuple(key),
827 [callback = std::move(callback)](
auto res) { callback(convert_result<value_type>(std::move(res))); });
839 return sync<std::optional<value_type>>(
854 m_delegate.replace_async(tx, convert_to_tuple(key), convert_to_tuple(value), std::move(callback));
870 [
this, tx, &key, &value](
auto callback) {
replace_async(tx, key, value, std::move(callback)); });
886 ignite_callback<bool> callback) {
887 m_delegate.replace_async(
888 tx, convert_to_tuple(key), convert_to_tuple(old_value), convert_to_tuple(new_value), std::move(callback));
902 bool replace(
transaction *tx,
const key_type &key,
const value_type &old_value,
const value_type &new_value) {
903 return sync<bool>([
this, tx, &key, &old_value, &new_value](
904 auto callback) {
replace_async(tx, key, old_value, new_value, std::move(callback)); });
919 ignite_callback<std::optional<value_type>> callback) {
920 m_delegate.get_and_replace_async(tx, convert_to_tuple(key), convert_to_tuple(value),
921 [callback = std::move(callback)](
auto res) { callback(convert_result<value_type>(std::move(res))); });
936 transaction *tx,
const key_type &key,
const value_type &value) {
937 return sync<std::optional<value_type>>(
938 [
this, tx, &key, &value](
auto callback) {
get_and_replace_async(tx, key, value, std::move(callback)); });
948 : m_delegate(std::move(delegate)) {}
951 key_value_view<ignite_tuple, ignite_tuple> m_delegate;
Definition ignite_tuple.h:40
IGNITE_API std::vector< std::optional< value_type > > get_all(transaction *tx, std::vector< key_type > keys)
Definition key_value_view.h:115
IGNITE_API bool remove(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:292
IGNITE_API void put(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:165
IGNITE_API std::optional< value_type > get_and_remove(transaction *tx, const key_type &key)
Definition key_value_view.h:373
IGNITE_API bool put_if_absent(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:241
IGNITE_API std::optional< value_type > get_and_put(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:213
IGNITE_API bool contains(transaction *tx, const key_type &key)
Definition key_value_view.h:141
IGNITE_API bool replace(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:403
IGNITE_API std::optional< value_type > get(transaction *tx, const key_type &key)
Definition key_value_view.h:84
IGNITE_API std::vector< key_type > remove_all(transaction *tx, std::vector< key_type > keys)
Definition key_value_view.h:319
IGNITE_API std::optional< value_type > get_and_replace(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:465
IGNITE_API std::vector< key_type > remove_all(transaction *tx, std::vector< std::pair< key_type, value_type > > pairs)
Definition key_value_view.h:347
IGNITE_API bool remove(transaction *tx, const key_type &key)
Definition key_value_view.h:265
IGNITE_API bool replace(transaction *tx, const key_type &key, const value_type &old_value, const value_type &new_value)
Definition key_value_view.h:434
IGNITE_API void put_all(transaction *tx, const std::vector< std::pair< key_type, value_type > > &pairs)
Definition key_value_view.h:187
Definition key_value_view.h:488
bool replace(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:868
void get_all_async(transaction *tx, std::vector< key_type > keys, ignite_callback< std::vector< std::optional< value_type > > > callback)
Definition key_value_view.h:543
std::optional< value_type > get_and_remove(transaction *tx, const key_type &key)
Definition key_value_view.h:838
void put_if_absent_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< bool > callback)
Definition key_value_view.h:681
bool put_if_absent(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:694
void remove_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< bool > callback)
Definition key_value_view.h:734
void put_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< void > callback)
Definition key_value_view.h:600
std::optional< value_type > get_and_replace(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:935
void put_all_async(transaction *tx, const std::vector< std::pair< key_type, value_type > > &pairs, ignite_callback< void > callback)
Definition key_value_view.h:624
void get_and_remove_async(transaction *tx, const key_type &key, ignite_callback< std::optional< value_type > > callback)
Definition key_value_view.h:824
bool contains(transaction *tx, const key_type &key)
Definition key_value_view.h:587
bool remove(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:748
void replace_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< bool > callback)
Definition key_value_view.h:853
std::vector< key_type > remove_all(transaction *tx, std::vector< key_type > keys)
Definition key_value_view.h:778
void get_and_replace_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< std::optional< value_type > > callback)
Definition key_value_view.h:918
void put(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:612
void get_and_put_async(transaction *tx, const key_type &key, const value_type &value, ignite_callback< std::optional< value_type > > callback)
Definition key_value_view.h:650
bool remove(transaction *tx, const key_type &key)
Definition key_value_view.h:720
void put_all(transaction *tx, const std::vector< std::pair< key_type, value_type > > &pairs)
Definition key_value_view.h:636
std::optional< value_type > get_and_put(transaction *tx, const key_type &key, const value_type &value)
Definition key_value_view.h:665
void remove_async(transaction *tx, const key_type &key, ignite_callback< bool > callback)
Definition key_value_view.h:708
bool replace(transaction *tx, const key_type &key, const value_type &old_value, const value_type &new_value)
Definition key_value_view.h:902
void remove_all_async(transaction *tx, const std::vector< std::pair< key_type, value_type > > &pairs, ignite_callback< std::vector< key_type > > callback)
Definition key_value_view.h:794
void contains_async(transaction *tx, const key_type &key, ignite_callback< bool > callback)
Definition key_value_view.h:575
void get_async(transaction *tx, const key_type &key, ignite_callback< std::optional< value_type > > callback)
Definition key_value_view.h:513
std::vector< std::optional< value_type > > get_all(transaction *tx, std::vector< key_type > keys)
Definition key_value_view.h:560
void replace_async(transaction *tx, const key_type &key, const value_type &old_value, const value_type &new_value, ignite_callback< bool > callback)
Definition key_value_view.h:885
std::optional< value_type > get(transaction *tx, const key_type &key)
Definition key_value_view.h:526
std::vector< key_type > remove_all(transaction *tx, std::vector< std::pair< key_type, value_type > > pairs)
Definition key_value_view.h:809
void remove_all_async(transaction *tx, std::vector< key_type > keys, ignite_callback< std::vector< key_type > > callback)
Definition key_value_view.h:763
Definition transaction.h:35