forked from EnterpriseDB/mongo_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo_wrapper.h
110 lines (95 loc) · 4.04 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*-------------------------------------------------------------------------
*
* mongo_wrapper.h
* Foreign-data wrapper for remote MongoDB servers
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
*
* Portions Copyright (c) 2004-2014, 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 "bson.h"
#ifdef META_DRIVER
#include "mongoc.h"
#else
#include "mongo.h"
#endif
#define json_object json_object_tmp
#include <bson.h>
#include <json.h>
#include <bits.h>
#ifdef META_DRIVER
MONGO_CONN* MongoConnect(const char* host, const unsigned short port, char *databaseName, char *user, char *password,
char *authenticationDatabase,char *replicaSet, char *readPreference, bool ssl, char *pem_file, char *pem_pwd, char *ca_file,
char *ca_dir, char *crl_file, bool weak_cert_validation);
#else
MONGO_CONN* MongoConnect(const char* host, const unsigned short port, char *databaseName, char *user, char *password);
#endif
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);
#ifdef META_DRIVER
const char* BsonIterBinData(BSON_ITERATOR *it, uint32_t *len);
#else
const char* BsonIterBinData(BSON_ITERATOR *it);
int BsonIterBinLen(BSON_ITERATOR *it);
#endif
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(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 char* 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 BsonFinish(BSON* b);
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