Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## v1.0.0

* Breaking: Activate parameter was removed from CreateDeployment; use WithCreateDeploymentActivate.
* Breaking: UpdateRelationshipAttribute API path changed and old overload removed.
* Added: GetConsolePausing endpoint to monitor console pausing status.
* Added: TTL option to list operations for documents and rows.
* Updated: Document and Row sequence comments to reflect sequence IDs.

## 0.17.0

* Added new Activities service to the Go SDK with a NewActivities constructor to access Activities endpoints.
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ type Client struct {
func New(optionalSetters ...ClientOption) Client {
headers := map[string]string{
"X-Appwrite-Response-Format" : "1.8.0",
"user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.17.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"user-agent" : fmt.Sprintf("AppwriteGoSDK/v1.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH),
"x-sdk-name": "Go",
"x-sdk-platform": "server",
"x-sdk-language": "go",
"x-sdk-version": "v0.17.0",
"x-sdk-version": "v1.0.0",
}
httpClient, err := GetDefaultClient(defaultTimeout)
if err != nil {
Expand Down
163 changes: 87 additions & 76 deletions databases/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -2949,6 +2949,82 @@ func (srv *Databases) CreateRelationshipAttribute(DatabaseId string, CollectionI
}
return &parsed, nil

}
type UpdateRelationshipAttributeOptions struct {
OnDelete string
NewKey string
enabledSetters map[string]bool
}
func (options UpdateRelationshipAttributeOptions) New() *UpdateRelationshipAttributeOptions {
options.enabledSetters = map[string]bool{
"OnDelete": false,
"NewKey": false,
}
return &options
}
type UpdateRelationshipAttributeOption func(*UpdateRelationshipAttributeOptions)
func (srv *Databases) WithUpdateRelationshipAttributeOnDelete(v string) UpdateRelationshipAttributeOption {
return func(o *UpdateRelationshipAttributeOptions) {
o.OnDelete = v
o.enabledSetters["OnDelete"] = true
}
}
func (srv *Databases) WithUpdateRelationshipAttributeNewKey(v string) UpdateRelationshipAttributeOption {
return func(o *UpdateRelationshipAttributeOptions) {
o.NewKey = v
o.enabledSetters["NewKey"] = true
}
}

// UpdateRelationshipAttribute update relationship attribute. [Learn more
// about relationship
// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes).
//
// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.updateRelationshipColumn` instead.
func (srv *Databases) UpdateRelationshipAttribute(DatabaseId string, CollectionId string, Key string, optionalSetters ...UpdateRelationshipAttributeOption)(*models.AttributeRelationship, error) {
r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key)
path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/relationship/{key}")
options := UpdateRelationshipAttributeOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["databaseId"] = DatabaseId
params["collectionId"] = CollectionId
params["key"] = Key
if options.enabledSetters["OnDelete"] {
params["onDelete"] = options.OnDelete
}
if options.enabledSetters["NewKey"] {
params["newKey"] = options.NewKey
}
headers := map[string]interface{}{
"content-type": "application/json",
}

resp, err := srv.client.Call("PATCH", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.AttributeRelationship{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.AttributeRelationship
parsed, ok := resp.Result.(models.AttributeRelationship)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
type CreateStringAttributeOptions struct {
Default string
Expand Down Expand Up @@ -3637,94 +3713,20 @@ func (srv *Databases) DeleteAttribute(DatabaseId string, CollectionId string, Ke
}
return &parsed, nil

}
type UpdateRelationshipAttributeOptions struct {
OnDelete string
NewKey string
enabledSetters map[string]bool
}
func (options UpdateRelationshipAttributeOptions) New() *UpdateRelationshipAttributeOptions {
options.enabledSetters = map[string]bool{
"OnDelete": false,
"NewKey": false,
}
return &options
}
type UpdateRelationshipAttributeOption func(*UpdateRelationshipAttributeOptions)
func (srv *Databases) WithUpdateRelationshipAttributeOnDelete(v string) UpdateRelationshipAttributeOption {
return func(o *UpdateRelationshipAttributeOptions) {
o.OnDelete = v
o.enabledSetters["OnDelete"] = true
}
}
func (srv *Databases) WithUpdateRelationshipAttributeNewKey(v string) UpdateRelationshipAttributeOption {
return func(o *UpdateRelationshipAttributeOptions) {
o.NewKey = v
o.enabledSetters["NewKey"] = true
}
}

// UpdateRelationshipAttribute update relationship attribute. [Learn more
// about relationship
// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes).
//
// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.updateRelationshipColumn` instead.
func (srv *Databases) UpdateRelationshipAttribute(DatabaseId string, CollectionId string, Key string, optionalSetters ...UpdateRelationshipAttributeOption)(*models.AttributeRelationship, error) {
r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key)
path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship")
options := UpdateRelationshipAttributeOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
params["databaseId"] = DatabaseId
params["collectionId"] = CollectionId
params["key"] = Key
if options.enabledSetters["OnDelete"] {
params["onDelete"] = options.OnDelete
}
if options.enabledSetters["NewKey"] {
params["newKey"] = options.NewKey
}
headers := map[string]interface{}{
"content-type": "application/json",
}

resp, err := srv.client.Call("PATCH", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.AttributeRelationship{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.AttributeRelationship
parsed, ok := resp.Result.(models.AttributeRelationship)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}
type ListDocumentsOptions struct {
Queries []string
TransactionId string
Total bool
Ttl int
enabledSetters map[string]bool
}
func (options ListDocumentsOptions) New() *ListDocumentsOptions {
options.enabledSetters = map[string]bool{
"Queries": false,
"TransactionId": false,
"Total": false,
"Ttl": false,
}
return &options
}
Expand All @@ -3747,6 +3749,12 @@ func (srv *Databases) WithListDocumentsTotal(v bool) ListDocumentsOption {
o.enabledSetters["Total"] = true
}
}
func (srv *Databases) WithListDocumentsTtl(v int) ListDocumentsOption {
return func(o *ListDocumentsOptions) {
o.Ttl = v
o.enabledSetters["Ttl"] = true
}
}

// ListDocuments get a list of all the user's documents in a given collection.
// You can use the query params to filter your results.
Expand All @@ -3771,6 +3779,9 @@ func (srv *Databases) ListDocuments(DatabaseId string, CollectionId string, opti
if options.enabledSetters["Total"] {
params["total"] = options.Total
}
if options.enabledSetters["Ttl"] {
params["ttl"] = options.Ttl
}
headers := map[string]interface{}{
}

Expand Down
1 change: 1 addition & 0 deletions docs/examples/databases/list-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ response, error := service.ListDocuments(
databases.WithListDocumentsQueries([]interface{}{}),
databases.WithListDocumentsTransactionId("<TRANSACTION_ID>"),
databases.WithListDocumentsTotal(false),
databases.WithListDocumentsTtl(0),
)
```
22 changes: 22 additions & 0 deletions docs/examples/health/get-console-pausing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
```go
package main

import (
"fmt"
"github.com/appwrite/sdk-for-go/client"
"github.com/appwrite/sdk-for-go/health"
)

client := client.New(
client.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1")
client.WithProject("<YOUR_PROJECT_ID>")
client.WithKey("<YOUR_API_KEY>")
)

service := health.New(client)

response, error := service.GetConsolePausing(
health.WithGetConsolePausingThreshold(0),
health.WithGetConsolePausingInactivityDays(0),
)
```
2 changes: 1 addition & 1 deletion docs/examples/sites/create-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ service := sites.New(client)
response, error := service.CreateDeployment(
"<SITE_ID>",
file.NewInputFile("/path/to/file.png", "file.png"),
false,
sites.WithCreateDeploymentInstallCommand("<INSTALL_COMMAND>"),
sites.WithCreateDeploymentBuildCommand("<BUILD_COMMAND>"),
sites.WithCreateDeploymentOutputDirectory("<OUTPUT_DIRECTORY>"),
sites.WithCreateDeploymentActivate(false),
)
```
1 change: 1 addition & 0 deletions docs/examples/tablesdb/list-rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ response, error := service.ListRows(
tablesdb.WithListRowsQueries([]interface{}{}),
tablesdb.WithListRowsTransactionId("<TRANSACTION_ID>"),
tablesdb.WithListRowsTotal(false),
tablesdb.WithListRowsTtl(0),
)
```
69 changes: 69 additions & 0 deletions health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,75 @@ func (srv *Health) GetCertificate(optionalSetters ...GetCertificateOption)(*mode
}
return &parsed, nil

}
type GetConsolePausingOptions struct {
Threshold int
InactivityDays int
enabledSetters map[string]bool
}
func (options GetConsolePausingOptions) New() *GetConsolePausingOptions {
options.enabledSetters = map[string]bool{
"Threshold": false,
"InactivityDays": false,
}
return &options
}
type GetConsolePausingOption func(*GetConsolePausingOptions)
func (srv *Health) WithGetConsolePausingThreshold(v int) GetConsolePausingOption {
return func(o *GetConsolePausingOptions) {
o.Threshold = v
o.enabledSetters["Threshold"] = true
}
}
func (srv *Health) WithGetConsolePausingInactivityDays(v int) GetConsolePausingOption {
return func(o *GetConsolePausingOptions) {
o.InactivityDays = v
o.enabledSetters["InactivityDays"] = true
}
}

// GetConsolePausing get console pausing health status. Monitors projects
// approaching the pause threshold to detect potential issues with console
// access tracking.
func (srv *Health) GetConsolePausing(optionalSetters ...GetConsolePausingOption)(*models.HealthStatus, error) {
path := "/health/console-pausing"
options := GetConsolePausingOptions{}.New()
for _, opt := range optionalSetters {
opt(options)
}
params := map[string]interface{}{}
if options.enabledSetters["Threshold"] {
params["threshold"] = options.Threshold
}
if options.enabledSetters["InactivityDays"] {
params["inactivityDays"] = options.InactivityDays
}
headers := map[string]interface{}{
}

resp, err := srv.client.Call("GET", path, headers, params)
if err != nil {
return nil, err
}
if strings.HasPrefix(resp.Type, "application/json") {
bytes := []byte(resp.Result.(string))

parsed := models.HealthStatus{}.New(bytes)

err = json.Unmarshal(bytes, parsed)
if err != nil {
return nil, err
}

return parsed, nil
}
var parsed models.HealthStatus
parsed, ok := resp.Result.(models.HealthStatus)
if !ok {
return nil, errors.New("unexpected response type")
}
return &parsed, nil

}

// GetDB check the Appwrite database servers are up and connection is
Expand Down
2 changes: 1 addition & 1 deletion models/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Document struct {
// Document ID.
Id string `json:"$id"`
// Document automatically incrementing ID.
// Document sequence ID.
Sequence int `json:"$sequence"`
// Collection ID.
CollectionId string `json:"$collectionId"`
Expand Down
2 changes: 1 addition & 1 deletion models/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type Row struct {
// Row ID.
Id string `json:"$id"`
// Row automatically incrementing ID.
// Row sequence ID.
Sequence int `json:"$sequence"`
// Table ID.
TableId string `json:"$tableId"`
Expand Down
Loading