一个用于 Cloudant 和 CouchDB 的 Swift 语言客户端
注意,2023年6月22日
该框架位于 @IBM 组织下的这个仓库中,但它是从原始来源派生的分支。
这个框架将在中期/长期内维护,但仅由热衷于该项目并希望在空闲时间从事该项目的工作的 IBM 员工尽最大努力维护。
请不要联系 @Cloudant 咨询此仓库。 也不要联系任何以前的维护者。 Cloudant 团队与此仓库没有任何联系,无法提供任何帮助或支持。
应用程序使用 swift-cloudant 在 Cloudant 或 CouchDB 上存储、索引和查询远程 JSON 数据。
Swift-Cloudant 是用 Swift 编写的 Apache CouchDB™ 客户端。 它由 Cloudant 构建,并根据 Apache 2.0 许可证提供。
这是该库的早期版本,支持以下操作
我们将在未来的版本中完善功能集。
目前不支持从 Objective-C 调用。
SwiftCloudant
受到支持,但由于它是早期版本,因此基于“尽最大努力”。
目前 Swift Cloudant 支持
Swift 版本
平台
Swift Cloudant 在以下平台上不受支持
SwiftCloudant 可通过 Swift Package Manager 和 CocoaPods 获得。
要与 CocoaPods 一起使用,请将以下行添加到您的 Podfile
pod 'SwiftCloudant', :git => 'https://github.com/cloudant/swift-cloudant.git'
要与 swift package manager 一起使用,请将以下行添加到您的 Package.swift 中的依赖项中
.Package(url: "https://github.com/cloudant/swift-cloudant.git")
import SwiftCloudant
// Create a CouchDBClient
let cloudantURL = URL(string:"https://username.cloudant.com")!
let client = CouchDBClient(url:cloudantURL, username:"username", password:"password")
let dbName = "database"
// Create a document
let create = PutDocumentOperation(id: "doc1", body: ["hello":"world"], databaseName: dbName) {(response, httpInfo, error) in
if let error = error as? SwiftCloudant.Operation.Error {
switch error {
case .http(let httpError):
print("http error status code: \(httpError.statusCode) response: \(httpError.response)")
default:
print("Encountered an error while creating a document. Error:\(error)")
}
} else {
print("Created document \(response?["id"]) with revision id \(response?["rev"])")
}
}
client.add(operation:create)
// create an attachment
let attachment = "This is my awesome essay attachment for my document"
let putAttachment = PutAttachmentOperation(name: "myAwesomeAttachment",
contentType: "text/plain",
data: attachment.data(using: String.Encoding.utf8, allowLossyConversion: false)!,
documentID: "doc1",
revision: "1-revisionidhere",
databaseName: dbName) { (response, info, error) in
if let error = error {
print("Encountered an error while creating an attachment. Error:\(error)")
} else {
print("Created attachment \(response?["id"]) with revision id \(response?["rev"])")
}
}
client.add(operation: putAttachment)
// Read a document
let read = GetDocumentOperation(id: "doc1", databaseName: dbName) { (response, httpInfo, error) in
if let error = error {
print("Encountered an error while reading a document. Error:\(error)")
} else {
print("Read document: \(response)")
}
}
client.add(operation:read)
// Delete a document
let delete = DeleteDocumentOperation(id: "doc1",
revision: "1-revisionidhere",
databaseName: dbName) { (response, httpInfo, error) in
if let error = error {
print("Encountered an error while deleting a document. Error: \(error)")
} else {
print("Document deleted")
}
}
client.add(operation:delete)
目前没有第三方依赖项。
请参阅 CONTRIBUTORS。
请参阅 CONTRIBUTING。
请参阅 LICENSE