Hello.
I am having some issues getting couch base lite to work.
I am using this setup in my controllers and classes:
// creates the manager object
- (BOOL) createTheManager {
// create a shared instance of CBLManager
_manager = [CBLManager sharedInstance];
if (!_manager) {
NSLog (@"Cannot create shared instance of CBLManager");
return NO;
}
NSLog (@"Manager created");
return YES;
}
- (BOOL) isDatabaseCreated : (NSString *) name {
// create a database
if (![self createTheDatabase : name]) return NO;
return YES;
}
// creates the database
- (BOOL) createTheDatabase : (NSString *) name {
NSError *error;
// create a name for the database and make sure the name is legal
NSString *dbname = name;
if (![CBLManager isValidDatabaseName: dbname]) {
NSLog (@"Bad database name");
return NO;
}
// create a new database
_database = [_manager databaseNamed: dbname error: &error];
if (!_database) {
NSLog (@"database error . Error message: %@", error.localizedDescription);
return NO;
}
// log the database location
NSString *databaseLocation = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingString: @"/Library/Application Support/CouchbaseLite"];
NSLog(@"Database %@ created at %@", dbname, [NSString stringWithFormat:@"%@/%@%@", databaseLocation, dbname, @".cblite"]);
return YES;
}
This is how I am using the code once I make an instance of the database:
- (void)insert:(NSString *)name isCurrent:(BOOL)isCurrent
{
NSError *error;
CBLQuery *query = [[_database viewNamed:@"test"] createQuery];
[query setStartKey: name];
CBLQueryEnumerator *result = [query run:nil];
NSNumber *total = [[result rowAtIndex:0] value];
if(total == 0)
{
// add item
NSMutableDictionary *item = [NSMutableDictionary new];
item[@"name"] = name;
item[@"isCurrent"] = [NSNumber numberWithBool:isCurrent];
// Create an empty document
CBLDocument *doc = [_database documentWithID: name];
// Save the ID of the new document
NSString *docID = doc.documentID;
// Write the document to the database
CBLRevision *newRevision = [doc putProperties:course error:
&error];
if (newRevision) {
NSLog(@"Document created and written to database, ID = %@", docID);
}
else
{
// retrieve the document from the database
CBLDocument *retrievedDoc = [_database documentWithID: @"Burgers"];
// display the retrieved document
NSLog(@"The retrieved document contains: %@", retrievedDoc.properties);
}
}
}
I need to know what I am doing wrong here and I want to have two databases open at the same time “test” and “test2”, how would I do that so I wouldnt get a concurrent issue?