Skip to content

Commit 74927f4

Browse files
added compact() to CouchDbDatabase
1 parent cf37788 commit 74927f4

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

couchdb/src/main/java/me/retrodaredevil/couchdbjava/CouchDbDatabase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ default String getCurrentRevision(String id) throws CouchDbException {
131131
return deleteAttachment(documentId, attachmentName, documentRevision, false);
132132
}
133133

134+
void compact() throws CouchDbException;
135+
134136
// TODO implement:
135137
// _local_docs: https://docs.couchdb.org/en/stable/api/local.html#db-local-docs
136138
// _local/id: https://docs.couchdb.org/en/stable/api/local.html#db-local-id

couchdb/src/main/java/me/retrodaredevil/couchdbjava/okhttp/CouchDbDatabaseService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Call<DocumentResponse.Body> deleteAttachment(
119119
* https://docs.couchdb.org/en/stable/api/database/compact.html
120120
* https://docs.couchdb.org/en/stable/maintenance/compaction.html#database-compaction
121121
*/
122+
@Headers({"Content-Type: application/json"})
122123
@POST("_compact")
123124
Call<SimpleStatus> compact();
124125

couchdb/src/main/java/me/retrodaredevil/couchdbjava/okhttp/OkHttpCouchDbDatabase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ public boolean isOneShot() {
479479
return instance.executeAndHandle(service.deleteAttachment(documentId, attachmentName, documentRevision, batchString), OkHttpCouchDbDatabase::transformDocumentResponseOptionalETag);
480480
}
481481

482+
@Override
483+
public void compact() throws CouchDbException {
484+
instance.preAuthorize();
485+
instance.executeAndHandle(service.compact());
486+
}
487+
482488
// endregion
483489

484490
private class OkHttpCouchDbShared implements CouchDbShared {

couchdb/src/test/java/me/retrodaredevil/couchdbjava/integration/test/DocumentUpdateTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void test(DatabaseService databaseService) throws CouchDbException, IOException
109109
} else if (databaseService == DatabaseService.POUCHDB) {
110110
assertThrows(UnsupportedOperationException.class, () -> database.getCurrentRevision(documentId));
111111
}
112+
113+
// test database compacting here since we have a couple of revisions
114+
database.compact();
112115
}
113116

114117
}

0 commit comments

Comments
 (0)