assert(jb && path);
bool err = false;
bool isdir = false;
- if (!tcstatfile(path, &isdir, NULL, NULL)) {
- return false;
- }
+ tcstatfile(path, &isdir, NULL, NULL);
if (!isdir) {
if (mkdir(path, 00755)) {
_ejdbsetecode(jb, TCEMKDIR, __FILE__, __LINE__, __func__);
static bool _exportcoll(EJCOLL *coll, const char *dpath, int flags) {
bool err = false;
- char *fpath = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, ".bson");
+ char *fpath = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, (flags & JBJSONEXPORT) ? ".json" : ".bson");
char *fpathm = tcsprintf("%s%c%s%s", dpath, MYPATHCHR, coll->cname, "-meta.json");
TCHDB *hdb = coll->tdb->hdb;
TCXSTR *skbuf = tcxstrnew3(sizeof (bson_oid_t) + 1);
}
}
bson_finish(&mbs);
+ bson_print_raw(bson_data(&mbs), 0);
+
+
char *wbuf = NULL;
int wsiz;
if (bson2json(bson_data(&mbs), &wbuf, &wsiz) != BSON_OK) {
/** Export settings */
enum {
- JBJSONEXPORT = 1 //If set json collection data will be exported into JSON instead of BSON
+ JBJSONEXPORT = 1, //If set json collection data will be exported into JSON instead of BSON.
+ JBIMPORTUPDATE = 2, //Update existing collection entries with imported ones. Collection options are ignored.
+ JBIMPORTREPLACE = 3 //Recreate existing collections and replace all collection entries with imported data.
+
};
/**
* Export database collections data to the specified location.
* Database read lock will be taken on each collection
* @param path Directory name in which data will exported.
- * @param colnames List of collection names to export. If NULL all collections will be exported.
+ * @param colnames List of collection names to export. If its value is `NULL` then all existing collections will be exported.
* @param flags. Can be set to `JBJSONEXPORT` in order to export collection data into JSON instead of BSON.
* @return on sucess `true`
*/
EJDB_EXPORT bool ejdbexport(EJDB *jb, const char *path, TCLIST *cnames, int flags);
+/**
+ *
+ * @param jb
+ * @param path
+ * @param cnames
+ * @param flags
+ * @return
+ */
+EJDB_EXPORT bool ejdbimport(EJDB *jb, const char *path, TCLIST *cnames, int flags);
+
+
EJDB_EXTERN_C_END
#endif /* EJDB_H */