Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added -[CouchDatabase purgeDocuments:]

  • Loading branch information...
commit 7b60e2b217ddb9ca5f7a0cf7a4cec54596438cd4 1 parent cb2c132
Jens Alfke snej authored
4 Couch/CouchDatabase.h
View
@@ -101,6 +101,10 @@ typedef NSString* (^CouchDocumentPathMap)(NSString* documentID);
/** Deletes the given documents. */
- (RESTOperation*) deleteDocuments: (NSArray*)documents;
+/** Purges the given documents from the database; this isn't deletion, more like forgetting entirely about them.
+ @documents Array of CouchDocument objects or document IDs (NSStrings). */
+- (RESTOperation*) purgeDocuments: (NSArray*)documents;
+
/** Empties the cache of recently used CouchDocument objects.
API calls will now instantiate and return new instances. */
- (void) clearDocumentCache;
22 Couch/CouchDatabase.m
View
@@ -99,11 +99,9 @@ - (BOOL) ensureCreated: (NSError**)outError {
- (RESTOperation*) compact {
// http://wiki.apache.org/couchdb/Compaction
- CouchResource* rsrc = [[[CouchResource alloc] initWithParent: self relativePath: @"_compact"]
- autorelease];
NSDictionary* params = [NSDictionary dictionaryWithObject: @"application/json"
forKey: @"Content-Type"];
- return [[rsrc POST: nil parameters: params] start];
+ return [[[self childWithPath: @"_compact"] POST: nil parameters: params] start];
}
@@ -201,10 +199,8 @@ - (RESTOperation*) putChanges: (NSArray*)properties toRevisions: (NSArray*)revis
}
NSDictionary* body = [NSDictionary dictionaryWithObject: entries forKey: @"docs"];
- RESTResource* bulkDocs = [[[RESTResource alloc] initWithParent: self
- relativePath: @"_bulk_docs"] autorelease];
[self beginDocumentOperation: self];
- RESTOperation* op = [bulkDocs POSTJSON: body parameters: nil];
+ RESTOperation* op = [[self childWithPath: @"_bulk_docs"] POSTJSON: body parameters: nil];
[op onCompletion: ^{
if (op.isSuccessful) {
NSArray* responses = $castIf(NSArray, op.responseBody.fromJSON);
@@ -245,6 +241,20 @@ - (RESTOperation*) deleteDocuments: (NSArray*)documents {
}
+- (RESTOperation*) purgeDocuments: (NSArray*)documents {
+ NSMutableDictionary* param = [NSMutableDictionary dictionary];
+ for (id doc in documents) {
+ NSString* docID;
+ if ([doc isKindOfClass: [NSString class]])
+ docID = doc;
+ else
+ docID = ((CouchDocument*)doc).documentID;
+ [param setObject: [NSMutableArray arrayWithObject: @"*"] forKey: docID];
+ }
+ return [[self childWithPath: @"_purge"] POSTJSON: param parameters: nil];
+}
+
+
- (void) beginDocumentOperation: (CouchResource*)resource {
if (!_busyDocuments)
_busyDocuments = [[NSCountedSet alloc] init];
4 Couch/CouchResource.h
View
@@ -27,4 +27,8 @@ extern NSString* const kCouchDBErrorDomain;
/** The owning database. */
@property (readonly) CouchDatabase* database;
+/** Returns a CouchResource object with the given relative path from the receiver.
+ (This will always be an instance of CouchResource, not something more specific like CouchDocument. This is a convenience to reach API endpoints like _bulk_docs or _purge that aren't part of the regular object model. */
+- (CouchResource*) childWithPath: (NSString*)relativePath;
+
@end
5 Couch/CouchResource.m
View
@@ -29,6 +29,11 @@ - (CouchDatabase*) database {
}
+- (CouchResource*) childWithPath: (NSString*)relativePath {
+ return [[[CouchResource alloc] initWithParent: self relativePath: relativePath] autorelease];
+}
+
+
- (NSError*) operation: (RESTOperation*)op willCompleteWithError: (NSError*)error {
error = [super operation: op willCompleteWithError: error];
5 Couch/CouchServer.m
View
@@ -61,11 +61,6 @@ - (void) close {
}
-- (RESTResource*) childWithPath: (NSString*)name {
- return [[[CouchResource alloc] initWithParent: self relativePath: name] autorelease];
-}
-
-
- (CouchDatabase*) database { // Overridden from CouchResource.
return nil;
}
Please sign in to comment.
Something went wrong with that request. Please try again.