#include <SWI-cpp.h>
#include <iostream>
#include "knowrob/storage/mongo/MongoInterface.h"
#include "knowrob/reasoner/mongolog/bson_pl.h"
#include "knowrob/storage/mongo/Document.h"
Go to the source code of this file.
|
| PREDICATE (mng_collections, 2) |
|
| PREDICATE (mng_distinct_values_json, 4) |
|
| PREDICATE (mng_index_create_core, 3) |
|
| PREDICATE (mng_drop_unsafe, 2) |
|
| PREDICATE (mng_store, 3) |
|
| PREDICATE (mng_remove, 3) |
|
| PREDICATE (mng_update, 4) |
|
| PREDICATE (mng_bulk_write, 3) |
|
| PREDICATE (mng_cursor_create, 3) |
|
| PREDICATE (mng_cursor_create, 4) |
|
| PREDICATE (mng_cursor_destroy, 1) |
|
| PREDICATE (mng_cursor_erase, 1) |
|
| PREDICATE (mng_cursor_filter, 2) |
|
| PREDICATE (mng_cursor_aggregate, 2) |
|
| PREDICATE (mng_cursor_descending, 2) |
|
| PREDICATE (mng_cursor_ascending, 2) |
|
| PREDICATE (mng_cursor_limit, 2) |
|
| PREDICATE (mng_cursor_next_pairs, 2) |
|
| PREDICATE (mng_cursor_next_json, 2) |
|
◆ PL_SAFE_ARG_MACROS
#define PL_SAFE_ARG_MACROS |
◆ PREDICATE_COLLECTION
#define PREDICATE_COLLECTION MongoInterface::get().connect(PL_A1, (char*)PL_A2) |
◆ PREDICATE_CURSOR
#define PREDICATE_CURSOR MongoInterface::get().cursor((char*)PL_A1) |
◆ PREDICATE() [1/19]
PREDICATE |
( |
mng_bulk_write |
, |
|
|
3 |
|
|
) |
| |
Definition at line 144 of file mongo_kb.cpp.
145 static const PlAtom ATOM_insert(
"insert");
146 static const PlAtom ATOM_remove(
"remove");
147 static const PlAtom ATOM_update(
"update");
151 PlTail pl_list(PL_A3);
154 while(pl_list.next(pl_member)) {
155 const PlAtom operation_name(pl_member.name());
156 const auto &pl_value1 = pl_member[1];
165 if(operation_name == ATOM_insert) {
166 bulk->pushInsert(doc1.bson());
168 else if(operation_name == ATOM_remove) {
169 bulk->pushRemoveAll(doc1.bson());
171 else if(operation_name == ATOM_update) {
172 const auto &pl_value2 = pl_member[2];
177 bulk->pushUpdate(doc1.bson(), doc2.bson());
181 MONGOC_ERROR_COMMAND,
182 MONGOC_ERROR_COMMAND_INVALID_ARG,
183 "unknown bulk operation '%s'", pl_member.name());
192 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
bool bsonpl_concat(bson_t *doc, const PlTerm &term, bson_error_t *err)
#define PREDICATE_COLLECTION
◆ PREDICATE() [2/19]
PREDICATE |
( |
mng_collections |
, |
|
|
2 |
|
|
) |
| |
Definition at line 48 of file mongo_kb.cpp.
49 auto db_handle = MongoInterface::get().connect(PL_A1);
52 if ((strv = mongoc_database_get_collection_names_with_opts(
53 db_handle->db(),
nullptr , &err))) {
55 for (
int i=0; strv[i]; i++) {
63 throw MongoPLException(
MongoException(
"collection_lookup_failed", err));
◆ PREDICATE() [3/19]
PREDICATE |
( |
mng_cursor_aggregate |
, |
|
|
2 |
|
|
) |
| |
Definition at line 244 of file mongo_kb.cpp.
246 Document doc_a(termToDocument(PL_A2));
251 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [4/19]
PREDICATE |
( |
mng_cursor_ascending |
, |
|
|
2 |
|
|
) |
| |
Definition at line 263 of file mongo_kb.cpp.
269 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [5/19]
PREDICATE |
( |
mng_cursor_create |
, |
|
|
3 |
|
|
) |
| |
Definition at line 195 of file mongo_kb.cpp.
197 PL_A3 = MongoInterface::get().cursor_create(PL_A1,(
char*)PL_A2)->id().c_str();
201 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [6/19]
PREDICATE |
( |
mng_cursor_create |
, |
|
|
4 |
|
|
) |
| |
Definition at line 204 of file mongo_kb.cpp.
206 Document doc_a(termToDocument(PL_A4));
207 auto cursor = MongoInterface::get().cursor_create(PL_A1,(
char*)PL_A2);
208 cursor->filter(doc_a.bson());
209 PL_A3 = cursor->id().c_str();
213 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [7/19]
PREDICATE |
( |
mng_cursor_descending |
, |
|
|
2 |
|
|
) |
| |
Definition at line 254 of file mongo_kb.cpp.
260 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [8/19]
PREDICATE |
( |
mng_cursor_destroy |
, |
|
|
1 |
|
|
) |
| |
Definition at line 216 of file mongo_kb.cpp.
218 char* cursor_id = (
char*)PL_A1;
219 MongoInterface::get().cursor_destroy(cursor_id);
223 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [9/19]
PREDICATE |
( |
mng_cursor_erase |
, |
|
|
1 |
|
|
) |
| |
Definition at line 226 of file mongo_kb.cpp.
231 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [10/19]
PREDICATE |
( |
mng_cursor_filter |
, |
|
|
2 |
|
|
) |
| |
Definition at line 234 of file mongo_kb.cpp.
236 Document doc_a(termToDocument(PL_A2));
241 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [11/19]
PREDICATE |
( |
mng_cursor_limit |
, |
|
|
2 |
|
|
) |
| |
Definition at line 272 of file mongo_kb.cpp.
278 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [12/19]
PREDICATE |
( |
mng_cursor_next_json |
, |
|
|
2 |
|
|
) |
| |
Definition at line 296 of file mongo_kb.cpp.
300 char* str = bson_as_canonical_extended_json(doc,
nullptr);
310 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [13/19]
PREDICATE |
( |
mng_cursor_next_pairs |
, |
|
|
2 |
|
|
) |
| |
Definition at line 281 of file mongo_kb.cpp.
293 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
PlTerm bson_to_term(const bson_t *bson)
◆ PREDICATE() [14/19]
PREDICATE |
( |
mng_distinct_values_json |
, |
|
|
4 |
|
|
) |
| |
Definition at line 67 of file mongo_kb.cpp.
68 auto db_handle = MongoInterface::get().connect(PL_A1);
69 char* coll_name = (
char*)PL_A2;
70 char* key = (
char*)PL_A3;
74 bson_t *command = BCON_NEW(
"distinct", BCON_UTF8(coll_name),
"key", BCON_UTF8(key));
75 bool success = mongoc_database_command_simple(
76 db_handle->db(), command,
nullptr, &reply, &err);
78 char* str = bson_as_canonical_extended_json(&reply,
nullptr);
82 bson_destroy(command);
◆ PREDICATE() [15/19]
PREDICATE |
( |
mng_drop_unsafe |
, |
|
|
2 |
|
|
) |
| |
Definition at line 106 of file mongo_kb.cpp.
112 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [16/19]
PREDICATE |
( |
mng_index_create_core |
, |
|
|
3 |
|
|
) |
| |
Definition at line 86 of file mongo_kb.cpp.
87 static const PlAtom ATOM_minus(
"-");
89 std::vector<mongo::IndexKey> indexes;
90 PlTail pl_list(PL_A3);
92 while (pl_list.next(pl_member)) {
93 const PlAtom mode_atom(pl_member.name());
94 const PlTerm &pl_value = pl_member[1];
95 if (mode_atom == ATOM_minus) {
96 indexes.emplace_back((
char *) pl_value, mongo::IndexType::DESCENDING);
98 indexes.emplace_back((
char *) pl_value, mongo::IndexType::ASCENDING);
102 return MongoInterface::get().connect(PL_A1)->create_index((
char*)PL_A2,indexes);
◆ PREDICATE() [17/19]
PREDICATE |
( |
mng_remove |
, |
|
|
3 |
|
|
) |
| |
Definition at line 124 of file mongo_kb.cpp.
130 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [18/19]
PREDICATE |
( |
mng_store |
, |
|
|
3 |
|
|
) |
| |
Definition at line 115 of file mongo_kb.cpp.
121 catch(
const std::exception &exc) {
throw MongoPLException(exc); }
◆ PREDICATE() [19/19]
PREDICATE |
( |
mng_update |
, |
|
|
4 |
|
|
) |
| |
Definition at line 133 of file mongo_kb.cpp.
141 catch(
const std::exception &exc) {
throw MongoPLException(exc); }