Couchbase Lite
Objective-C API for iOS and Mac OS
CBLDatabase.h
Go to the documentation of this file.
1 //
2 // CBLDatabase.h
3 // CouchbaseLite
4 //
5 // Created by Pasin Suriyentrakorn on 12/15/16.
6 // Copyright © 2016 Couchbase. All rights reserved.
7 //
8 
9 #import <Foundation/Foundation.h>
10 @class CBLDocument, CBLQuery;
11 @protocol CBLConflictResolver;
12 
13 NS_ASSUME_NONNULL_BEGIN
14 
15 extern NSString* const kCBLDatabaseChangeNotification;
16 extern NSString* const kCBLDatabaseChangesUserInfoKey;
17 extern NSString* const kCBLDatabaseLastSequenceUserInfoKey;
18 extern NSString* const kCBLDatabaseIsExternalUserInfoKey;
19 
20 
22 typedef NS_ENUM(uint32_t, CBLIndexType) {
23  kCBLValueIndex,
24  kCBLFullTextIndex,
25  kCBLGeoIndex,
26 };
27 
28 
30 typedef struct {
31  const char * _Nullable language;
32  BOOL ignoreDiacritics;
36 
37 
39 @interface CBLDatabaseOptions : NSObject <NSCopying>
40 
45 @property (nonatomic, copy, nullable) NSString* directory;
46 
54 @property (nonatomic) NSDataWritingOptions fileProtection;
55 
65 @property (nonatomic, strong, nullable) id encryptionKey;
66 
68 @property (nonatomic) BOOL readOnly;
69 
71 + (instancetype) defaultOptions;
72 
73 @end
74 
75 
77 @interface CBLDatabase : NSObject
78 
80 @property (readonly, nonatomic) NSString* name;
81 
83 @property (readonly, nonatomic, nullable) NSString* path;
84 
89 - (instancetype) initWithName: (NSString*)name
90  error: (NSError**)error;
91 
97 - (instancetype) initWithName: (NSString*)name
98  options: (nullable CBLDatabaseOptions*)options
99  error: (NSError**)error
100  NS_DESIGNATED_INITIALIZER;
101 
102 - (instancetype) init NS_UNAVAILABLE;
103 
105 - (BOOL) close: (NSError**)error;
106 
114 - (BOOL) changeEncryptionKey: (nullable id)key error: (NSError**)error;
115 
117 - (BOOL) deleteDatabase: (NSError**)error;
118 
120 + (BOOL) deleteDatabase: (NSString*)name
121  inDirectory: (nullable NSString*)directory
122  error: (NSError**)error;
123 
125 + (BOOL) databaseExists: (NSString*)name
126  inDirectory: (nullable NSString*)directory;
127 
134 - (BOOL) inBatch: (NSError**)error do: (void (^)())block;
135 
138 - (CBLDocument*) document;
139 
144 - (CBLDocument*) documentWithID: (NSString*)docID;
145 
147 - (CBLDocument*) objectForKeyedSubscript: (NSString*)docID;
148 
150 - (BOOL) documentExists: (NSString*)docID;
151 
155 @property (nonatomic, nullable) id<CBLConflictResolver> conflictResolver;
156 
157 
158 #pragma mark - QUERYING:
159 
160 
162 - (NSEnumerator<CBLDocument*>*) allDocuments;
163 
170 - (CBLQuery*) createQueryWhere: (nullable id)where;
171 
179 - (BOOL) createIndexOn: (NSArray*)expressions
180  error: (NSError**)error;
181 
191 - (BOOL) createIndexOn: (NSArray*)expressions
192  type: (CBLIndexType)type
193  options: (nullable const CBLIndexOptions*)options
194  error: (NSError**)error;
195 
201 - (BOOL) deleteIndexOn: (NSArray*)expressions
202  type: (CBLIndexType)type
203  error: (NSError**)error;
204 
205 @end
206 
207 NS_ASSUME_NONNULL_END
208 
209 // TODO:
210 // * Logging
211 // * Threading Support
NSString *const kCBLDatabaseIsExternalUserInfoKey
Options for opening a database.
Definition: CBLDatabase.h:39
typedef NS_ENUM(uint32_t, CBLIndexType)
Types of database indexes.
Definition: CBLDatabase.h:22
A Couchbase Lite database.
Definition: CBLDatabase.h:77
NSString *const kCBLDatabaseChangesUserInfoKey
A compiled database query.
Definition: CBLQuery.h:22
A Couchbase Lite document.
Definition: CBLDocument.h:36
NSString *const kCBLDatabaseLastSequenceUserInfoKey
NS_ASSUME_NONNULL_BEGIN NSString *const kCBLDatabaseChangeNotification
Abstract interface for an application-defined object that can resolve a conflict between two revision...
Definition: CBLConflictResolver.h:18
const char *_Nullable language
Full-text: Language code, e.g.
Definition: CBLDatabase.h:31
Options for creating a database index.
Definition: CBLDatabase.h:30