#59 #72
authoradam <adamansky@gmail.com>
Mon, 15 Jul 2013 05:31:26 +0000 (12:31 +0700)
committeradam <adamansky@gmail.com>
Mon, 15 Jul 2013 05:31:26 +0000 (12:31 +0700)
.gitignore
tcejdb/ejdb.c
tcejdb/ejdb.h

index 662db7c..76e490d 100644 (file)
@@ -83,6 +83,7 @@ config.status
 /tcejdb/testejdb/t2
 /tcejdb/testejdb/t3
 /tcejdb/testejdb/t4
+/tcejdb/testejdb/test*
 
 */nbproject/private/*
 
index 649e074..566e913 100644 (file)
@@ -954,9 +954,7 @@ bool ejdbexport(EJDB *jb, const char *path, TCLIST *cnames, int flags) {
     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__);
@@ -997,7 +995,7 @@ finish:
 
 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);
@@ -1073,6 +1071,9 @@ wfinish:
             }
         }
         bson_finish(&mbs);
+        bson_print_raw(bson_data(&mbs), 0);
+
+
         char *wbuf = NULL;
         int wsiz;
         if (bson2json(bson_data(&mbs), &wbuf, &wsiz) != BSON_OK) {
index fcaf726..92c24f6 100644 (file)
@@ -503,20 +503,34 @@ EJDB_EXPORT bson* ejdbmeta(EJDB *jb);
 
 /** 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 */