forked from citusdata/mongo_fdw
-
Notifications
You must be signed in to change notification settings - Fork 70
/
mongo_wrapper.h
94 lines (81 loc) · 3.52 KB
/
mongo_wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*-------------------------------------------------------------------------
*
* mongo_wrapper.h
* Wrapper functions for remote MongoDB servers
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
* Portions Copyright (c) 2004-2024, EnterpriseDB Corporation.
* Portions Copyright (c) 2012–2014 Citus Data, Inc.
*
* IDENTIFICATION
* mongo_wrapper.h
*
*-------------------------------------------------------------------------
*/
#ifndef MONGO_WRAPPER_H
#define MONGO_WRAPPER_H
#include "mongo_fdw.h"
#include "mongoc.h"
#define json_object json_object_tmp
#include <json.h>
MONGO_CONN *mongoConnect(MongoFdwOptions *opt);
void mongoDisconnect(MONGO_CONN *conn);
bool mongoInsert(MONGO_CONN *conn, char *database, char *collection,
BSON *b);
bool mongoUpdate(MONGO_CONN *conn, char *database, char *collection,
BSON *b, BSON *op);
bool mongoDelete(MONGO_CONN *conn, char *database, char *collection,
BSON *b);
MONGO_CURSOR *mongoCursorCreate(MONGO_CONN *conn, char *database,
char *collection, BSON *q);
const BSON *mongoCursorBson(MONGO_CURSOR *c);
bool mongoCursorNext(MONGO_CURSOR *c, BSON *b);
void mongoCursorDestroy(MONGO_CURSOR *c);
double mongoAggregateCount(MONGO_CONN *conn, const char *database,
const char *collection, const BSON *b);
BSON *bsonCreate(void);
void bsonDestroy(BSON *b);
bool bsonIterInit(BSON_ITERATOR *it, BSON *b);
bool bsonIterSubObject(BSON_ITERATOR *it, BSON *b);
int32_t bsonIterInt32(BSON_ITERATOR *it);
int64_t bsonIterInt64(BSON_ITERATOR *it);
double bsonIterDouble(BSON_ITERATOR *it);
bool bsonIterBool(BSON_ITERATOR *it);
const char *bsonIterString(BSON_ITERATOR *it);
const char *bsonIterBinData(BSON_ITERATOR *it, uint32_t *len);
const bson_oid_t *bsonIterOid(BSON_ITERATOR *it);
time_t bsonIterDate(BSON_ITERATOR *it);
int bsonIterType(BSON_ITERATOR *it);
int bsonIterNext(BSON_ITERATOR *it);
bool bsonIterSubIter(BSON_ITERATOR *it, BSON_ITERATOR *sub);
void bsonOidFromString(bson_oid_t *o, char *str);
void bsonOidToString(const bson_oid_t *o, char str[25]);
const char *bsonIterCode(BSON_ITERATOR *i);
const char *bsonIterRegex(BSON_ITERATOR *i);
const char *bsonIterKey(BSON_ITERATOR *i);
const bson_value_t *bsonIterValue(BSON_ITERATOR *i);
void bsonIteratorFromBuffer(BSON_ITERATOR *i, const char *buffer);
BSON *bsonCreate();
bool bsonAppendOid(BSON *b, const char *key, bson_oid_t *v);
bool bsonAppendBool(BSON *b, const char *key, bool v);
bool bsonAppendNull(BSON *b, const char *key);
bool bsonAppendInt32(BSON *b, const char *key, int v);
bool bsonAppendInt64(BSON *b, const char *key, int64_t v);
bool bsonAppendDouble(BSON *b, const char *key, double v);
bool bsonAppendUTF8(BSON *b, const char *key, char *v);
bool bsonAppendBinary(BSON *b, const char *key, char *v, size_t len);
bool bsonAppendDate(BSON *b, const char *key, time_t v);
bool bsonAppendStartArray(BSON *b, const char *key, BSON *c);
bool bsonAppendFinishArray(BSON *b, BSON *c);
bool bsonAppendStartObject(BSON *b, char *key, BSON *r);
bool bsonAppendFinishObject(BSON *b, BSON *r);
bool bsonAppendBson(BSON *b, char *key, BSON *c);
bool jsonToBsonAppendElement(BSON *bb, const char *k,
struct json_object *v);
json_object *jsonTokenerPrase(char *s);
char *bsonAsJson(const BSON *bsonDocument);
void bsonToJsonStringValue(StringInfo output, BSON_ITERATOR *iter,
bool isArray);
void dumpJsonObject(StringInfo output, BSON_ITERATOR *iter);
void dumpJsonArray(StringInfo output, BSON_ITERATOR *iter);
#endif /* MONGO_QUERY_H */