Ejemplo n.º 1
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);   
     }
 }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
        public static C4DocEnumerator* c4db_enumerateSomeDocs(C4Database *db, string[] docIDs, C4EnumeratorOptions *options,
            C4Error *outError)
        {
            var c4StringArr = docIDs.Select(x => new C4String(x)).ToArray();
            var sliceArr = c4StringArr.Select(x => x.AsC4Slice()).ToArray();
            var retVal = default(C4DocEnumerator*);
            fixed(C4Slice* ptr = sliceArr) {
                retVal = _c4db_enumerateSomeDocs(db, ptr, (uint)docIDs.Length, options, outError);
                #if DEBUG
                if(retVal != null) {
                    _AllocatedObjects[(IntPtr)retVal] = "C4DocEnumerator";
                #if ENABLE_LOGGING
                    Console.WriteLine("[c4db_enumerateSomeDocs] Allocated 0x{0}", ((IntPtr)retVal).ToString("X"));
                #endif
                }
                #endif
            }

            foreach (var c4str in c4StringArr) {
                c4str.Dispose();
            }

            return retVal;
        }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
0
 private static extern C4DocEnumerator* _c4db_enumerateAllDocs(C4Database *db, C4Slice startDocID, C4Slice endDocID, 
     C4EnumeratorOptions *options, C4Error *outError);
Ejemplo n.º 6
0
        public static C4Document* c4doc_get(C4Database *db, C4Slice docID, bool mustExist, 
            C4Error *outError)
        {
            #if DEBUG
            var retVal = _c4doc_get(db, docID, mustExist, outError);
            if(retVal != null) {
                _AllocatedObjects[(IntPtr)retVal] = "C4Document";
                #if ENABLE_LOGGING
                Console.WriteLine("[c4doc_get] Allocated 0x{0}", ((IntPtr)retVal).ToString("X"));
                #endif
            }

            return retVal;
            #else
            return _c4doc_get(db, docID, mustExist, outError);
            #endif
        }
Ejemplo n.º 7
0
 public static extern C4Document* c4doc_getBySequence(C4Database *db, ulong sequence, C4Error *outError);
Ejemplo n.º 8
0
 public static extern bool c4db_rekey(C4Database *db, C4EncryptionKey *newKey, C4Error *outError);
Ejemplo n.º 9
0
 public static extern ulong c4db_getDocumentCount(C4Database *db);
Ejemplo n.º 10
0
 /// <summary>
 /// Closes the database, deletes the file, and frees the object
 /// </summary>
 /// <param name="db">The DB object to delete</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 c4db_delete(C4Database *db, C4Error *outError)
 {
     #if DEBUG
     var ptr = (IntPtr)db;
     #if ENABLE_LOGGING
     if(ptr != IntPtr.Zero && !_AllocatedObjects.ContainsKey(ptr)) {
         Console.WriteLine("WARNING: [c4db_delete] freeing object 0x{0} that was not found in allocated list", ptr.ToString("X"));
     } else {
     #endif
         _AllocatedObjects.Remove(ptr);
     #if ENABLE_LOGGING
     }
     #endif
     #endif
     return _c4db_delete(db, outError);
 }
Ejemplo n.º 11
0
 public static extern bool c4db_compact(C4Database *db, C4Error *outError);
Ejemplo n.º 12
0
 private static extern bool _c4db_delete(C4Database *db, C4Error *outError);
Ejemplo n.º 13
0
        /// <summary>
        /// Creates an indexing task on one or more views in a database.
        /// </summary>
        /// <param name="db">The database to operate on</param>
        /// <param name="views">An array of views whose indexes should be updated in parallel.</param>
        /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
        /// <returns>A pointer to the indexer on success, otherwise null</returns>
        public static C4Indexer* c4indexer_begin(C4Database* db, C4View*[] views, C4Error* outError)
        {
            fixed(C4View** viewPtr = views) {
                #if DEBUG
                var retVal = _c4indexer_begin(db, viewPtr, views.Length, outError);
                if(retVal != null) {
                    _AllocatedObjects[(IntPtr)retVal] = "C4Indexer";
                #if ENABLE_LOGGING
                    Console.WriteLine("[c4indexer_begin] Allocated 0x{0}", ((IntPtr)retVal).ToString("X"));
                #endif
                }

                return retVal;
                #else
                return _c4indexer_begin(db, viewPtr, views.Length, outError);
                #endif
            }
        }
Ejemplo n.º 14
0
 private static extern C4Indexer* _c4indexer_begin(C4Database *db, C4View** views, int viewCount, C4Error *outError);
Ejemplo n.º 15
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);  
     }
 }
Ejemplo n.º 16
0
 public static extern ulong c4db_getLastSequence(C4Database *db);
Ejemplo n.º 17
0
 private static extern C4Document* _c4doc_get(C4Database *db, C4Slice docID, [MarshalAs(UnmanagedType.U1)]bool mustExist, 
     C4Error *outError);
Ejemplo n.º 18
0
 public static extern bool c4db_beginTransaction(C4Database *db, C4Error *outError);
Ejemplo n.º 19
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);   
     }
 }
Ejemplo n.º 20
0
 public static extern bool c4db_endTransaction(C4Database *db, [MarshalAs(UnmanagedType.U1)]bool commit, C4Error *outError);
Ejemplo n.º 21
0
 public static extern bool c4db_purgeDoc(C4Database *db, C4Slice docId, C4Error *outError);
Ejemplo n.º 22
0
 public static extern bool c4db_isInTransaction(C4Database *db);
Ejemplo n.º 23
0
 private static extern C4DocEnumerator* _c4db_enumerateChanges(C4Database* db, ulong since, C4EnumeratorOptions* options, 
     C4Error* outError);
Ejemplo n.º 24
0
 private static extern C4RawDocument* _c4raw_get(C4Database *db, C4Slice storeName, C4Slice docID, C4Error *outError);
Ejemplo n.º 25
0
        public static C4DocEnumerator* c4db_enumerateAllDocs(C4Database *db, C4Slice startDocID, C4Slice endDocID, 
            C4EnumeratorOptions *options, C4Error *outError)
        {
            #if DEBUG
            var retVal = _c4db_enumerateAllDocs(db, startDocID, endDocID, options, outError);
            if(retVal != null) {
                _AllocatedObjects[(IntPtr)retVal] = "C4DocEnumerator";
                #if ENABLE_LOGGING
                Console.WriteLine("[c4db_enumerateAllDocs] Allocated 0x{0}", ((IntPtr)retVal).ToString("X"));
                #endif
            }

            return retVal;
            #else
            return _c4db_enumerateAllDocs(db, startDocID, endDocID, options, outError);
            #endif
        }
Ejemplo n.º 26
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);
     }
 }
Ejemplo n.º 27
0
 private static extern C4DocEnumerator* _c4db_enumerateSomeDocs(C4Database *db, C4Slice* docIDs, uint docIDsCount, 
     C4EnumeratorOptions *options, C4Error *outError);
Ejemplo n.º 28
0
 public static extern bool c4raw_put(C4Database *db, C4Slice storeName, C4Slice key, C4Slice meta,
     C4Slice body, C4Error *outError);
Ejemplo n.º 29
0
 public TransactionHelper(C4Database *db)
 {
     C4Error error;
     Assert.IsTrue(Native.c4db_beginTransaction(db, &error));
     _db = db;
 }
Ejemplo n.º 30
0
        public static C4View* c4view_open(C4Database *db, C4Slice path, C4Slice viewName, C4Slice version, 
            C4DatabaseFlags flags, C4EncryptionKey *encryptionKey, C4Error *outError)
        {
            #if DEBUG
            var retVal = _c4view_open(db, path, viewName, version, flags, encryptionKey, outError);
            if(retVal != null) {
                _AllocatedObjects[(IntPtr)retVal] = "C4View";
                #if ENABLE_LOGGING
                Console.WriteLine("[c4view_open] Allocated 0x{0}", ((IntPtr)retVal).ToString("X"));
                #endif
            }

            return retVal;
            #else
            return _c4view_open(db, path, viewName, version, flags, encryptionKey, outError);
            #endif
        }