AllDatabaseDocuments

public struct AllDatabaseDocuments

A struct representing the JSON returned when querying a Database or View. If includeDocuments was true for the query, each row will have an additional doc field containing the JSON document. These documents can then be decoded to a given Swift type using decodeDocuments(ofType:).

CouchDB reference: All_Database_Documents

Usage Example:

struct MyDocument: Document {
    let _id: String?
    var _rev: String?
    var value: String
}
database.retrieveAll(includeDocuments: true) { (allDocs, error) in
    if let allDocs = allDocs,
       let decodedDocs = allDocs.decodeDocuments(ofType: MyDocument)
    {
        for doc in decodedDocs {
           print("Retrieved MyDocument with value: \(doc.value)")
        }
    }
}
  • Number of documents in the database/view.

    Declaration

    Swift

    public let total_rows: Int?
  • Offset where the document list started

    Declaration

    Swift

    public let offset: Int?
  • Current update sequence for the database.

    Declaration

    Swift

    public let update_seq: String?
  • The JSON response from a request to the view endpoint. Each element of the array contains an id, key and value field. If include_docs was true, also contains the corresponding Document inside the doc field. http://docs.couchdb.org/en/stable/api/ddoc/views.html#api-ddoc-view

    Declaration

    Swift

    public let rows: [[String: Any]]
  • This function iterates through the AllDatabaseDocuments rows and returns the documents that could be successfully decoded as the given type. If the includeDocuments query parameter was false, this will return an empty array.

    Declaration

    Swift

    public func decodeDocuments<T: Document>(ofType: T.Type) -> [T]