CreDB  0.1.0
Collection.h
1 #pragma once
2 
3 #include <cowlang/Value.h>
4 #include <memory>
5 #include <functional>
6 #include <json/Document.h>
7 #include <vector>
8 
9 #include "Witness.h"
10 #include "event_id.h"
11 
12 namespace credb
13 {
14 
22 {
23 public:
24  virtual ~Collection() = default;
25 
30  virtual std::vector<json::Document> diff(const std::string &key, version_number_t version1, version_number_t version2) = 0;
31 
43  virtual bool create_index(const std::string &name, const std::vector<std::string> &paths) = 0;
44 
53  virtual cow::ValuePtr call(const std::string &program_name, const std::vector<std::string> &args) = 0;
54 
63  virtual bool drop_index(const std::string &name) = 0;
64 
70  virtual const std::string &name() = 0;
71 
77  virtual uint32_t size() { return count(); }
78 
89  virtual bool set_trigger(std::function<void()> lambda) = 0;
90 
95  virtual bool unset_trigger() = 0;
96 
101  virtual uint32_t count(const json::Document &predicates = json::Document("")) = 0;
102 
112  virtual event_id_t add(const std::string &path, const json::Document &doc) = 0;
113 
118  virtual std::tuple<std::string, event_id_t> put(const json::Document &doc) = 0;
119 
129  virtual event_id_t put(const std::string &key, const json::Document &doc) = 0;
130 
140  virtual event_id_t put_code(const std::string &key, const std::string &code) = 0;
141 
151  virtual event_id_t put_code_from_file(const std::string &key, const std::string &filename) = 0;
152 
162  virtual event_id_t put_from_file(const std::string &key, const std::string &filename) = 0;
163 
168  virtual bool clear() = 0;
169 
177  virtual event_id_t remove(const std::string &key) = 0;
178 
187  virtual json::Document get(const std::string &key, event_id_t &event_id) = 0;
188 
195  virtual bool has_object(const std::string &key) = 0;
196 
207  virtual bool check(const std::string &key, const json::Document &predicate) = 0;
208 
212  virtual json::Document get_with_witness(const std::string &key, event_id_t &event_id, Witness &witness) = 0;
213 
218  virtual std::vector<json::Document> get_history(const std::string &key) = 0;
219 
229  virtual std::tuple<std::string, json::Document>
230  find_one(const json::Document &predicates = json::Document(""),
231  const std::vector<std::string> &projection = {}) = 0;
232 
244  virtual std::vector<std::tuple<std::string, json::Document>>
245  find(const json::Document &predicates = json::Document(""),
246  const std::vector<std::string> &projection = {},
247  int32_t limit = -1) = 0;
248 
256  json::Document get(const std::string &key)
257  {
258  event_id_t eid;
259  return std::forward<json::Document>(get(key, eid));
260  }
261 };
262 
263 } // namespace credb
virtual bool create_index(const std::string &name, const std::vector< std::string > &paths)=0
Witnesses hold a record about event(s) on the datastore&#39;s timeline.
Definition: Witness.h:29
virtual bool set_trigger(std::function< void()> lambda)=0
Set a function that will be triggered when the collection is modified, This will overwrite any existi...
virtual bool drop_index(const std::string &name)=0
virtual std::vector< json::Document > diff(const std::string &key, version_number_t version1, version_number_t version2)=0
Get the changes between two versions of the same object.
virtual event_id_t put_from_file(const std::string &key, const std::string &filename)=0
Insert or update an object to store the contents in a file.
Definition: Collection.h:21
virtual json::Document get_with_witness(const std::string &key, event_id_t &event_id, Witness &witness)=0
Get a value and return a witness for it.
virtual bool has_object(const std::string &key)=0
Check whether an object exists.
virtual std::vector< json::Document > get_history(const std::string &key)=0
Get the history of changes to a specified object.
virtual std::tuple< std::string, event_id_t > put(const json::Document &doc)=0
Insert a new value and generate a unique key for it.
virtual uint32_t count(const json::Document &predicates=json::Document(""))=0
Return the number of objects in this collection matching a specified predicate.
virtual bool unset_trigger()=0
Unset modification notifications for this collection.
Definition: Client.h:19
virtual std::vector< std::tuple< std::string, json::Document > > find(const json::Document &predicates=json::Document(""), const std::vector< std::string > &projection={}, int32_t limit=-1)=0
find all objects that fit a predicate
virtual bool check(const std::string &key, const json::Document &predicate)=0
Check whether an object matches a certain predicate.
virtual std::tuple< std::string, json::Document > find_one(const json::Document &predicates=json::Document(""), const std::vector< std::string > &projection={})=0
returns the first object that fits a predicate
virtual bool clear()=0
virtual uint32_t size()
Definition: Collection.h:77
virtual event_id_t put_code_from_file(const std::string &key, const std::string &filename)=0
Create a new object holding executable code loaded from a specified file.
virtual event_id_t put_code(const std::string &key, const std::string &code)=0
Create a new object holding executable code.
Specifies the position of an event on a node&#39;s ledger.
Definition: event_id.h:47
virtual event_id_t add(const std::string &path, const json::Document &doc)=0
Increment the vale of an object.
uint32_t version_number_t
Indicator of how many changes where made to an object.
Definition: event_id.h:27
virtual const std::string & name()=0
virtual cow::ValuePtr call(const std::string &program_name, const std::vector< std::string > &args)=0