Beispiel #1
0
 public static C4Query *c4query_new(C4Database *db, string queryExpression, string sortExpression, C4Error *outError)
 {
     using (var queryExpression_ = new C4String(queryExpression))
         using (var sortExpression_ = new C4String(sortExpression)) {
             return(NativeRaw.c4query_new(db, queryExpression_.AsC4Slice(), sortExpression_.AsC4Slice(), outError));
         }
 }
Beispiel #2
0
 public static C4DocEnumerator *c4db_enumerateAllDocs(C4Database *database, string startDocID, string endDocID, C4EnumeratorOptions *options, C4Error *outError)
 {
     using (var startDocID_ = new C4String(startDocID))
         using (var endDocID_ = new C4String(endDocID)) {
             return(NativeRaw.c4db_enumerateAllDocs(database, startDocID_.AsC4Slice(), endDocID_.AsC4Slice(), options, outError));
         }
 }
Beispiel #3
0
 public static C4RawDocument *c4raw_get(C4Database *database, string storeName, string docID, C4Error *outError)
 {
     using (var storeName_ = new C4String(storeName))
         using (var docID_ = new C4String(docID)) {
             return(NativeRaw.c4raw_get(database, storeName_.AsC4Slice(), docID_.AsC4Slice(), outError));
         }
 }
Beispiel #4
0
 public static C4Replicator *c4repl_new(C4Database *db, C4Address remoteAddress, string remoteDatabaseName,
                                        C4Database *otherDb, C4ReplicatorParameters @params, C4Error *err)
 {
     using (var remoteDatabaseName_ = new C4String(remoteDatabaseName)) {
         return(c4repl_new(db, remoteAddress, remoteDatabaseName_.AsC4Slice(), otherDb, @params, err));
     }
 }
 public static C4Key *c4key_newFullTextString(string text, string language)
 {
     using (var text_ = new C4String(text))
         using (var language_ = new C4String(language)) {
             return(NativeRaw.c4key_newFullTextString(text_.AsC4Slice(), language_.AsC4Slice()));
         }
 }
Beispiel #6
0
        public void TestInvalidDocID()
        {
            RunTestVariants(() =>
            {
                NativePrivate.c4log_warnOnErrors(false);
                LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err));
                try {
                    Action <C4Slice> checkPutBadDocID = (C4Slice docID) =>
                    {
                        C4Error e;
                        var rq   = new C4DocPutRequest();
                        rq.body  = Body;
                        rq.save  = true;
                        rq.docID = docID;
                        ((long)Native.c4doc_put(Db, &rq, null, &e)).Should()
                        .Be(0, "because the invalid doc ID should cause the put to fail");
                        e.domain.Should().Be(C4ErrorDomain.LiteCoreDomain);
                        e.code.Should().Be((int)C4ErrorCode.BadDocID);
                    };

                    checkPutBadDocID(C4Slice.Constant(""));
                    string tooLong = new string(Enumerable.Repeat('x', 241).ToArray());
                    using (var tooLong_ = new C4String(tooLong)) {
                        checkPutBadDocID(tooLong_.AsC4Slice());
                    }

                    checkPutBadDocID(C4Slice.Constant("oops\x00oops")); // Bad UTF-8
                    checkPutBadDocID(C4Slice.Constant("oops\noops"));   // Control characters
                } finally {
                    NativePrivate.c4log_warnOnErrors(true);
                    LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err));
                }
            });
        }
Beispiel #7
0
 public static bool c4db_setCookie(C4Database *db, string setCookieHeader, string fromHost, C4Error *outError)
 {
     using (var setCookieHeader_ = new C4String(setCookieHeader))
         using (var fromHost_ = new C4String(fromHost)) {
             return(NativeRaw.c4db_setCookie(db, setCookieHeader_.AsC4Slice(), fromHost_.AsC4Slice(), outError));
         }
 }
 public static C4Document *c4doc_getForPut(C4Database *database, string docID, string parentRevID, bool deleting, bool allowConflict, C4Error *outError)
 {
     using (var docID_ = new C4String(docID))
         using (var parentRevID_ = new C4String(parentRevID)) {
             return(NativeRawPrivate.c4doc_getForPut(database, docID_.AsC4Slice(), parentRevID_.AsC4Slice(), deleting, allowConflict, outError));
         }
 }
 public static bool c4db_createIndex(C4Database *database, string name, string expressionsJSON, C4IndexType indexType, C4IndexOptions *indexOptions, C4Error *outError)
 {
     using (var name_ = new C4String(name))
         using (var expressionsJSON_ = new C4String(expressionsJSON)) {
             return(NativeRaw.c4db_createIndex(database, name_.AsC4Slice(), expressionsJSON_.AsC4Slice(), indexType, indexOptions, outError));
         }
 }
Beispiel #10
0
 public static bool c4db_copy(string sourcePath, string destinationPath, C4DatabaseConfig *config, C4Error *error)
 {
     using (var sourcePath_ = new C4String(sourcePath))
         using (var destinationPath_ = new C4String(destinationPath)) {
             return(NativeRaw.c4db_copy(sourcePath_.AsC4Slice(), destinationPath_.AsC4Slice(), config, error));
         }
 }
Beispiel #11
0
 public static bool c4doc_selectCommonAncestorRevision(C4Document *doc, string rev1ID, string rev2ID)
 {
     using (var rev1ID_ = new C4String(rev1ID))
         using (var rev2ID_ = new C4String(rev2ID)) {
             return(NativeRaw.c4doc_selectCommonAncestorRevision(doc, rev1ID_.AsC4Slice(), rev2ID_.AsC4Slice()));
         }
 }
Beispiel #12
0
 public static string FLJSON5_ToJSON(string json5, FLError *error)
 {
     using (var json5_ = new C4String(json5)) {
         using (var retVal = NativeRaw.FLJSON5_ToJSON((FLSlice)json5_.AsC4Slice(), error)) {
             return(((FLSlice)retVal).CreateString());
         }
     }
 }
 public static string c4query_fullTextMatched(C4Query *query, string docID, ulong seq, C4Error *outError)
 {
     using (var docID_ = new C4String(docID)) {
         using (var retVal = NativeRaw.c4query_fullTextMatched(query, docID_.AsC4Slice(), seq, outError)) {
             return(((C4Slice)retVal).CreateString());
         }
     }
 }
Beispiel #14
0
 public static byte[] c4db_encodeJSON(C4Database *db, string jsonData, C4Error *outError)
 {
     using (var jsonData_ = new C4String(jsonData)) {
         using (var retVal = NativeRaw.c4db_encodeJSON(db, jsonData_.AsC4Slice(), outError)) {
             return(((C4Slice)retVal).ToArrayFast());
         }
     }
 }
Beispiel #15
0
 public static string FLData_ConvertJSON(string json, FLError *outError)
 {
     using (var json_ = new C4String(json)) {
         using (var retVal = NativeRaw.FLData_ConvertJSON((FLSlice)json_.AsC4Slice(), outError)) {
             return(((FLSlice)retVal).CreateString());
         }
     }
 }
Beispiel #16
0
 public static C4Document *c4doc_create(C4Database *db, string docID, byte[] body, C4RevisionFlags revisionFlags, C4Error *error)
 {
     using (var docID_ = new C4String(docID))
         fixed(byte *body_ = body)
         {
             return(NativeRaw.c4doc_create(db, docID_.AsC4Slice(), new C4Slice(body_, body == null ? 0 : (ulong)body.Length), revisionFlags, error));
         }
 }
 public static string c4doc_generateRevID(string body, string parentRevID, bool deletion)
 {
     using (var body_ = new C4String(body))
         using (var parentRevID_ = new C4String(parentRevID)) {
             using (var retVal = NativeRaw.c4doc_generateRevID(body_.AsC4Slice(), parentRevID_.AsC4Slice(), deletion)) {
                 return(((C4Slice)retVal).CreateString());
             }
         }
 }
Beispiel #18
0
 public static C4BlobStore *c4blob_openStore(string dirPath,
                                             C4DatabaseFlags flags,
                                             C4EncryptionKey *encryptionKey,
                                             C4Error *outError)
 {
     using (var dirPath_ = new C4String(dirPath)) {
         return(NativeRaw.c4blob_openStore(dirPath_.AsC4Slice(), flags, encryptionKey, outError));
     }
 }
Beispiel #19
0
 public static bool c4raw_put(C4Database *database, string storeName, string key, string meta, string body, C4Error *outError)
 {
     using (var storeName_ = new C4String(storeName))
         using (var key_ = new C4String(key))
             using (var meta_ = new C4String(meta))
                 using (var body_ = new C4String(body)) {
                     return(NativeRaw.c4raw_put(database, storeName_.AsC4Slice(), key_.AsC4Slice(), meta_.AsC4Slice(), body_.AsC4Slice(), outError));
                 }
 }
Beispiel #20
0
 public static bool c4doc_resolveConflict(C4Document *doc, string winningRevID, string losingRevID, byte[] mergedBody, C4RevisionFlags mergedFlags, C4Error *error)
 {
     using (var winningRevID_ = new C4String(winningRevID))
         using (var losingRevID_ = new C4String(losingRevID))
             fixed(byte *mergedBody_ = mergedBody)
             {
                 return(NativeRaw.c4doc_resolveConflict(doc, winningRevID_.AsC4Slice(), losingRevID_.AsC4Slice(), new C4Slice(mergedBody_, mergedBody == null ? 0 : (ulong)mergedBody.Length), mergedFlags, error));
             }
 }
        private unsafe C4Slice Reduce(void *context)
        {
            if (_reduce == null)
            {
                return(C4Slice.Null);
            }

            _lastReturn.Dispose();
            _lastReturn = new C4String(_reduce(_context));
            return(_lastReturn.AsC4Slice());
        }
Beispiel #22
0
        public void TestDuplicateRev()
        {
            RunTestVariants(() =>
            {
                var docID = "mydoc";
                var body  = "{\"key\":\"value\"}";
                var doc   = PutDoc(docID, null, body);
                var revID = doc->revID.CreateString();
                Native.c4doc_free(doc);

                body        = "{\"key\":\"newvalue\"}";
                doc         = PutDoc(docID, revID, body);
                var revID2a = doc->revID.CreateString();
                Native.c4doc_free(doc);

                LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err));
                var success = false;
                try {
                    using (var docID_ = new C4String(docID))
                        using (var revID_ = new C4String(revID))
                            using (var body_ = new C4String(body)) {
                                var history = new C4Slice[] { revID_.AsC4Slice() };
                                fixed(C4Slice * history_ = history)
                                {
                                    var rq = new C4DocPutRequest
                                    {
                                        allowConflict = true,
                                        docID         = docID_.AsC4Slice(),
                                        history       = history_,
                                        historyCount  = 1,
                                        body          = body_.AsC4Slice(),
                                        revFlags      = 0,
                                        save          = true
                                    };

                                    doc = (C4Document *)LiteCoreBridge.Check(err =>
                                    {
                                        var local = rq;
                                        return(Native.c4doc_put(Db, &local, null, err));
                                    });

                                    doc->docID.CreateString().Should().Be(docID);
                                }
                            }
                } finally {
                    LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, success, err));
                }

                var revID2b = doc->revID.CreateString();
                Native.c4doc_free(doc);

                revID2b.Should().Be(revID2a, "because an identical revision was inserted");
            });
        }
 public static string c4view_fullTextMatched(C4View *view,
                                             string docID,
                                             C4SequenceNumber seq,
                                             uint fullTextID,
                                             C4Error *outError)
 {
     using (var docID_ = new C4String(docID)) {
         using (var retVal = NativeRaw.c4view_fullTextMatched(view, docID_.AsC4Slice(), seq, fullTextID, outError)) {
             return(((C4Slice)retVal).CreateString());
         }
     }
 }
 public static C4QueryEnumerator *c4view_fullTextQuery(C4View *view,
                                                       string queryString,
                                                       string queryStringLanguage,
                                                       C4QueryOptions *c4Options,
                                                       C4Error *outError)
 {
     using (var queryString_ = new C4String(queryString))
         using (var queryStringLanguage_ = new C4String(queryStringLanguage)) {
             return(NativeRaw.c4view_fullTextQuery(view, queryString_.AsC4Slice(), queryStringLanguage_.AsC4Slice(),
                                                   c4Options, outError));
         }
 }
        private CBForestQueryEnumerator QueryEnumeratorWithOptions(QueryOptions options)
        {
            var enumerator = default(C4QueryEnumerator *);

            var startKey = options.StartKey;
            var endKey   = options.EndKey;

            if (options.Descending)
            {
                startKey = Misc.KeyForPrefixMatch(startKey, options.PrefixMatchLevel);
            }
            else
            {
                endKey = Misc.KeyForPrefixMatch(options.EndKey, options.PrefixMatchLevel);
            }
            using (var startkeydocid_ = new C4String(options.StartKeyDocId))
                using (var endkeydocid_ = new C4String(options.EndKeyDocId)) {
                    WithC4Keys(new object[] { startKey, endKey }, false, startEndKey =>
                               WithC4Keys(options.Keys == null ? null : options.Keys.ToArray(), true, c4keys =>
                    {
                        var opts            = C4QueryOptions.DEFAULT;
                        opts.descending     = options.Descending;
                        opts.endKey         = startEndKey[1];
                        opts.endKeyDocID    = endkeydocid_.AsC4Slice();
                        opts.inclusiveEnd   = options.InclusiveEnd;
                        opts.inclusiveStart = options.InclusiveStart;
                        if (c4keys != null)
                        {
                            opts.keysCount = (uint)c4keys.Length;
                        }

                        if (!options.Reduce)
                        {
                            opts.limit = (ulong)options.Limit;
                            opts.skip  = (ulong)options.Skip;
                        }

                        opts.startKey          = startEndKey[0];
                        opts.startKeyDocID     = startkeydocid_.AsC4Slice();
                        fixed(C4Key * *keysPtr = c4keys)
                        {
                            opts.keys  = keysPtr;
                            enumerator = (C4QueryEnumerator *)ForestDBBridge.Check(err => {
                                var localOpts = opts;
                                return(Native.c4view_query(IndexDB, &localOpts, err));
                            });
                        }
                    })
                               );
                }

            return(new CBForestQueryEnumerator(enumerator));
        }
 public static C4View *c4view_open(C4Database *database,
                                   string path,
                                   string viewName,
                                   string version,
                                   C4DatabaseConfig *config,
                                   C4Error *outError)
 {
     using (var path_ = new C4String(path))
         using (var viewName_ = new C4String(viewName))
             using (var version_ = new C4String(version)) {
                 return(NativeRaw.c4view_open(database, path_.AsC4Slice(), viewName_.AsC4Slice(), version_.AsC4Slice(),
                                              config, outError));
             }
 }
Beispiel #27
0
        protected override void SetupVariant(int option)
        {
            base.SetupVariant(option);

            var c = new List <char>(Enumerable.Repeat('a', SizeOfDocument));

            c.Add((char)0);
            var content = new string(c.ToArray());

            C4Error err;

            Native.c4db_beginTransaction(Db, &err).Should().BeTrue("because starting a transaction should succeed");
            var rng = new Random();

            for (int i = 0; i < NumDocuments; i++)
            {
                using (var docID = new C4String($"doc-{rng.Next():D8}-{rng.Next():D8}-{rng.Next():D8}-{i:D4}"))
                    using (var revID = new C4String("1-deadbeefcafebabe80081e50"))
                        using (var json = new C4String("{{\"content\":\"{content}\"}}")) {
                            var history = IsRevTrees() ? new C4String[1] {
                                new C4String("1-deadbeefcafebabe80081e50")
                            }
                        : new C4String[1] {
                                new C4String("1@deadbeefcafebabe80081e50")
                            };

                            var rawHistory = history.Select(x => x.AsC4Slice()).ToArray();
                            fixed(C4Slice *rawHistory_ = rawHistory)
                            {
                                var rq = new C4DocPutRequest();

                                rq.existingRevision = true;
                                rq.docID            = docID.AsC4Slice();
                                rq.history          = rawHistory_;
                                rq.historyCount     = 1;
                                rq.body             = json.AsC4Slice();
                                rq.save             = true;
                                var doc = Native.c4doc_put(Db, &rq, null, &err);

                                ((long)doc).Should().NotBe(0, $"because otherwise the put failed");
                                Native.c4doc_free(doc);
                            }
                        }
            }

            Native.c4db_endTransaction(Db, true, &err).Should().BeTrue("because otherwise the transaction failed to end");
            Console.WriteLine($"Created {NumDocuments} docs");
            Native.c4db_getDocumentCount(Db).Should().Be(NumDocuments, "because the number of documents should be the number that was just inserted");
        }
        private C4Document *PutDoc(C4Database *db, string docID, string revID, string body, C4RevisionFlags flags, C4Error *error = null)
        {
            LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err));
            var success = false;

            try {
                using (var docID_ = new C4String(docID))
                    using (var revID_ = new C4String(revID))
                        using (var body_ = new C4String(body)) {
                            var history = new C4Slice[] { revID_.AsC4Slice() };
                            fixed(C4Slice *history_ = history)
                            {
                                var rq = new C4DocPutRequest
                                {
                                    allowConflict = false,
                                    docID         = docID_.AsC4Slice(),
                                    history       = revID == null ? null : history_,
                                    historyCount  = revID == null ? 0UL : 1UL,
                                    body          = body_.AsC4Slice(),
                                    revFlags      = flags,
                                    remoteDBID    = _remoteDocID,
                                    save          = true
                                };

                                C4Document *doc;

                                if (error != null)
                                {
                                    var local = rq;
                                    doc = Native.c4doc_put(db, &local, null, error);
                                }
                                else
                                {
                                    doc = (C4Document *)LiteCoreBridge.Check(err =>
                                    {
                                        var local = rq;
                                        return(Native.c4doc_put(db, &local, null, err));
                                    });
                                }

                                success = true;
                                return(doc);
                            }
                        }
            } finally {
                LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, success, err));
            }
        }
Beispiel #29
0
        protected bool ReadFileByLines(string path, Func <FLSlice, bool> callback)
        {
            using (var tr = new StreamReader(File.Open(path, FileMode.Open))) {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
                    using (var c4 = new C4String(line)) {
                        if (!callback((FLSlice)c4.AsC4Slice()))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #30
0
        internal bool ReadFileByLines(string path, Func <FLSlice, bool> callback)
        {
#if WINDOWS_UWP
            var url  = $"ms-appx:///Assets/{path}";
            var file = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri(url))
                       .AsTask()
                       .ConfigureAwait(false)
                       .GetAwaiter()
                       .GetResult();

            var lines = Windows.Storage.FileIO.ReadLinesAsync(file).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
            foreach (var line in lines)
            {
#elif __ANDROID__
            var ctx = global::Couchbase.Lite.Tests.Android.MainActivity.ActivityContext;
            using (var tr = new StreamReader(ctx.Assets.Open(path))) {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
#elif __IOS__
            var bundlePath = ios::Foundation.NSBundle.MainBundle.PathForResource(Path.GetFileNameWithoutExtension(path), Path.GetExtension(path));
            using (var tr = new StreamReader(File.Open(bundlePath, FileMode.Open, FileAccess.Read)))
            {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
#else
            using (var tr = new StreamReader(File.Open(path, FileMode.Open))) {
                string line;
                while ((line = tr.ReadLine()) != null)
                {
#endif
                using (var c4 = new C4String(line)) {
                    if (!callback((FLSlice)c4.AsC4Slice()))
                    {
                        return(false);
                    }
                }
            }
#if !WINDOWS_UWP
        }
#endif

            return(true);
        }
Beispiel #31
0
 /// <summary>
 /// Reads a raw document from the database. In Couchbase Lite the store named "info" is used for 
 /// per-database key/value pairs, and the store "_local" is used for local documents.
 /// </summary>
 /// <param name="db">The database to operate on</param>
 /// <param name="storeName">The name of the store to read from</param>
 /// <param name="docID">The ID of the document to retrieve</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>A pointer to the retrieved document on success, or null on failure</returns>
 public static C4RawDocument* c4raw_get(C4Database *db, string storeName, string docID, C4Error *outError)
 {
     using(var storeName_ = new C4String(storeName))
     using(var docID_ = new C4String(docID)) {
         return c4raw_get(db, storeName_.AsC4Slice(), docID_.AsC4Slice(), outError);
     }
 }
Beispiel #32
0
 /// <summary>
 /// Adds a revision to a document, as a child of the currently selected revision
 /// (or as a root revision if there is no selected revision.)
 /// On success, the new revision will be selected.
 /// Must be called within a transaction.
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="revID">The ID of the revision being inserted</param>
 /// <param name="body">The (JSON) body of the revision</param>
 /// <param name="deleted">True if this revision is a deletion (tombstone)</param>
 /// <param name="hasAttachments">True if this revision contains an _attachments dictionary</param>
 /// <param name="allowConflict">If false, and the parent is not a leaf, a 409 error is returned</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>The number of revisions inserted (0, 1, or -1 on error)</returns>
 public static int c4doc_insertRevision(C4Document *doc, string revID, string body, bool deleted, bool hasAttachments,
     bool allowConflict, C4Error *outError)
 {
     using(var revID_ = new C4String(revID))
     using(var body_ = new C4String(body)) {
         return c4doc_insertRevision(doc, revID_.AsC4Slice(), body_.AsC4Slice(), deleted, 
             hasAttachments, allowConflict, outError);
     }
 }
Beispiel #33
0
 public static int c4doc_purgeRevision(C4Document *doc, string revId, C4Error *outError)
 {
     using(var revId_ = new C4String(revId)) {
         return c4doc_purgeRevision(doc, revId_.AsC4Slice(), outError);   
     }
 }
Beispiel #34
0
 /// <summary>
 /// Adds a map key, before the next value. When adding to a map, every value must be
 /// preceded by a key.
 /// </summary>
 /// <param name="key">The key to operate on</param>
 /// <param name="s">The value to store</param>
 public static void c4key_addMapKey(C4Key *key, string s)
 {
     using(var s_ = new C4String(s)) {
         c4key_addMapKey(key, s_.AsC4Slice());   
     }
 }
Beispiel #35
0
 public static bool c4db_purgeDoc(C4Database *db, string docId, C4Error *outError)
 {
     using (var docId_ = new C4String(docId)) {
         return c4db_purgeDoc(db, docId_.AsC4Slice(), outError);
     }
 }
Beispiel #36
0
 /// <summary>
 /// Creates an enumerator ordered by docID.
 /// Options have the same meanings as in Couchbase Lite.
 /// There's no 'limit' option; just stop enumerating when you're done.
 /// Caller is responsible for freeing the enumerator when finished with it.
 /// </summary>
 /// <param name="db">The database to operate on</param>
 /// <param name="startDocID">The document ID to begin at</param>
 /// <param name="endDocID">The document ID to end at</param>
 /// <param name="options">Enumeration options (NULL for defaults)</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>A pointer to the enumeator on success, otherwise null</returns>
 public static C4DocEnumerator* c4db_enumerateAllDocs(C4Database *db, string startDocID, string endDocID, C4EnumeratorOptions *options,
     C4Error *outError)
 {
     using(var startDocID_ = new C4String(startDocID))
     using(var endDocID_ = new C4String(endDocID)) {
         return c4db_enumerateAllDocs(db, startDocID_.AsC4Slice(), endDocID_.AsC4Slice(), options, outError);
     }
 }
Beispiel #37
0
 /// <summary>
 /// Writes a raw document to the database, or deletes it if both meta and body are NULL.
 /// </summary>
 /// <param name="db">The database to operate on</param>
 /// <param name="storeName">The store to write to</param>
 /// <param name="key">The key to store</param>
 /// <param name="meta">The metadata to store</param>
 /// <param name="body">The body to store</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4raw_put(C4Database *db, string storeName, string key, string meta, string body, C4Error *outError)
 {
     using(var storeName_ = new C4String(storeName))
     using(var key_ = new C4String(key))
     using(var meta_ = new C4String(meta))
     using(var body_ = new C4String(body)) {
         return c4raw_put(db, storeName_.AsC4Slice(), key_.AsC4Slice(), meta_.AsC4Slice(), 
                         body_.AsC4Slice(), outError);  
     }
 }
Beispiel #38
0
 /// <summary>
 /// Gets a document from the database. If there's no such document, the behavior depends on
 /// the mustExist flag.If it's true, NULL is returned. If it's false, a valid C4Document
 /// The current revision is selected(if the document exists.)
 /// </summary>
 /// <param name="db">The database to retrieve from</param>
 /// <param name="docID">The ID of the document to retrieve</param>
 /// <param name="mustExist">Whether or not to create the document on demand</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>A pointer to the retrieved document on success, or null on failure</returns>
 public static C4Document* c4doc_get(C4Database *db, string docID, bool mustExist, C4Error *outError)
 {
     using(var docID_ = new C4String(docID)) {
         return c4doc_get(db, docID_.AsC4Slice(), mustExist, outError);   
     }
 }
Beispiel #39
0
 /// <summary>
 /// Opens a database.
 /// </summary>
 /// <param name="path">The path to the DB file</param>
 /// <param name="readOnly">Whether or not the DB should be opened in read-only mode</param>
 /// <param name="encryptionKey">The option encryption key used to encrypt the database</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>A database instance for use in the C4 API</returns>
 public static C4Database *c4db_open(string path, C4DatabaseFlags flags,
     C4EncryptionKey *encryptionKey, C4Error *outError)
 {
     using(var path_ = new C4String(path)) {
         return c4db_open(path_.AsC4Slice(), flags, encryptionKey, outError);
     }
 }
Beispiel #40
0
 /// <summary>
 /// Opens a view, or creates it if the file doesn't already exist.
 /// </summary>
 /// <param name="db">The database the view is associated with</param>
 /// <param name="path">The file that the view is stored in</param>
 /// <param name="viewName">The name of the view</param>
 /// <param name="version">The version of the view's map function</param>
 /// <param name="flags">The flags for opening the view file</param>
 /// <param name="encryptionKey">The option encryption key used to encrypt the database</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>A pointer to the view on success, otherwise null</returns>
 public static C4View* c4view_open(C4Database *db, string path, string viewName, string version, C4DatabaseFlags flags,
     C4EncryptionKey *encryptionKey, C4Error *outError)
 {
     using(var path_ = new C4String(path))
     using(var viewName_ = new C4String(viewName))
     using(var version_ = new C4String(version)) {
         return c4view_open(db, path_.AsC4Slice(), viewName_.AsC4Slice(), version_.AsC4Slice(), flags, encryptionKey, outError);   
     }
 }
Beispiel #41
0
 /// <summary>
 /// Sets a document's docType. (By convention this is the value of the "type" property of the 
 /// current revision's JSON; this value can be used as optimization when indexing a view.)
 /// The change will not be persisted until the document is saved.
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="docType">The document type to set</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4doc_setType(C4Document *doc, string docType, C4Error *outError)
 {
     using(var docType_ = new C4String(docType)) {
         return c4doc_setType(doc, docType_.AsC4Slice(), outError);   
     }
 }
Beispiel #42
0
 /// <summary>
 /// Selects a specific revision of a document (or no revision, if revID is NULL.)
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="revID">The revID of the revision to select</param>
 /// <param name="withBody">Whether or not to load the body of the revision</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4doc_selectRevision(C4Document *doc, string revID, bool withBody, C4Error *outError)
 {
     using(var revID_ = new C4String(revID)) {
         return c4doc_selectRevision(doc, revID_.AsC4Slice(), withBody, outError);
     }
 }