Skip to content

Dev #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 18, 2025
Merged

Dev #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-swift.svg?color=green&style=flat-square)
![License](https://img.shields.io/github/license/appwrite/sdk-for-swift.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.2-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.7.0-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**
**This SDK is compatible with Appwrite server version 1.7.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-swift/releases).**

> This is the Swift SDK for integrating with Appwrite from your Swift server-side code. If you're looking for the Apple SDK you should check [appwrite/sdk-for-apple](https://github.com/appwrite/sdk-for-apple)

Expand All @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies:

```swift
dependencies: [
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "9.0.0"),
.package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "10.0.0"),
],
```

Expand Down
4 changes: 2 additions & 2 deletions Sources/Appwrite/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ open class Client {
"x-sdk-name": "Swift",
"x-sdk-platform": "server",
"x-sdk-language": "swift",
"x-sdk-version": "9.0.0",
"x-appwrite-response-format": "1.6.0"
"x-sdk-version": "10.0.0",
"x-appwrite-response-format": "1.7.0"
]

internal var config: [String: String] = [:]
Expand Down
283 changes: 279 additions & 4 deletions Sources/Appwrite/Services/Databases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,6 @@ open class Databases: Service {
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
///
/// @param String databaseId
/// @param String collectionId
Expand Down Expand Up @@ -1630,7 +1629,6 @@ open class Databases: Service {
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
///
/// @param String databaseId
/// @param String collectionId
Expand All @@ -1657,6 +1655,280 @@ open class Databases: Service {
)
}

///
/// Create new Documents. Before using this route, you should create a new
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
/// @param String databaseId
/// @param String collectionId
/// @param [Any] documents
/// @throws Exception
/// @return array
///
open func createDocuments<T>(
databaseId: String,
collectionId: String,
documents: [Any],
nestedType: T.Type
) async throws -> AppwriteModels.DocumentList<T> {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
.replacingOccurrences(of: "{collectionId}", with: collectionId)

let apiParams: [String: Any?] = [
"documents": documents
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.DocumentList<T> = { response in
return AppwriteModels.DocumentList.from(map: response as! [String: Any])
}

return try await client.call(
method: "POST",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// Create new Documents. Before using this route, you should create a new
/// collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
/// @param String databaseId
/// @param String collectionId
/// @param [Any] documents
/// @throws Exception
/// @return array
///
open func createDocuments(
databaseId: String,
collectionId: String,
documents: [Any]
) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> {
return try await createDocuments(
databaseId: databaseId,
collectionId: collectionId,
documents: documents,
nestedType: [String: AnyCodable].self
)
}

///
/// Create or update Documents. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
///
/// @param String databaseId
/// @param String collectionId
/// @param [Any] documents
/// @throws Exception
/// @return array
///
open func upsertDocuments<T>(
databaseId: String,
collectionId: String,
documents: [Any]? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.DocumentList<T> {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
.replacingOccurrences(of: "{collectionId}", with: collectionId)

let apiParams: [String: Any?] = [
"documents": documents
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.DocumentList<T> = { response in
return AppwriteModels.DocumentList.from(map: response as! [String: Any])
}

return try await client.call(
method: "PUT",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// Create or update Documents. Before using this route, you should create a
/// new collection resource using either a [server
/// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection)
/// API or directly from your database console.
///
///
/// @param String databaseId
/// @param String collectionId
/// @param [Any] documents
/// @throws Exception
/// @return array
///
open func upsertDocuments(
databaseId: String,
collectionId: String,
documents: [Any]? = nil
) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> {
return try await upsertDocuments(
databaseId: databaseId,
collectionId: collectionId,
documents: documents,
nestedType: [String: AnyCodable].self
)
}

///
/// Update all documents that match your queries, if no queries are submitted
/// then all documents are updated. You can pass only specific fields to be
/// updated.
///
/// @param String databaseId
/// @param String collectionId
/// @param Any data
/// @param [String] queries
/// @throws Exception
/// @return array
///
open func updateDocuments<T>(
databaseId: String,
collectionId: String,
data: Any? = nil,
queries: [String]? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.DocumentList<T> {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
.replacingOccurrences(of: "{collectionId}", with: collectionId)

let apiParams: [String: Any?] = [
"data": data,
"queries": queries
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.DocumentList<T> = { response in
return AppwriteModels.DocumentList.from(map: response as! [String: Any])
}

return try await client.call(
method: "PATCH",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// Update all documents that match your queries, if no queries are submitted
/// then all documents are updated. You can pass only specific fields to be
/// updated.
///
/// @param String databaseId
/// @param String collectionId
/// @param Any data
/// @param [String] queries
/// @throws Exception
/// @return array
///
open func updateDocuments(
databaseId: String,
collectionId: String,
data: Any? = nil,
queries: [String]? = nil
) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> {
return try await updateDocuments(
databaseId: databaseId,
collectionId: collectionId,
data: data,
queries: queries,
nestedType: [String: AnyCodable].self
)
}

///
/// Bulk delete documents using queries, if no queries are passed then all
/// documents are deleted.
///
/// @param String databaseId
/// @param String collectionId
/// @param [String] queries
/// @throws Exception
/// @return array
///
open func deleteDocuments<T>(
databaseId: String,
collectionId: String,
queries: [String]? = nil,
nestedType: T.Type
) async throws -> AppwriteModels.DocumentList<T> {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/documents"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
.replacingOccurrences(of: "{collectionId}", with: collectionId)

let apiParams: [String: Any?] = [
"queries": queries
]

let apiHeaders: [String: String] = [
"content-type": "application/json"
]

let converter: (Any) -> AppwriteModels.DocumentList<T> = { response in
return AppwriteModels.DocumentList.from(map: response as! [String: Any])
}

return try await client.call(
method: "DELETE",
path: apiPath,
headers: apiHeaders,
params: apiParams,
converter: converter
)
}

///
/// Bulk delete documents using queries, if no queries are passed then all
/// documents are deleted.
///
/// @param String databaseId
/// @param String collectionId
/// @param [String] queries
/// @throws Exception
/// @return array
///
open func deleteDocuments(
databaseId: String,
collectionId: String,
queries: [String]? = nil
) async throws -> AppwriteModels.DocumentList<[String: AnyCodable]> {
return try await deleteDocuments(
databaseId: databaseId,
collectionId: collectionId,
queries: queries,
nestedType: [String: AnyCodable].self
)
}

///
/// Get a document by its unique ID. This endpoint response returns a JSON
/// object with the document data.
Expand Down Expand Up @@ -1881,6 +2153,7 @@ open class Databases: Service {
/// @param AppwriteEnums.IndexType type
/// @param [String] attributes
/// @param [String] orders
/// @param [Int] lengths
/// @throws Exception
/// @return array
///
Expand All @@ -1890,7 +2163,8 @@ open class Databases: Service {
key: String,
type: AppwriteEnums.IndexType,
attributes: [String],
orders: [String]? = nil
orders: [String]? = nil,
lengths: [Int]? = nil
) async throws -> AppwriteModels.Index {
let apiPath: String = "/databases/{databaseId}/collections/{collectionId}/indexes"
.replacingOccurrences(of: "{databaseId}", with: databaseId)
Expand All @@ -1900,7 +2174,8 @@ open class Databases: Service {
"key": key,
"type": type,
"attributes": attributes,
"orders": orders
"orders": orders,
"lengths": lengths
]

let apiHeaders: [String: String] = [
Expand Down
Loading