From 5174aaf011bc134775bc6c12316d1dd3d4e741d4 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Mar 2026 13:09:13 +0000 Subject: [PATCH 1/6] feat: update Go SDK to 0.18.0 * Added `NewDocumentsDB`, `NewProject`, `NewVectorsDB`, and `NewWebhooks` client constructors * Added impersonation helpers `WithImpersonateUserId`, `WithImpersonateUserEmail`, `WithImpersonateUserPhone` * Added avatar URL helpers: `GetBrowserURL`, `GetCreditCardURL`, `GetFaviconURL`, `GetFlagURL`, `GetImageURL`, `GetInitialsURL`, `GetQRURL`, `GetScreenshotURL` * Updated README badge to API version 1.9.0 --- CHANGELOG.md | 11 +- README.md | 2 +- appwrite/appwrite.go | 43 + avatars/avatars.go | 316 +++ client/client.go | 11 +- docs/examples/databases/upsert-documents.md | 2 +- .../examples/documentsdb/create-collection.md | 28 + docs/examples/documentsdb/create-document.md | 31 + docs/examples/documentsdb/create-documents.md | 23 + docs/examples/documentsdb/create-index.md | 27 + .../examples/documentsdb/create-operations.md | 32 + .../documentsdb/create-transaction.md | 21 + docs/examples/documentsdb/create.md | 23 + .../decrement-document-attribute.md | 27 + .../examples/documentsdb/delete-collection.md | 22 + docs/examples/documentsdb/delete-document.md | 24 + docs/examples/documentsdb/delete-documents.md | 24 + docs/examples/documentsdb/delete-index.md | 23 + .../documentsdb/delete-transaction.md | 21 + docs/examples/documentsdb/delete.md | 21 + docs/examples/documentsdb/get-collection.md | 22 + docs/examples/documentsdb/get-document.md | 25 + docs/examples/documentsdb/get-index.md | 23 + docs/examples/documentsdb/get-transaction.md | 21 + docs/examples/documentsdb/get.md | 21 + .../increment-document-attribute.md | 27 + docs/examples/documentsdb/list-collections.md | 24 + docs/examples/documentsdb/list-documents.md | 26 + docs/examples/documentsdb/list-indexes.md | 24 + .../examples/documentsdb/list-transactions.md | 21 + docs/examples/documentsdb/list.md | 23 + .../examples/documentsdb/update-collection.md | 26 + docs/examples/documentsdb/update-document.md | 26 + docs/examples/documentsdb/update-documents.md | 25 + .../documentsdb/update-transaction.md | 23 + docs/examples/documentsdb/update.md | 23 + docs/examples/documentsdb/upsert-document.md | 26 + docs/examples/documentsdb/upsert-documents.md | 24 + docs/examples/functions/create.md | 4 +- docs/examples/functions/update.md | 4 +- docs/examples/project/create-variable.md | 24 + docs/examples/project/delete-variable.md | 21 + docs/examples/project/get-variable.md | 21 + docs/examples/project/list-variables.md | 22 + docs/examples/project/update-variable.md | 24 + docs/examples/sites/create.md | 5 +- docs/examples/sites/update.md | 5 +- docs/examples/users/update-impersonator.md | 22 + docs/examples/vectorsdb/create-collection.md | 27 + docs/examples/vectorsdb/create-document.md | 35 + docs/examples/vectorsdb/create-documents.md | 23 + docs/examples/vectorsdb/create-index.md | 27 + docs/examples/vectorsdb/create-operations.md | 32 + .../vectorsdb/create-text-embeddings.md | 22 + docs/examples/vectorsdb/create-transaction.md | 21 + docs/examples/vectorsdb/create.md | 23 + docs/examples/vectorsdb/delete-collection.md | 22 + docs/examples/vectorsdb/delete-document.md | 24 + docs/examples/vectorsdb/delete-documents.md | 24 + docs/examples/vectorsdb/delete-index.md | 23 + docs/examples/vectorsdb/delete-transaction.md | 21 + docs/examples/vectorsdb/delete.md | 21 + docs/examples/vectorsdb/get-collection.md | 22 + docs/examples/vectorsdb/get-document.md | 25 + docs/examples/vectorsdb/get-index.md | 23 + docs/examples/vectorsdb/get-transaction.md | 21 + docs/examples/vectorsdb/get.md | 21 + docs/examples/vectorsdb/list-collections.md | 24 + docs/examples/vectorsdb/list-documents.md | 26 + docs/examples/vectorsdb/list-indexes.md | 24 + docs/examples/vectorsdb/list-transactions.md | 21 + docs/examples/vectorsdb/list.md | 23 + docs/examples/vectorsdb/update-collection.md | 27 + docs/examples/vectorsdb/update-document.md | 26 + docs/examples/vectorsdb/update-documents.md | 25 + docs/examples/vectorsdb/update-transaction.md | 23 + docs/examples/vectorsdb/update.md | 23 + docs/examples/vectorsdb/upsert-document.md | 26 + docs/examples/vectorsdb/upsert-documents.md | 24 + docs/examples/webhooks/create.md | 28 + docs/examples/webhooks/delete.md | 21 + docs/examples/webhooks/get.md | 21 + docs/examples/webhooks/list.md | 22 + docs/examples/webhooks/update-signature.md | 21 + docs/examples/webhooks/update.md | 28 + documentsdb/documents_db.go | 2051 +++++++++++++++++ functions/functions.go | 98 +- models/attribute_object.go | 49 + models/attribute_vector.go | 51 + models/document.go | 2 +- models/embedding.go | 39 + models/embedding_list.go | 35 + models/function.go | 9 +- models/log.go | 9 +- models/row.go | 2 +- models/site.go | 11 +- models/user.go | 7 + models/vectorsdb_collection.go | 61 + models/vectorsdb_collection_list.go | 35 + models/webhook.go | 57 + models/webhook_list.go | 35 + project/project.go | 298 +++ sites/sites.go | 120 +- storage/storage.go | 106 + users/users.go | 40 + vectorsdb/vectors_db.go | 1900 +++++++++++++++ webhooks/webhooks.go | 387 ++++ 107 files changed, 7554 insertions(+), 52 deletions(-) create mode 100644 docs/examples/documentsdb/create-collection.md create mode 100644 docs/examples/documentsdb/create-document.md create mode 100644 docs/examples/documentsdb/create-documents.md create mode 100644 docs/examples/documentsdb/create-index.md create mode 100644 docs/examples/documentsdb/create-operations.md create mode 100644 docs/examples/documentsdb/create-transaction.md create mode 100644 docs/examples/documentsdb/create.md create mode 100644 docs/examples/documentsdb/decrement-document-attribute.md create mode 100644 docs/examples/documentsdb/delete-collection.md create mode 100644 docs/examples/documentsdb/delete-document.md create mode 100644 docs/examples/documentsdb/delete-documents.md create mode 100644 docs/examples/documentsdb/delete-index.md create mode 100644 docs/examples/documentsdb/delete-transaction.md create mode 100644 docs/examples/documentsdb/delete.md create mode 100644 docs/examples/documentsdb/get-collection.md create mode 100644 docs/examples/documentsdb/get-document.md create mode 100644 docs/examples/documentsdb/get-index.md create mode 100644 docs/examples/documentsdb/get-transaction.md create mode 100644 docs/examples/documentsdb/get.md create mode 100644 docs/examples/documentsdb/increment-document-attribute.md create mode 100644 docs/examples/documentsdb/list-collections.md create mode 100644 docs/examples/documentsdb/list-documents.md create mode 100644 docs/examples/documentsdb/list-indexes.md create mode 100644 docs/examples/documentsdb/list-transactions.md create mode 100644 docs/examples/documentsdb/list.md create mode 100644 docs/examples/documentsdb/update-collection.md create mode 100644 docs/examples/documentsdb/update-document.md create mode 100644 docs/examples/documentsdb/update-documents.md create mode 100644 docs/examples/documentsdb/update-transaction.md create mode 100644 docs/examples/documentsdb/update.md create mode 100644 docs/examples/documentsdb/upsert-document.md create mode 100644 docs/examples/documentsdb/upsert-documents.md create mode 100644 docs/examples/project/create-variable.md create mode 100644 docs/examples/project/delete-variable.md create mode 100644 docs/examples/project/get-variable.md create mode 100644 docs/examples/project/list-variables.md create mode 100644 docs/examples/project/update-variable.md create mode 100644 docs/examples/users/update-impersonator.md create mode 100644 docs/examples/vectorsdb/create-collection.md create mode 100644 docs/examples/vectorsdb/create-document.md create mode 100644 docs/examples/vectorsdb/create-documents.md create mode 100644 docs/examples/vectorsdb/create-index.md create mode 100644 docs/examples/vectorsdb/create-operations.md create mode 100644 docs/examples/vectorsdb/create-text-embeddings.md create mode 100644 docs/examples/vectorsdb/create-transaction.md create mode 100644 docs/examples/vectorsdb/create.md create mode 100644 docs/examples/vectorsdb/delete-collection.md create mode 100644 docs/examples/vectorsdb/delete-document.md create mode 100644 docs/examples/vectorsdb/delete-documents.md create mode 100644 docs/examples/vectorsdb/delete-index.md create mode 100644 docs/examples/vectorsdb/delete-transaction.md create mode 100644 docs/examples/vectorsdb/delete.md create mode 100644 docs/examples/vectorsdb/get-collection.md create mode 100644 docs/examples/vectorsdb/get-document.md create mode 100644 docs/examples/vectorsdb/get-index.md create mode 100644 docs/examples/vectorsdb/get-transaction.md create mode 100644 docs/examples/vectorsdb/get.md create mode 100644 docs/examples/vectorsdb/list-collections.md create mode 100644 docs/examples/vectorsdb/list-documents.md create mode 100644 docs/examples/vectorsdb/list-indexes.md create mode 100644 docs/examples/vectorsdb/list-transactions.md create mode 100644 docs/examples/vectorsdb/list.md create mode 100644 docs/examples/vectorsdb/update-collection.md create mode 100644 docs/examples/vectorsdb/update-document.md create mode 100644 docs/examples/vectorsdb/update-documents.md create mode 100644 docs/examples/vectorsdb/update-transaction.md create mode 100644 docs/examples/vectorsdb/update.md create mode 100644 docs/examples/vectorsdb/upsert-document.md create mode 100644 docs/examples/vectorsdb/upsert-documents.md create mode 100644 docs/examples/webhooks/create.md create mode 100644 docs/examples/webhooks/delete.md create mode 100644 docs/examples/webhooks/get.md create mode 100644 docs/examples/webhooks/list.md create mode 100644 docs/examples/webhooks/update-signature.md create mode 100644 docs/examples/webhooks/update.md create mode 100644 documentsdb/documents_db.go create mode 100644 models/attribute_object.go create mode 100644 models/attribute_vector.go create mode 100644 models/embedding.go create mode 100644 models/embedding_list.go create mode 100644 models/vectorsdb_collection.go create mode 100644 models/vectorsdb_collection_list.go create mode 100644 models/webhook.go create mode 100644 models/webhook_list.go create mode 100644 project/project.go create mode 100644 vectorsdb/vectors_db.go create mode 100644 webhooks/webhooks.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ab6e104..644245d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,11 @@ # Change Log -## v1.0.0 +## 0.18.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. +* Added `NewDocumentsDB`, `NewProject`, `NewVectorsDB`, and `NewWebhooks` client constructors +* Added impersonation helpers `WithImpersonateUserId`, `WithImpersonateUserEmail`, `WithImpersonateUserPhone` +* Added avatar URL helpers: `GetBrowserURL`, `GetCreditCardURL`, `GetFaviconURL`, `GetFlagURL`, `GetImageURL`, `GetInitialsURL`, `GetQRURL`, `GetScreenshotURL` +* Updated README badge to API version 1.9.0 ## 0.17.0 diff --git a/README.md b/README.md index 8ad82ca3..54a69930 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Appwrite Go SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-go.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.8.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.9.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) diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index 0f2d7b9e..b34e3e7b 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -9,17 +9,21 @@ import ( "github.com/appwrite/sdk-for-go/avatars" "github.com/appwrite/sdk-for-go/backups" "github.com/appwrite/sdk-for-go/databases" + "github.com/appwrite/sdk-for-go/documentsdb" "github.com/appwrite/sdk-for-go/functions" "github.com/appwrite/sdk-for-go/graphql" "github.com/appwrite/sdk-for-go/health" "github.com/appwrite/sdk-for-go/locale" "github.com/appwrite/sdk-for-go/messaging" + "github.com/appwrite/sdk-for-go/project" "github.com/appwrite/sdk-for-go/sites" "github.com/appwrite/sdk-for-go/storage" "github.com/appwrite/sdk-for-go/tablesdb" "github.com/appwrite/sdk-for-go/teams" "github.com/appwrite/sdk-for-go/tokens" "github.com/appwrite/sdk-for-go/users" + "github.com/appwrite/sdk-for-go/vectorsdb" + "github.com/appwrite/sdk-for-go/webhooks" ) func NewAccount(clt client.Client) *account.Account { @@ -37,6 +41,9 @@ func NewBackups(clt client.Client) *backups.Backups { func NewDatabases(clt client.Client) *databases.Databases { return databases.New(clt) } +func NewDocumentsDB(clt client.Client) *documentsdb.DocumentsDB { + return documentsdb.New(clt) +} func NewFunctions(clt client.Client) *functions.Functions { return functions.New(clt) } @@ -52,6 +59,9 @@ func NewLocale(clt client.Client) *locale.Locale { func NewMessaging(clt client.Client) *messaging.Messaging { return messaging.New(clt) } +func NewProject(clt client.Client) *project.Project { + return project.New(clt) +} func NewSites(clt client.Client) *sites.Sites { return sites.New(clt) } @@ -70,6 +80,12 @@ func NewTokens(clt client.Client) *tokens.Tokens { func NewUsers(clt client.Client) *users.Users { return users.New(clt) } +func NewVectorsDB(clt client.Client) *vectorsdb.VectorsDB { + return vectorsdb.New(clt) +} +func NewWebhooks(clt client.Client) *webhooks.Webhooks { + return webhooks.New(clt) +} // NewClient initializes a new Appwrite client with a given timeout func NewClient(optionalSetters ...client.ClientOption) client.Client { @@ -167,3 +183,30 @@ func WithForwardedUserAgent(value string) client.ClientOption { return nil } } +// Helper method to construct NewClient() +// +// Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. +func WithImpersonateUserId(value string) client.ClientOption { + return func(clt *client.Client) error { + clt.Headers["X-Appwrite-Impersonate-User-Id"] = value + return nil + } +} +// Helper method to construct NewClient() +// +// Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. +func WithImpersonateUserEmail(value string) client.ClientOption { + return func(clt *client.Client) error { + clt.Headers["X-Appwrite-Impersonate-User-Email"] = value + return nil + } +} +// Helper method to construct NewClient() +// +// Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. +func WithImpersonateUserPhone(value string) client.ClientOption { + return func(clt *client.Client) error { + clt.Headers["X-Appwrite-Impersonate-User-Phone"] = value + return nil + } +} diff --git a/avatars/avatars.go b/avatars/avatars.go index 0492f3bb..4027c4de 100644 --- a/avatars/avatars.go +++ b/avatars/avatars.go @@ -4,6 +4,8 @@ import ( "encoding/json" "errors" "github.com/appwrite/sdk-for-go/client" + "net/url" + "fmt" "strings" ) @@ -107,6 +109,43 @@ func (srv *Avatars) GetBrowser(Code string, optionalSetters ...GetBrowserOption) return &parsed, nil } +// GetBrowserURL you can use this endpoint to show different browser icons to +// your users. The code argument receives the browser code as it appears in +// your user [GET +// /account/sessions](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) +// endpoint. Use width, height and quality arguments to change the output +// settings. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetBrowserURL(Code string, optionalSetters ...GetBrowserOption) (*string, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/browsers/{code}") + options := GetBrowserOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Quality"] { + q.Set("quality", fmt.Sprintf("%v", options.Quality)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetCreditCardOptions struct { Width int Height int @@ -193,6 +232,40 @@ func (srv *Avatars) GetCreditCard(Code string, optionalSetters ...GetCreditCardO return &parsed, nil } +// GetCreditCardURL the credit card endpoint will return you the icon of the +// credit card provider you need. Use width, height and quality arguments to +// change the output settings. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetCreditCardURL(Code string, optionalSetters ...GetCreditCardOption) (*string, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/credit-cards/{code}") + options := GetCreditCardOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Quality"] { + q.Set("quality", fmt.Sprintf("%v", options.Quality)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} // GetFavicon use this endpoint to fetch the favorite icon (AKA favicon) of // any remote website URL. @@ -228,6 +301,23 @@ func (srv *Avatars) GetFavicon(Url string)(*[]byte, error) { return &parsed, nil } +// GetFaviconURL use this endpoint to fetch the favorite icon (AKA favicon) of +// any remote website URL. +// +// This endpoint does not follow HTTP redirects. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetFaviconURL(Url string) (*string, error) { + path := "/avatars/favicon" + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + q.Set("url", fmt.Sprintf("%v", Url)) + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetFlagOptions struct { Width int Height int @@ -316,6 +406,42 @@ func (srv *Avatars) GetFlag(Code string, optionalSetters ...GetFlagOption)(*[]by return &parsed, nil } +// GetFlagURL you can use this endpoint to show different country flags icons +// to your users. The code argument receives the 2 letter country code. Use +// width, height and quality arguments to change the output settings. Country +// codes follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) +// standard. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetFlagURL(Code string, optionalSetters ...GetFlagOption) (*string, error) { + r := strings.NewReplacer("{code}", Code) + path := r.Replace("/avatars/flags/{code}") + options := GetFlagOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Quality"] { + q.Set("quality", fmt.Sprintf("%v", options.Quality)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetImageOptions struct { Width int Height int @@ -393,6 +519,40 @@ func (srv *Avatars) GetImage(Url string, optionalSetters ...GetImageOption)(*[]b return &parsed, nil } +// GetImageURL use this endpoint to fetch a remote image URL and crop it to +// any image size you want. This endpoint is very useful if you need to crop +// and display remote images in your app or in case you want to make sure a +// 3rd party image is properly served using a TLS protocol. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 400x400px. +// +// This endpoint does not follow HTTP redirects. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetImageURL(Url string, optionalSetters ...GetImageOption) (*string, error) { + path := "/avatars/image" + options := GetImageOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + q.Set("url", fmt.Sprintf("%v", Url)) + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetInitialsOptions struct { Name string Width int @@ -495,6 +655,49 @@ func (srv *Avatars) GetInitials(optionalSetters ...GetInitialsOption)(*[]byte, e return &parsed, nil } +// GetInitialsURL use this endpoint to show your user initials avatar icon on +// your website or app. By default, this route will try to print your +// logged-in user name or email initials. You can also overwrite the user name +// if you pass the 'name' parameter. If no name is given and no user is +// logged, an empty avatar will be returned. +// +// You can use the color and background params to change the avatar colors. By +// default, a random theme will be selected. The random theme will persist for +// the user's initials when reloading the same theme will always return for +// the same initials. +// +// When one dimension is specified and the other is 0, the image is scaled +// with preserved aspect ratio. If both dimensions are 0, the API provides an +// image at source quality. If dimensions are not specified, the default size +// of image returned is 100x100px. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetInitialsURL(optionalSetters ...GetInitialsOption) (*string, error) { + path := "/avatars/initials" + options := GetInitialsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Name"] { + q.Set("name", fmt.Sprintf("%v", options.Name)) + } + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Background"] { + q.Set("background", fmt.Sprintf("%v", options.Background)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetQROptions struct { Size int Margin int @@ -574,6 +777,34 @@ func (srv *Avatars) GetQR(Text string, optionalSetters ...GetQROption)(*[]byte, return &parsed, nil } +// GetQRURL converts a given plain text to a QR code image. You can use the +// query parameters to change the size and style of the resulting image. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetQRURL(Text string, optionalSetters ...GetQROption) (*string, error) { + path := "/avatars/qr" + options := GetQROptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + q.Set("text", fmt.Sprintf("%v", Text)) + if options.enabledSetters["Size"] { + q.Set("size", fmt.Sprintf("%v", options.Size)) + } + if options.enabledSetters["Margin"] { + q.Set("margin", fmt.Sprintf("%v", options.Margin)) + } + if options.enabledSetters["Download"] { + q.Set("download", fmt.Sprintf("%v", options.Download)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetScreenshotOptions struct { Headers interface{} ViewportWidth int @@ -838,3 +1069,88 @@ func (srv *Avatars) GetScreenshot(Url string, optionalSetters ...GetScreenshotOp return &parsed, nil } +// GetScreenshotURL use this endpoint to capture a screenshot of any website +// URL. This endpoint uses a headless browser to render the webpage and +// capture it as an image. +// +// You can configure the browser viewport size, theme, user agent, +// geolocation, permissions, and more. Capture either just the viewport or the +// full page scroll. +// +// When width and height are specified, the image is resized accordingly. If +// both dimensions are 0, the API provides an image at original size. If +// dimensions are not specified, the default viewport size is 1280x720px. +// Returns the URL for the resource instead of the content. +func (srv *Avatars) GetScreenshotURL(Url string, optionalSetters ...GetScreenshotOption) (*string, error) { + path := "/avatars/screenshots" + options := GetScreenshotOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + q.Set("url", fmt.Sprintf("%v", Url)) + if options.enabledSetters["Headers"] { + q.Set("headers", fmt.Sprintf("%v", options.Headers)) + } + if options.enabledSetters["ViewportWidth"] { + q.Set("viewportWidth", fmt.Sprintf("%v", options.ViewportWidth)) + } + if options.enabledSetters["ViewportHeight"] { + q.Set("viewportHeight", fmt.Sprintf("%v", options.ViewportHeight)) + } + if options.enabledSetters["Scale"] { + q.Set("scale", fmt.Sprintf("%v", options.Scale)) + } + if options.enabledSetters["Theme"] { + q.Set("theme", fmt.Sprintf("%v", options.Theme)) + } + if options.enabledSetters["UserAgent"] { + q.Set("userAgent", fmt.Sprintf("%v", options.UserAgent)) + } + if options.enabledSetters["Fullpage"] { + q.Set("fullpage", fmt.Sprintf("%v", options.Fullpage)) + } + if options.enabledSetters["Locale"] { + q.Set("locale", fmt.Sprintf("%v", options.Locale)) + } + if options.enabledSetters["Timezone"] { + q.Set("timezone", fmt.Sprintf("%v", options.Timezone)) + } + if options.enabledSetters["Latitude"] { + q.Set("latitude", fmt.Sprintf("%v", options.Latitude)) + } + if options.enabledSetters["Longitude"] { + q.Set("longitude", fmt.Sprintf("%v", options.Longitude)) + } + if options.enabledSetters["Accuracy"] { + q.Set("accuracy", fmt.Sprintf("%v", options.Accuracy)) + } + if options.enabledSetters["Touch"] { + q.Set("touch", fmt.Sprintf("%v", options.Touch)) + } + if options.enabledSetters["Permissions"] { + q.Set("permissions", fmt.Sprintf("%v", options.Permissions)) + } + if options.enabledSetters["Sleep"] { + q.Set("sleep", fmt.Sprintf("%v", options.Sleep)) + } + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Quality"] { + q.Set("quality", fmt.Sprintf("%v", options.Quality)) + } + if options.enabledSetters["Output"] { + q.Set("output", fmt.Sprintf("%v", options.Output)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} diff --git a/client/client.go b/client/client.go index f3373104..b7f2768e 100644 --- a/client/client.go +++ b/client/client.go @@ -73,12 +73,12 @@ type Client struct { // Initialize a new Appwrite client with a given timeout func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ - "X-Appwrite-Response-Format" : "1.8.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v1.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "X-Appwrite-Response-Format" : "1.9.0", + "user-agent" : fmt.Sprintf("AppwriteGoSDK/0.18.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v1.0.0", + "x-sdk-version": "0.18.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { @@ -125,6 +125,11 @@ func (client *Client) AddHeader(key string, value string) { client.Headers[key] = value } +// GetEndpoint returns the client's current endpoint +func (client *Client) GetEndpoint() string { + return client.Endpoint +} + func isFileUpload(headers map[string]interface{}) bool { contentType, ok := headers["content-type"].(string) if ok { diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md index 71d5a175..4424405e 100644 --- a/docs/examples/databases/upsert-documents.md +++ b/docs/examples/databases/upsert-documents.md @@ -10,7 +10,7 @@ import ( client := client.New( client.WithEndpoint("https://.cloud.appwrite.io/v1") client.WithProject("") - client.WithKey("") + client.WithSession("") ) service := databases.New(client) diff --git a/docs/examples/documentsdb/create-collection.md b/docs/examples/documentsdb/create-collection.md new file mode 100644 index 00000000..e70d6e18 --- /dev/null +++ b/docs/examples/documentsdb/create-collection.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.CreateCollection( + "", + "", + "", + documentsdb.WithCreateCollectionPermissions(interface{}{"read("any")"}), + documentsdb.WithCreateCollectionDocumentSecurity(false), + documentsdb.WithCreateCollectionEnabled(false), + documentsdb.WithCreateCollectionAttributes([]interface{}{}), + documentsdb.WithCreateCollectionIndexes([]interface{}{}), +) +``` diff --git a/docs/examples/documentsdb/create-document.md b/docs/examples/documentsdb/create-document.md new file mode 100644 index 00000000..3d9bef2f --- /dev/null +++ b/docs/examples/documentsdb/create-document.md @@ -0,0 +1,31 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.CreateDocument( + "", + "", + "", + map[string]interface{}{ + "username": "walter.obrien", + "email": "walter.obrien@example.com", + "fullName": "Walter O'Brien", + "age": 30, + "isAdmin": false + }, + documentsdb.WithCreateDocumentPermissions(interface{}{"read("any")"}), +) +``` diff --git a/docs/examples/documentsdb/create-documents.md b/docs/examples/documentsdb/create-documents.md new file mode 100644 index 00000000..aaa7ae80 --- /dev/null +++ b/docs/examples/documentsdb/create-documents.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.CreateDocuments( + "", + "", + []interface{}{}, +) +``` diff --git a/docs/examples/documentsdb/create-index.md b/docs/examples/documentsdb/create-index.md new file mode 100644 index 00000000..e76d2417 --- /dev/null +++ b/docs/examples/documentsdb/create-index.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.CreateIndex( + "", + "", + "", + "key", + []interface{}{}, + documentsdb.WithCreateIndexOrders([]interface{}{}), + documentsdb.WithCreateIndexLengths([]interface{}{}), +) +``` diff --git a/docs/examples/documentsdb/create-operations.md b/docs/examples/documentsdb/create-operations.md new file mode 100644 index 00000000..aaeae14c --- /dev/null +++ b/docs/examples/documentsdb/create-operations.md @@ -0,0 +1,32 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.CreateOperations( + "", + documentsdb.WithCreateOperationsOperations(interface{}{ + { + "action": "create", + "databaseId": "", + "collectionId": "", + "documentId": "", + "data": { + "name": "Walter O'Brien" + } + } + }), +) +``` diff --git a/docs/examples/documentsdb/create-transaction.md b/docs/examples/documentsdb/create-transaction.md new file mode 100644 index 00000000..5521a0d5 --- /dev/null +++ b/docs/examples/documentsdb/create-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.CreateTransaction( + documentsdb.WithCreateTransactionTtl(60), +) +``` diff --git a/docs/examples/documentsdb/create.md b/docs/examples/documentsdb/create.md new file mode 100644 index 00000000..d4bd107c --- /dev/null +++ b/docs/examples/documentsdb/create.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.Create( + "", + "", + documentsdb.WithCreateEnabled(false), +) +``` diff --git a/docs/examples/documentsdb/decrement-document-attribute.md b/docs/examples/documentsdb/decrement-document-attribute.md new file mode 100644 index 00000000..a4d2306f --- /dev/null +++ b/docs/examples/documentsdb/decrement-document-attribute.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.DecrementDocumentAttribute( + "", + "", + "", + "", + documentsdb.WithDecrementDocumentAttributeValue(0), + documentsdb.WithDecrementDocumentAttributeMin(0), + documentsdb.WithDecrementDocumentAttributeTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/delete-collection.md b/docs/examples/documentsdb/delete-collection.md new file mode 100644 index 00000000..80e5b0db --- /dev/null +++ b/docs/examples/documentsdb/delete-collection.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.DeleteCollection( + "", + "", +) +``` diff --git a/docs/examples/documentsdb/delete-document.md b/docs/examples/documentsdb/delete-document.md new file mode 100644 index 00000000..866134a6 --- /dev/null +++ b/docs/examples/documentsdb/delete-document.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.DeleteDocument( + "", + "", + "", + documentsdb.WithDeleteDocumentTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/delete-documents.md b/docs/examples/documentsdb/delete-documents.md new file mode 100644 index 00000000..7a60da37 --- /dev/null +++ b/docs/examples/documentsdb/delete-documents.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.DeleteDocuments( + "", + "", + documentsdb.WithDeleteDocumentsQueries([]interface{}{}), + documentsdb.WithDeleteDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/delete-index.md b/docs/examples/documentsdb/delete-index.md new file mode 100644 index 00000000..a7d84588 --- /dev/null +++ b/docs/examples/documentsdb/delete-index.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.DeleteIndex( + "", + "", + "", +) +``` diff --git a/docs/examples/documentsdb/delete-transaction.md b/docs/examples/documentsdb/delete-transaction.md new file mode 100644 index 00000000..f809346c --- /dev/null +++ b/docs/examples/documentsdb/delete-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.DeleteTransaction( + "", +) +``` diff --git a/docs/examples/documentsdb/delete.md b/docs/examples/documentsdb/delete.md new file mode 100644 index 00000000..aeeb848f --- /dev/null +++ b/docs/examples/documentsdb/delete.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.Delete( + "", +) +``` diff --git a/docs/examples/documentsdb/get-collection.md b/docs/examples/documentsdb/get-collection.md new file mode 100644 index 00000000..a8d8ee67 --- /dev/null +++ b/docs/examples/documentsdb/get-collection.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.GetCollection( + "", + "", +) +``` diff --git a/docs/examples/documentsdb/get-document.md b/docs/examples/documentsdb/get-document.md new file mode 100644 index 00000000..bed4178c --- /dev/null +++ b/docs/examples/documentsdb/get-document.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.GetDocument( + "", + "", + "", + documentsdb.WithGetDocumentQueries([]interface{}{}), + documentsdb.WithGetDocumentTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/get-index.md b/docs/examples/documentsdb/get-index.md new file mode 100644 index 00000000..6def9a71 --- /dev/null +++ b/docs/examples/documentsdb/get-index.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.GetIndex( + "", + "", + "", +) +``` diff --git a/docs/examples/documentsdb/get-transaction.md b/docs/examples/documentsdb/get-transaction.md new file mode 100644 index 00000000..bc2b00d2 --- /dev/null +++ b/docs/examples/documentsdb/get-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.GetTransaction( + "", +) +``` diff --git a/docs/examples/documentsdb/get.md b/docs/examples/documentsdb/get.md new file mode 100644 index 00000000..45a17357 --- /dev/null +++ b/docs/examples/documentsdb/get.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.Get( + "", +) +``` diff --git a/docs/examples/documentsdb/increment-document-attribute.md b/docs/examples/documentsdb/increment-document-attribute.md new file mode 100644 index 00000000..8c16ee5b --- /dev/null +++ b/docs/examples/documentsdb/increment-document-attribute.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.IncrementDocumentAttribute( + "", + "", + "", + "", + documentsdb.WithIncrementDocumentAttributeValue(0), + documentsdb.WithIncrementDocumentAttributeMax(0), + documentsdb.WithIncrementDocumentAttributeTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/list-collections.md b/docs/examples/documentsdb/list-collections.md new file mode 100644 index 00000000..132a545b --- /dev/null +++ b/docs/examples/documentsdb/list-collections.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.ListCollections( + "", + documentsdb.WithListCollectionsQueries([]interface{}{}), + documentsdb.WithListCollectionsSearch(""), + documentsdb.WithListCollectionsTotal(false), +) +``` diff --git a/docs/examples/documentsdb/list-documents.md b/docs/examples/documentsdb/list-documents.md new file mode 100644 index 00000000..729fac74 --- /dev/null +++ b/docs/examples/documentsdb/list-documents.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.ListDocuments( + "", + "", + documentsdb.WithListDocumentsQueries([]interface{}{}), + documentsdb.WithListDocumentsTransactionId(""), + documentsdb.WithListDocumentsTotal(false), + documentsdb.WithListDocumentsTtl(0), +) +``` diff --git a/docs/examples/documentsdb/list-indexes.md b/docs/examples/documentsdb/list-indexes.md new file mode 100644 index 00000000..130a37aa --- /dev/null +++ b/docs/examples/documentsdb/list-indexes.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.ListIndexes( + "", + "", + documentsdb.WithListIndexesQueries([]interface{}{}), + documentsdb.WithListIndexesTotal(false), +) +``` diff --git a/docs/examples/documentsdb/list-transactions.md b/docs/examples/documentsdb/list-transactions.md new file mode 100644 index 00000000..88ab51d8 --- /dev/null +++ b/docs/examples/documentsdb/list-transactions.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.ListTransactions( + documentsdb.WithListTransactionsQueries([]interface{}{}), +) +``` diff --git a/docs/examples/documentsdb/list.md b/docs/examples/documentsdb/list.md new file mode 100644 index 00000000..b8abf051 --- /dev/null +++ b/docs/examples/documentsdb/list.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.List( + documentsdb.WithListQueries([]interface{}{}), + documentsdb.WithListSearch(""), + documentsdb.WithListTotal(false), +) +``` diff --git a/docs/examples/documentsdb/update-collection.md b/docs/examples/documentsdb/update-collection.md new file mode 100644 index 00000000..4b7818cf --- /dev/null +++ b/docs/examples/documentsdb/update-collection.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.UpdateCollection( + "", + "", + "", + documentsdb.WithUpdateCollectionPermissions(interface{}{"read("any")"}), + documentsdb.WithUpdateCollectionDocumentSecurity(false), + documentsdb.WithUpdateCollectionEnabled(false), +) +``` diff --git a/docs/examples/documentsdb/update-document.md b/docs/examples/documentsdb/update-document.md new file mode 100644 index 00000000..d2f1e291 --- /dev/null +++ b/docs/examples/documentsdb/update-document.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.UpdateDocument( + "", + "", + "", + documentsdb.WithUpdateDocumentData(map[string]interface{}{}), + documentsdb.WithUpdateDocumentPermissions(interface{}{"read("any")"}), + documentsdb.WithUpdateDocumentTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/update-documents.md b/docs/examples/documentsdb/update-documents.md new file mode 100644 index 00000000..7f08b6e4 --- /dev/null +++ b/docs/examples/documentsdb/update-documents.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.UpdateDocuments( + "", + "", + documentsdb.WithUpdateDocumentsData(map[string]interface{}{}), + documentsdb.WithUpdateDocumentsQueries([]interface{}{}), + documentsdb.WithUpdateDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/update-transaction.md b/docs/examples/documentsdb/update-transaction.md new file mode 100644 index 00000000..1e486544 --- /dev/null +++ b/docs/examples/documentsdb/update-transaction.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.UpdateTransaction( + "", + documentsdb.WithUpdateTransactionCommit(false), + documentsdb.WithUpdateTransactionRollback(false), +) +``` diff --git a/docs/examples/documentsdb/update.md b/docs/examples/documentsdb/update.md new file mode 100644 index 00000000..5adf7265 --- /dev/null +++ b/docs/examples/documentsdb/update.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.Update( + "", + "", + documentsdb.WithUpdateEnabled(false), +) +``` diff --git a/docs/examples/documentsdb/upsert-document.md b/docs/examples/documentsdb/upsert-document.md new file mode 100644 index 00000000..5ef42be1 --- /dev/null +++ b/docs/examples/documentsdb/upsert-document.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := documentsdb.New(client) + +response, error := service.UpsertDocument( + "", + "", + "", + documentsdb.WithUpsertDocumentData(map[string]interface{}{}), + documentsdb.WithUpsertDocumentPermissions(interface{}{"read("any")"}), + documentsdb.WithUpsertDocumentTransactionId(""), +) +``` diff --git a/docs/examples/documentsdb/upsert-documents.md b/docs/examples/documentsdb/upsert-documents.md new file mode 100644 index 00000000..03ec1ff1 --- /dev/null +++ b/docs/examples/documentsdb/upsert-documents.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/documentsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := documentsdb.New(client) + +response, error := service.UpsertDocuments( + "", + "", + []interface{}{}, + documentsdb.WithUpsertDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index b75cbe83..673c84d4 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -33,6 +33,8 @@ response, error := service.Create( functions.WithCreateProviderBranch(""), functions.WithCreateProviderSilentMode(false), functions.WithCreateProviderRootDirectory(""), - functions.WithCreateSpecification(""), + functions.WithCreateBuildSpecification(""), + functions.WithCreateRuntimeSpecification(""), + functions.WithCreateDeploymentRetention(0), ) ``` diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index 2038abcc..6f89a995 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -33,6 +33,8 @@ response, error := service.Update( functions.WithUpdateProviderBranch(""), functions.WithUpdateProviderSilentMode(false), functions.WithUpdateProviderRootDirectory(""), - functions.WithUpdateSpecification(""), + functions.WithUpdateBuildSpecification(""), + functions.WithUpdateRuntimeSpecification(""), + functions.WithUpdateDeploymentRetention(0), ) ``` diff --git a/docs/examples/project/create-variable.md b/docs/examples/project/create-variable.md new file mode 100644 index 00000000..84284e72 --- /dev/null +++ b/docs/examples/project/create-variable.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.CreateVariable( + "", + "", + "", + project.WithCreateVariableSecret(false), +) +``` diff --git a/docs/examples/project/delete-variable.md b/docs/examples/project/delete-variable.md new file mode 100644 index 00000000..fd5da105 --- /dev/null +++ b/docs/examples/project/delete-variable.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.DeleteVariable( + "", +) +``` diff --git a/docs/examples/project/get-variable.md b/docs/examples/project/get-variable.md new file mode 100644 index 00000000..1a765804 --- /dev/null +++ b/docs/examples/project/get-variable.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.GetVariable( + "", +) +``` diff --git a/docs/examples/project/list-variables.md b/docs/examples/project/list-variables.md new file mode 100644 index 00000000..15657c6a --- /dev/null +++ b/docs/examples/project/list-variables.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.ListVariables( + project.WithListVariablesQueries([]interface{}{}), + project.WithListVariablesTotal(false), +) +``` diff --git a/docs/examples/project/update-variable.md b/docs/examples/project/update-variable.md new file mode 100644 index 00000000..3da119f0 --- /dev/null +++ b/docs/examples/project/update-variable.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateVariable( + "", + project.WithUpdateVariableKey(""), + project.WithUpdateVariableValue(""), + project.WithUpdateVariableSecret(false), +) +``` diff --git a/docs/examples/sites/create.md b/docs/examples/sites/create.md index a44a8d18..ba161003 100644 --- a/docs/examples/sites/create.md +++ b/docs/examples/sites/create.md @@ -25,6 +25,7 @@ response, error := service.Create( sites.WithCreateTimeout(1), sites.WithCreateInstallCommand(""), sites.WithCreateBuildCommand(""), + sites.WithCreateStartCommand(""), sites.WithCreateOutputDirectory(""), sites.WithCreateAdapter("static"), sites.WithCreateInstallationId(""), @@ -33,6 +34,8 @@ response, error := service.Create( sites.WithCreateProviderBranch(""), sites.WithCreateProviderSilentMode(false), sites.WithCreateProviderRootDirectory(""), - sites.WithCreateSpecification(""), + sites.WithCreateBuildSpecification(""), + sites.WithCreateRuntimeSpecification(""), + sites.WithCreateDeploymentRetention(0), ) ``` diff --git a/docs/examples/sites/update.md b/docs/examples/sites/update.md index 0f322edb..f20edc4e 100644 --- a/docs/examples/sites/update.md +++ b/docs/examples/sites/update.md @@ -24,6 +24,7 @@ response, error := service.Update( sites.WithUpdateTimeout(1), sites.WithUpdateInstallCommand(""), sites.WithUpdateBuildCommand(""), + sites.WithUpdateStartCommand(""), sites.WithUpdateOutputDirectory(""), sites.WithUpdateBuildRuntime("node-14.5"), sites.WithUpdateAdapter("static"), @@ -33,6 +34,8 @@ response, error := service.Update( sites.WithUpdateProviderBranch(""), sites.WithUpdateProviderSilentMode(false), sites.WithUpdateProviderRootDirectory(""), - sites.WithUpdateSpecification(""), + sites.WithUpdateBuildSpecification(""), + sites.WithUpdateRuntimeSpecification(""), + sites.WithUpdateDeploymentRetention(0), ) ``` diff --git a/docs/examples/users/update-impersonator.md b/docs/examples/users/update-impersonator.md new file mode 100644 index 00000000..0e0445f7 --- /dev/null +++ b/docs/examples/users/update-impersonator.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/users" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := users.New(client) + +response, error := service.UpdateImpersonator( + "", + false, +) +``` diff --git a/docs/examples/vectorsdb/create-collection.md b/docs/examples/vectorsdb/create-collection.md new file mode 100644 index 00000000..59e6af99 --- /dev/null +++ b/docs/examples/vectorsdb/create-collection.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateCollection( + "", + "", + "", + 1, + vectorsdb.WithCreateCollectionPermissions(interface{}{"read("any")"}), + vectorsdb.WithCreateCollectionDocumentSecurity(false), + vectorsdb.WithCreateCollectionEnabled(false), +) +``` diff --git a/docs/examples/vectorsdb/create-document.md b/docs/examples/vectorsdb/create-document.md new file mode 100644 index 00000000..0b859790 --- /dev/null +++ b/docs/examples/vectorsdb/create-document.md @@ -0,0 +1,35 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateDocument( + "", + "", + "", + map[string]interface{}{ + "embeddings": [ + 0.12, + -0.55, + 0.88, + 1.02 + ], + "metadata": { + "key": "value" + } + }, + vectorsdb.WithCreateDocumentPermissions(interface{}{"read("any")"}), +) +``` diff --git a/docs/examples/vectorsdb/create-documents.md b/docs/examples/vectorsdb/create-documents.md new file mode 100644 index 00000000..861974ec --- /dev/null +++ b/docs/examples/vectorsdb/create-documents.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateDocuments( + "", + "", + []interface{}{}, +) +``` diff --git a/docs/examples/vectorsdb/create-index.md b/docs/examples/vectorsdb/create-index.md new file mode 100644 index 00000000..5cf29cec --- /dev/null +++ b/docs/examples/vectorsdb/create-index.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateIndex( + "", + "", + "", + "hnsw_euclidean", + []interface{}{}, + vectorsdb.WithCreateIndexOrders([]interface{}{}), + vectorsdb.WithCreateIndexLengths([]interface{}{}), +) +``` diff --git a/docs/examples/vectorsdb/create-operations.md b/docs/examples/vectorsdb/create-operations.md new file mode 100644 index 00000000..4237e435 --- /dev/null +++ b/docs/examples/vectorsdb/create-operations.md @@ -0,0 +1,32 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateOperations( + "", + vectorsdb.WithCreateOperationsOperations(interface{}{ + { + "action": "create", + "databaseId": "", + "collectionId": "", + "documentId": "", + "data": { + "name": "Walter O'Brien" + } + } + }), +) +``` diff --git a/docs/examples/vectorsdb/create-text-embeddings.md b/docs/examples/vectorsdb/create-text-embeddings.md new file mode 100644 index 00000000..ec998970 --- /dev/null +++ b/docs/examples/vectorsdb/create-text-embeddings.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateTextEmbeddings( + []interface{}{}, + vectorsdb.WithCreateTextEmbeddingsModel("embeddinggemma"), +) +``` diff --git a/docs/examples/vectorsdb/create-transaction.md b/docs/examples/vectorsdb/create-transaction.md new file mode 100644 index 00000000..28e1bc7a --- /dev/null +++ b/docs/examples/vectorsdb/create-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.CreateTransaction( + vectorsdb.WithCreateTransactionTtl(60), +) +``` diff --git a/docs/examples/vectorsdb/create.md b/docs/examples/vectorsdb/create.md new file mode 100644 index 00000000..fbc2ebdd --- /dev/null +++ b/docs/examples/vectorsdb/create.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.Create( + "", + "", + vectorsdb.WithCreateEnabled(false), +) +``` diff --git a/docs/examples/vectorsdb/delete-collection.md b/docs/examples/vectorsdb/delete-collection.md new file mode 100644 index 00000000..edc10b22 --- /dev/null +++ b/docs/examples/vectorsdb/delete-collection.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.DeleteCollection( + "", + "", +) +``` diff --git a/docs/examples/vectorsdb/delete-document.md b/docs/examples/vectorsdb/delete-document.md new file mode 100644 index 00000000..c6eba01a --- /dev/null +++ b/docs/examples/vectorsdb/delete-document.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.DeleteDocument( + "", + "", + "", + vectorsdb.WithDeleteDocumentTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/delete-documents.md b/docs/examples/vectorsdb/delete-documents.md new file mode 100644 index 00000000..925b9d0b --- /dev/null +++ b/docs/examples/vectorsdb/delete-documents.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.DeleteDocuments( + "", + "", + vectorsdb.WithDeleteDocumentsQueries([]interface{}{}), + vectorsdb.WithDeleteDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/delete-index.md b/docs/examples/vectorsdb/delete-index.md new file mode 100644 index 00000000..67767694 --- /dev/null +++ b/docs/examples/vectorsdb/delete-index.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.DeleteIndex( + "", + "", + "", +) +``` diff --git a/docs/examples/vectorsdb/delete-transaction.md b/docs/examples/vectorsdb/delete-transaction.md new file mode 100644 index 00000000..e0f69c58 --- /dev/null +++ b/docs/examples/vectorsdb/delete-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.DeleteTransaction( + "", +) +``` diff --git a/docs/examples/vectorsdb/delete.md b/docs/examples/vectorsdb/delete.md new file mode 100644 index 00000000..432b05b5 --- /dev/null +++ b/docs/examples/vectorsdb/delete.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.Delete( + "", +) +``` diff --git a/docs/examples/vectorsdb/get-collection.md b/docs/examples/vectorsdb/get-collection.md new file mode 100644 index 00000000..80b7546d --- /dev/null +++ b/docs/examples/vectorsdb/get-collection.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.GetCollection( + "", + "", +) +``` diff --git a/docs/examples/vectorsdb/get-document.md b/docs/examples/vectorsdb/get-document.md new file mode 100644 index 00000000..95704a68 --- /dev/null +++ b/docs/examples/vectorsdb/get-document.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.GetDocument( + "", + "", + "", + vectorsdb.WithGetDocumentQueries([]interface{}{}), + vectorsdb.WithGetDocumentTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/get-index.md b/docs/examples/vectorsdb/get-index.md new file mode 100644 index 00000000..229ac812 --- /dev/null +++ b/docs/examples/vectorsdb/get-index.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.GetIndex( + "", + "", + "", +) +``` diff --git a/docs/examples/vectorsdb/get-transaction.md b/docs/examples/vectorsdb/get-transaction.md new file mode 100644 index 00000000..4eff8fd4 --- /dev/null +++ b/docs/examples/vectorsdb/get-transaction.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.GetTransaction( + "", +) +``` diff --git a/docs/examples/vectorsdb/get.md b/docs/examples/vectorsdb/get.md new file mode 100644 index 00000000..4ebc8208 --- /dev/null +++ b/docs/examples/vectorsdb/get.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.Get( + "", +) +``` diff --git a/docs/examples/vectorsdb/list-collections.md b/docs/examples/vectorsdb/list-collections.md new file mode 100644 index 00000000..e9911dee --- /dev/null +++ b/docs/examples/vectorsdb/list-collections.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.ListCollections( + "", + vectorsdb.WithListCollectionsQueries([]interface{}{}), + vectorsdb.WithListCollectionsSearch(""), + vectorsdb.WithListCollectionsTotal(false), +) +``` diff --git a/docs/examples/vectorsdb/list-documents.md b/docs/examples/vectorsdb/list-documents.md new file mode 100644 index 00000000..213cc08c --- /dev/null +++ b/docs/examples/vectorsdb/list-documents.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.ListDocuments( + "", + "", + vectorsdb.WithListDocumentsQueries([]interface{}{}), + vectorsdb.WithListDocumentsTransactionId(""), + vectorsdb.WithListDocumentsTotal(false), + vectorsdb.WithListDocumentsTtl(0), +) +``` diff --git a/docs/examples/vectorsdb/list-indexes.md b/docs/examples/vectorsdb/list-indexes.md new file mode 100644 index 00000000..0bb7f137 --- /dev/null +++ b/docs/examples/vectorsdb/list-indexes.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.ListIndexes( + "", + "", + vectorsdb.WithListIndexesQueries([]interface{}{}), + vectorsdb.WithListIndexesTotal(false), +) +``` diff --git a/docs/examples/vectorsdb/list-transactions.md b/docs/examples/vectorsdb/list-transactions.md new file mode 100644 index 00000000..5e99c3e2 --- /dev/null +++ b/docs/examples/vectorsdb/list-transactions.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.ListTransactions( + vectorsdb.WithListTransactionsQueries([]interface{}{}), +) +``` diff --git a/docs/examples/vectorsdb/list.md b/docs/examples/vectorsdb/list.md new file mode 100644 index 00000000..8b0cfd5c --- /dev/null +++ b/docs/examples/vectorsdb/list.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.List( + vectorsdb.WithListQueries([]interface{}{}), + vectorsdb.WithListSearch(""), + vectorsdb.WithListTotal(false), +) +``` diff --git a/docs/examples/vectorsdb/update-collection.md b/docs/examples/vectorsdb/update-collection.md new file mode 100644 index 00000000..41c76930 --- /dev/null +++ b/docs/examples/vectorsdb/update-collection.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.UpdateCollection( + "", + "", + "", + vectorsdb.WithUpdateCollectionDimension(1), + vectorsdb.WithUpdateCollectionPermissions(interface{}{"read("any")"}), + vectorsdb.WithUpdateCollectionDocumentSecurity(false), + vectorsdb.WithUpdateCollectionEnabled(false), +) +``` diff --git a/docs/examples/vectorsdb/update-document.md b/docs/examples/vectorsdb/update-document.md new file mode 100644 index 00000000..00cb38e4 --- /dev/null +++ b/docs/examples/vectorsdb/update-document.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.UpdateDocument( + "", + "", + "", + vectorsdb.WithUpdateDocumentData(map[string]interface{}{}), + vectorsdb.WithUpdateDocumentPermissions(interface{}{"read("any")"}), + vectorsdb.WithUpdateDocumentTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/update-documents.md b/docs/examples/vectorsdb/update-documents.md new file mode 100644 index 00000000..f44e9f95 --- /dev/null +++ b/docs/examples/vectorsdb/update-documents.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.UpdateDocuments( + "", + "", + vectorsdb.WithUpdateDocumentsData(map[string]interface{}{}), + vectorsdb.WithUpdateDocumentsQueries([]interface{}{}), + vectorsdb.WithUpdateDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/update-transaction.md b/docs/examples/vectorsdb/update-transaction.md new file mode 100644 index 00000000..349913b8 --- /dev/null +++ b/docs/examples/vectorsdb/update-transaction.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.UpdateTransaction( + "", + vectorsdb.WithUpdateTransactionCommit(false), + vectorsdb.WithUpdateTransactionRollback(false), +) +``` diff --git a/docs/examples/vectorsdb/update.md b/docs/examples/vectorsdb/update.md new file mode 100644 index 00000000..c4591fd4 --- /dev/null +++ b/docs/examples/vectorsdb/update.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.Update( + "", + "", + vectorsdb.WithUpdateEnabled(false), +) +``` diff --git a/docs/examples/vectorsdb/upsert-document.md b/docs/examples/vectorsdb/upsert-document.md new file mode 100644 index 00000000..0e824161 --- /dev/null +++ b/docs/examples/vectorsdb/upsert-document.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithSession("") +) + +service := vectorsdb.New(client) + +response, error := service.UpsertDocument( + "", + "", + "", + vectorsdb.WithUpsertDocumentData(map[string]interface{}{}), + vectorsdb.WithUpsertDocumentPermissions(interface{}{"read("any")"}), + vectorsdb.WithUpsertDocumentTransactionId(""), +) +``` diff --git a/docs/examples/vectorsdb/upsert-documents.md b/docs/examples/vectorsdb/upsert-documents.md new file mode 100644 index 00000000..b53f316b --- /dev/null +++ b/docs/examples/vectorsdb/upsert-documents.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/vectorsdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := vectorsdb.New(client) + +response, error := service.UpsertDocuments( + "", + "", + []interface{}{}, + vectorsdb.WithUpsertDocumentsTransactionId(""), +) +``` diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md new file mode 100644 index 00000000..14484c56 --- /dev/null +++ b/docs/examples/webhooks/create.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.Create( + "", + "", + "", + []interface{}{}, + webhooks.WithCreateEnabled(false), + webhooks.WithCreateSecurity(false), + webhooks.WithCreateHttpUser(""), + webhooks.WithCreateHttpPass(""), +) +``` diff --git a/docs/examples/webhooks/delete.md b/docs/examples/webhooks/delete.md new file mode 100644 index 00000000..c193e7b1 --- /dev/null +++ b/docs/examples/webhooks/delete.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.Delete( + "", +) +``` diff --git a/docs/examples/webhooks/get.md b/docs/examples/webhooks/get.md new file mode 100644 index 00000000..ce01f93b --- /dev/null +++ b/docs/examples/webhooks/get.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.Get( + "", +) +``` diff --git a/docs/examples/webhooks/list.md b/docs/examples/webhooks/list.md new file mode 100644 index 00000000..e2d4a851 --- /dev/null +++ b/docs/examples/webhooks/list.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.List( + webhooks.WithListQueries([]interface{}{}), + webhooks.WithListTotal(false), +) +``` diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-signature.md new file mode 100644 index 00000000..0c73804f --- /dev/null +++ b/docs/examples/webhooks/update-signature.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.UpdateSignature( + "", +) +``` diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md new file mode 100644 index 00000000..91f3f2e9 --- /dev/null +++ b/docs/examples/webhooks/update.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/webhooks" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := webhooks.New(client) + +response, error := service.Update( + "", + "", + "", + []interface{}{}, + webhooks.WithUpdateEnabled(false), + webhooks.WithUpdateSecurity(false), + webhooks.WithUpdateHttpUser(""), + webhooks.WithUpdateHttpPass(""), +) +``` diff --git a/documentsdb/documents_db.go b/documentsdb/documents_db.go new file mode 100644 index 00000000..53faff2c --- /dev/null +++ b/documentsdb/documents_db.go @@ -0,0 +1,2051 @@ +package documentsdb + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// DocumentsDB service +type DocumentsDB struct { + client client.Client +} + +func New(clt client.Client) *DocumentsDB { + return &DocumentsDB{ + client: clt, + } +} + +type ListOptions struct { + Queries []string + Search string + Total bool + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + "Total": false, + } + return &options +} +type ListOption func(*ListOptions) +func (srv *DocumentsDB) WithListQueries(v []string) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} +func (srv *DocumentsDB) WithListTotal(v bool) ListOption { + return func(o *ListOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// List get a list of all databases from the current Appwrite project. You can +// use the search parameter to filter your results. +func (srv *DocumentsDB) List(optionalSetters ...ListOption)(*models.DatabaseList, error) { + path := "/documentsdb" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.DatabaseList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DatabaseList + parsed, ok := resp.Result.(models.DatabaseList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func (srv *DocumentsDB) WithCreateEnabled(v bool) CreateOption { + return func(o *CreateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Create create a new Database. +func (srv *DocumentsDB) Create(DatabaseId string, Name string, optionalSetters ...CreateOption)(*models.Database, error) { + path := "/documentsdb" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListTransactionsOptions struct { + Queries []string + enabledSetters map[string]bool +} +func (options ListTransactionsOptions) New() *ListTransactionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListTransactionsOption func(*ListTransactionsOptions) +func (srv *DocumentsDB) WithListTransactionsQueries(v []string) ListTransactionsOption { + return func(o *ListTransactionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListTransactions +func (srv *DocumentsDB) ListTransactions(optionalSetters ...ListTransactionsOption)(*models.TransactionList, error) { + path := "/documentsdb/transactions" + options := ListTransactionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + 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.TransactionList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.TransactionList + parsed, ok := resp.Result.(models.TransactionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateTransactionOptions struct { + Ttl int + enabledSetters map[string]bool +} +func (options CreateTransactionOptions) New() *CreateTransactionOptions { + options.enabledSetters = map[string]bool{ + "Ttl": false, + } + return &options +} +type CreateTransactionOption func(*CreateTransactionOptions) +func (srv *DocumentsDB) WithCreateTransactionTtl(v int) CreateTransactionOption { + return func(o *CreateTransactionOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} + +// CreateTransaction +func (srv *DocumentsDB) CreateTransaction(optionalSetters ...CreateTransactionOption)(*models.Transaction, error) { + path := "/documentsdb/transactions" + options := CreateTransactionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetTransaction +func (srv *DocumentsDB) GetTransaction(TransactionId string)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/documentsdb/transactions/{transactionId}") + params := map[string]interface{}{} + params["transactionId"] = TransactionId + 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.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateTransactionOptions struct { + Commit bool + Rollback bool + enabledSetters map[string]bool +} +func (options UpdateTransactionOptions) New() *UpdateTransactionOptions { + options.enabledSetters = map[string]bool{ + "Commit": false, + "Rollback": false, + } + return &options +} +type UpdateTransactionOption func(*UpdateTransactionOptions) +func (srv *DocumentsDB) WithUpdateTransactionCommit(v bool) UpdateTransactionOption { + return func(o *UpdateTransactionOptions) { + o.Commit = v + o.enabledSetters["Commit"] = true + } +} +func (srv *DocumentsDB) WithUpdateTransactionRollback(v bool) UpdateTransactionOption { + return func(o *UpdateTransactionOptions) { + o.Rollback = v + o.enabledSetters["Rollback"] = true + } +} + +// UpdateTransaction +func (srv *DocumentsDB) UpdateTransaction(TransactionId string, optionalSetters ...UpdateTransactionOption)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/documentsdb/transactions/{transactionId}") + options := UpdateTransactionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["transactionId"] = TransactionId + if options.enabledSetters["Commit"] { + params["commit"] = options.Commit + } + if options.enabledSetters["Rollback"] { + params["rollback"] = options.Rollback + } + 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.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteTransaction +func (srv *DocumentsDB) DeleteTransaction(TransactionId string)(*interface{}, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/documentsdb/transactions/{transactionId}") + params := map[string]interface{}{} + params["transactionId"] = TransactionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateOperationsOptions struct { + Operations []interface{} + enabledSetters map[string]bool +} +func (options CreateOperationsOptions) New() *CreateOperationsOptions { + options.enabledSetters = map[string]bool{ + "Operations": false, + } + return &options +} +type CreateOperationsOption func(*CreateOperationsOptions) +func (srv *DocumentsDB) WithCreateOperationsOperations(v []interface{}) CreateOperationsOption { + return func(o *CreateOperationsOptions) { + o.Operations = v + o.enabledSetters["Operations"] = true + } +} + +// CreateOperations +func (srv *DocumentsDB) CreateOperations(TransactionId string, optionalSetters ...CreateOperationsOption)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/documentsdb/transactions/{transactionId}/operations") + options := CreateOperationsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["transactionId"] = TransactionId + if options.enabledSetters["Operations"] { + params["operations"] = options.Operations + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a database by its unique ID. This endpoint response returns a JSON +// object with the database metadata. +func (srv *DocumentsDB) Get(DatabaseId string)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/documentsdb/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + 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.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOptions) New() *UpdateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type UpdateOption func(*UpdateOptions) +func (srv *DocumentsDB) WithUpdateEnabled(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Update update a database by its unique ID. +func (srv *DocumentsDB) Update(DatabaseId string, Name string, optionalSetters ...UpdateOption)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/documentsdb/{databaseId}") + options := UpdateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a database by its unique ID. Only API keys with with +// databases.write scope can delete a database. +func (srv *DocumentsDB) Delete(DatabaseId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/documentsdb/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListCollectionsOptions struct { + Queries []string + Search string + Total bool + enabledSetters map[string]bool +} +func (options ListCollectionsOptions) New() *ListCollectionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + "Total": false, + } + return &options +} +type ListCollectionsOption func(*ListCollectionsOptions) +func (srv *DocumentsDB) WithListCollectionsQueries(v []string) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithListCollectionsSearch(v string) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} +func (srv *DocumentsDB) WithListCollectionsTotal(v bool) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListCollections get a list of all collections that belong to the provided +// databaseId. You can use the search parameter to filter your results. +func (srv *DocumentsDB) ListCollections(DatabaseId string, optionalSetters ...ListCollectionsOption)(*models.CollectionList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/documentsdb/{databaseId}/collections") + options := ListCollectionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.CollectionList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.CollectionList + parsed, ok := resp.Result.(models.CollectionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateCollectionOptions struct { + Permissions []string + DocumentSecurity bool + Enabled bool + Attributes []interface{} + Indexes []interface{} + enabledSetters map[string]bool +} +func (options CreateCollectionOptions) New() *CreateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + "Attributes": false, + "Indexes": false, + } + return &options +} +type CreateCollectionOption func(*CreateCollectionOptions) +func (srv *DocumentsDB) WithCreateCollectionPermissions(v []string) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *DocumentsDB) WithCreateCollectionDocumentSecurity(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func (srv *DocumentsDB) WithCreateCollectionEnabled(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func (srv *DocumentsDB) WithCreateCollectionAttributes(v []interface{}) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Attributes = v + o.enabledSetters["Attributes"] = true + } +} +func (srv *DocumentsDB) WithCreateCollectionIndexes(v []interface{}) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Indexes = v + o.enabledSetters["Indexes"] = true + } +} + +// CreateCollection create a new Collection. Before using this route, you +// should create a new database resource using either a [server +// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) +// API or directly from your database console. +func (srv *DocumentsDB) CreateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...CreateCollectionOption)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/documentsdb/{databaseId}/collections") + options := CreateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Attributes"] { + params["attributes"] = options.Attributes + } + if options.enabledSetters["Indexes"] { + params["indexes"] = options.Indexes + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Collection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Collection + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetCollection get a collection by its unique ID. This endpoint response +// returns a JSON object with the collection metadata. +func (srv *DocumentsDB) GetCollection(DatabaseId string, CollectionId string)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + 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.Collection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Collection + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateCollectionOptions struct { + Permissions []string + DocumentSecurity bool + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateCollectionOptions) New() *UpdateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + } + return &options +} +type UpdateCollectionOption func(*UpdateCollectionOptions) +func (srv *DocumentsDB) WithUpdateCollectionPermissions(v []string) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *DocumentsDB) WithUpdateCollectionDocumentSecurity(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func (srv *DocumentsDB) WithUpdateCollectionEnabled(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateCollection update a collection by its unique ID. +func (srv *DocumentsDB) UpdateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...UpdateCollectionOption)(*models.Collection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") + options := UpdateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Collection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Collection + parsed, ok := resp.Result.(models.Collection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteCollection delete a collection by its unique ID. Only users with +// write permissions have access to delete this resource. +func (srv *DocumentsDB) DeleteCollection(DatabaseId string, CollectionId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + 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 +} +type ListDocumentsOption func(*ListDocumentsOptions) +func (srv *DocumentsDB) WithListDocumentsQueries(v []string) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithListDocumentsTransactionId(v string) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} +func (srv *DocumentsDB) WithListDocumentsTotal(v bool) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} +func (srv *DocumentsDB) 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. +func (srv *DocumentsDB) ListDocuments(DatabaseId string, CollectionId string, optionalSetters ...ListDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + options := ListDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } + 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.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateDocumentOptions struct { + Permissions []string + enabledSetters map[string]bool +} +func (options CreateDocumentOptions) New() *CreateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + } + return &options +} +type CreateDocumentOption func(*CreateDocumentOptions) +func (srv *DocumentsDB) WithCreateDocumentPermissions(v []string) CreateDocumentOption { + return func(o *CreateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// CreateDocument create a new Document. Before using this route, you should +// create a new collection resource using either a [server +// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) +// API or directly from your database console. +func (srv *DocumentsDB) CreateDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...CreateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + options := CreateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + params["data"] = Data + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateDocuments 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#documentsDBCreateCollection) +// API or directly from your database console. +func (srv *DocumentsDB) CreateDocuments(DatabaseId string, CollectionId string, Documents []interface{})(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documents"] = Documents + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpsertDocumentsOptions struct { + TransactionId string + enabledSetters map[string]bool +} +func (options UpsertDocumentsOptions) New() *UpsertDocumentsOptions { + options.enabledSetters = map[string]bool{ + "TransactionId": false, + } + return &options +} +type UpsertDocumentsOption func(*UpsertDocumentsOptions) +func (srv *DocumentsDB) WithUpsertDocumentsTransactionId(v string) UpsertDocumentsOption { + return func(o *UpsertDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpsertDocuments 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#documentsDBCreateCollection) +// API or directly from your database console. +func (srv *DocumentsDB) UpsertDocuments(DatabaseId string, CollectionId string, Documents []interface{}, optionalSetters ...UpsertDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + options := UpsertDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documents"] = Documents + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateDocumentsOptions struct { + Data interface{} + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpdateDocumentsOptions) New() *UpdateDocumentsOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Queries": false, + "TransactionId": false, + } + return &options +} +type UpdateDocumentsOption func(*UpdateDocumentsOptions) +func (srv *DocumentsDB) WithUpdateDocumentsData(v interface{}) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *DocumentsDB) WithUpdateDocumentsQueries(v []string) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithUpdateDocumentsTransactionId(v string) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpdateDocuments 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. +func (srv *DocumentsDB) UpdateDocuments(DatabaseId string, CollectionId string, optionalSetters ...UpdateDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + options := UpdateDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type DeleteDocumentsOptions struct { + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options DeleteDocumentsOptions) New() *DeleteDocumentsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "TransactionId": false, + } + return &options +} +type DeleteDocumentsOption func(*DeleteDocumentsOptions) +func (srv *DocumentsDB) WithDeleteDocumentsQueries(v []string) DeleteDocumentsOption { + return func(o *DeleteDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithDeleteDocumentsTransactionId(v string) DeleteDocumentsOption { + return func(o *DeleteDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// DeleteDocuments bulk delete documents using queries, if no queries are +// passed then all documents are deleted. +func (srv *DocumentsDB) DeleteDocuments(DatabaseId string, CollectionId string, optionalSetters ...DeleteDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") + options := DeleteDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type GetDocumentOptions struct { + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options GetDocumentOptions) New() *GetDocumentOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "TransactionId": false, + } + return &options +} +type GetDocumentOption func(*GetDocumentOptions) +func (srv *DocumentsDB) WithGetDocumentQueries(v []string) GetDocumentOption { + return func(o *GetDocumentOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithGetDocumentTransactionId(v string) GetDocumentOption { + return func(o *GetDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// GetDocument get a document by its unique ID. This endpoint response returns +// a JSON object with the document data. +func (srv *DocumentsDB) GetDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...GetDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := GetDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpsertDocumentOptions struct { + Data interface{} + Permissions []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpsertDocumentOptions) New() *UpsertDocumentOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Permissions": false, + "TransactionId": false, + } + return &options +} +type UpsertDocumentOption func(*UpsertDocumentOptions) +func (srv *DocumentsDB) WithUpsertDocumentData(v interface{}) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *DocumentsDB) WithUpsertDocumentPermissions(v []string) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *DocumentsDB) WithUpsertDocumentTransactionId(v string) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpsertDocument create or update a Document. Before using this route, you +// should create a new collection resource using either a [server +// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) +// API or directly from your database console. +func (srv *DocumentsDB) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := UpsertDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateDocumentOptions struct { + Data interface{} + Permissions []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpdateDocumentOptions) New() *UpdateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Permissions": false, + "TransactionId": false, + } + return &options +} +type UpdateDocumentOption func(*UpdateDocumentOptions) +func (srv *DocumentsDB) WithUpdateDocumentData(v interface{}) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *DocumentsDB) WithUpdateDocumentPermissions(v []string) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *DocumentsDB) WithUpdateDocumentTransactionId(v string) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpdateDocument update a document by its unique ID. Using the patch method +// you can pass only specific fields that will get updated. +func (srv *DocumentsDB) UpdateDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpdateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := UpdateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type DeleteDocumentOptions struct { + TransactionId string + enabledSetters map[string]bool +} +func (options DeleteDocumentOptions) New() *DeleteDocumentOptions { + options.enabledSetters = map[string]bool{ + "TransactionId": false, + } + return &options +} +type DeleteDocumentOption func(*DeleteDocumentOptions) +func (srv *DocumentsDB) WithDeleteDocumentTransactionId(v string) DeleteDocumentOption { + return func(o *DeleteDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// DeleteDocument delete a document by its unique ID. +func (srv *DocumentsDB) DeleteDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...DeleteDocumentOption)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := DeleteDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type DecrementDocumentAttributeOptions struct { + Value float64 + Min float64 + TransactionId string + enabledSetters map[string]bool +} +func (options DecrementDocumentAttributeOptions) New() *DecrementDocumentAttributeOptions { + options.enabledSetters = map[string]bool{ + "Value": false, + "Min": false, + "TransactionId": false, + } + return &options +} +type DecrementDocumentAttributeOption func(*DecrementDocumentAttributeOptions) +func (srv *DocumentsDB) WithDecrementDocumentAttributeValue(v float64) DecrementDocumentAttributeOption { + return func(o *DecrementDocumentAttributeOptions) { + o.Value = v + o.enabledSetters["Value"] = true + } +} +func (srv *DocumentsDB) WithDecrementDocumentAttributeMin(v float64) DecrementDocumentAttributeOption { + return func(o *DecrementDocumentAttributeOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func (srv *DocumentsDB) WithDecrementDocumentAttributeTransactionId(v string) DecrementDocumentAttributeOption { + return func(o *DecrementDocumentAttributeOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// DecrementDocumentAttribute decrement a specific column of a row by a given +// value. +func (srv *DocumentsDB) DecrementDocumentAttribute(DatabaseId string, CollectionId string, DocumentId string, Attribute string, optionalSetters ...DecrementDocumentAttributeOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId, "{attribute}", Attribute) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement") + options := DecrementDocumentAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + params["attribute"] = Attribute + if options.enabledSetters["Value"] { + params["value"] = options.Value + } + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type IncrementDocumentAttributeOptions struct { + Value float64 + Max float64 + TransactionId string + enabledSetters map[string]bool +} +func (options IncrementDocumentAttributeOptions) New() *IncrementDocumentAttributeOptions { + options.enabledSetters = map[string]bool{ + "Value": false, + "Max": false, + "TransactionId": false, + } + return &options +} +type IncrementDocumentAttributeOption func(*IncrementDocumentAttributeOptions) +func (srv *DocumentsDB) WithIncrementDocumentAttributeValue(v float64) IncrementDocumentAttributeOption { + return func(o *IncrementDocumentAttributeOptions) { + o.Value = v + o.enabledSetters["Value"] = true + } +} +func (srv *DocumentsDB) WithIncrementDocumentAttributeMax(v float64) IncrementDocumentAttributeOption { + return func(o *IncrementDocumentAttributeOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func (srv *DocumentsDB) WithIncrementDocumentAttributeTransactionId(v string) IncrementDocumentAttributeOption { + return func(o *IncrementDocumentAttributeOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// IncrementDocumentAttribute increment a specific column of a row by a given +// value. +func (srv *DocumentsDB) IncrementDocumentAttribute(DatabaseId string, CollectionId string, DocumentId string, Attribute string, optionalSetters ...IncrementDocumentAttributeOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId, "{attribute}", Attribute) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment") + options := IncrementDocumentAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + params["attribute"] = Attribute + if options.enabledSetters["Value"] { + params["value"] = options.Value + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListIndexesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListIndexesOptions) New() *ListIndexesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListIndexesOption func(*ListIndexesOptions) +func (srv *DocumentsDB) WithListIndexesQueries(v []string) ListIndexesOption { + return func(o *ListIndexesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *DocumentsDB) WithListIndexesTotal(v bool) ListIndexesOption { + return func(o *ListIndexesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListIndexes list indexes in the collection. +func (srv *DocumentsDB) ListIndexes(DatabaseId string, CollectionId string, optionalSetters ...ListIndexesOption)(*models.IndexList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes") + options := ListIndexesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.IndexList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.IndexList + parsed, ok := resp.Result.(models.IndexList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateIndexOptions struct { + Orders []string + Lengths []int + enabledSetters map[string]bool +} +func (options CreateIndexOptions) New() *CreateIndexOptions { + options.enabledSetters = map[string]bool{ + "Orders": false, + "Lengths": false, + } + return &options +} +type CreateIndexOption func(*CreateIndexOptions) +func (srv *DocumentsDB) WithCreateIndexOrders(v []string) CreateIndexOption { + return func(o *CreateIndexOptions) { + o.Orders = v + o.enabledSetters["Orders"] = true + } +} +func (srv *DocumentsDB) WithCreateIndexLengths(v []int) CreateIndexOption { + return func(o *CreateIndexOptions) { + o.Lengths = v + o.enabledSetters["Lengths"] = true + } +} + +// CreateIndex creates an index on the attributes listed. Your index should +// include all the attributes you will query in a single request. +// Attributes can be `key`, `fulltext`, and `unique`. +func (srv *DocumentsDB) CreateIndex(DatabaseId string, CollectionId string, Key string, Type string, Attributes []string, optionalSetters ...CreateIndexOption)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes") + options := CreateIndexOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["type"] = Type + params["attributes"] = Attributes + if options.enabledSetters["Orders"] { + params["orders"] = options.Orders + } + if options.enabledSetters["Lengths"] { + params["lengths"] = options.Lengths + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Index{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Index + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetIndex get index by ID. +func (srv *DocumentsDB) GetIndex(DatabaseId string, CollectionId string, Key string)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + 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.Index{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Index + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteIndex delete an index. +func (srv *DocumentsDB) DeleteIndex(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/functions/functions.go b/functions/functions.go index 9ba882b3..84ebc1a5 100644 --- a/functions/functions.go +++ b/functions/functions.go @@ -6,6 +6,8 @@ import ( "github.com/appwrite/sdk-for-go/client" "github.com/appwrite/sdk-for-go/models" "github.com/appwrite/sdk-for-go/file" + "net/url" + "fmt" "strings" ) @@ -114,7 +116,9 @@ type CreateOptions struct { ProviderBranch string ProviderSilentMode bool ProviderRootDirectory string - Specification string + BuildSpecification string + RuntimeSpecification string + DeploymentRetention int enabledSetters map[string]bool } func (options CreateOptions) New() *CreateOptions { @@ -133,7 +137,9 @@ func (options CreateOptions) New() *CreateOptions { "ProviderBranch": false, "ProviderSilentMode": false, "ProviderRootDirectory": false, - "Specification": false, + "BuildSpecification": false, + "RuntimeSpecification": false, + "DeploymentRetention": false, } return &options } @@ -222,10 +228,22 @@ func (srv *Functions) WithCreateProviderRootDirectory(v string) CreateOption { o.enabledSetters["ProviderRootDirectory"] = true } } -func (srv *Functions) WithCreateSpecification(v string) CreateOption { +func (srv *Functions) WithCreateBuildSpecification(v string) CreateOption { return func(o *CreateOptions) { - o.Specification = v - o.enabledSetters["Specification"] = true + o.BuildSpecification = v + o.enabledSetters["BuildSpecification"] = true + } +} +func (srv *Functions) WithCreateRuntimeSpecification(v string) CreateOption { + return func(o *CreateOptions) { + o.RuntimeSpecification = v + o.enabledSetters["RuntimeSpecification"] = true + } +} +func (srv *Functions) WithCreateDeploymentRetention(v int) CreateOption { + return func(o *CreateOptions) { + o.DeploymentRetention = v + o.enabledSetters["DeploymentRetention"] = true } } @@ -285,8 +303,14 @@ func (srv *Functions) Create(FunctionId string, Name string, Runtime string, opt if options.enabledSetters["ProviderRootDirectory"] { params["providerRootDirectory"] = options.ProviderRootDirectory } - if options.enabledSetters["Specification"] { - params["specification"] = options.Specification + if options.enabledSetters["BuildSpecification"] { + params["buildSpecification"] = options.BuildSpecification + } + if options.enabledSetters["RuntimeSpecification"] { + params["runtimeSpecification"] = options.RuntimeSpecification + } + if options.enabledSetters["DeploymentRetention"] { + params["deploymentRetention"] = options.DeploymentRetention } headers := map[string]interface{}{ "content-type": "application/json", @@ -431,7 +455,9 @@ type UpdateOptions struct { ProviderBranch string ProviderSilentMode bool ProviderRootDirectory string - Specification string + BuildSpecification string + RuntimeSpecification string + DeploymentRetention int enabledSetters map[string]bool } func (options UpdateOptions) New() *UpdateOptions { @@ -451,7 +477,9 @@ func (options UpdateOptions) New() *UpdateOptions { "ProviderBranch": false, "ProviderSilentMode": false, "ProviderRootDirectory": false, - "Specification": false, + "BuildSpecification": false, + "RuntimeSpecification": false, + "DeploymentRetention": false, } return &options } @@ -546,10 +574,22 @@ func (srv *Functions) WithUpdateProviderRootDirectory(v string) UpdateOption { o.enabledSetters["ProviderRootDirectory"] = true } } -func (srv *Functions) WithUpdateSpecification(v string) UpdateOption { +func (srv *Functions) WithUpdateBuildSpecification(v string) UpdateOption { return func(o *UpdateOptions) { - o.Specification = v - o.enabledSetters["Specification"] = true + o.BuildSpecification = v + o.enabledSetters["BuildSpecification"] = true + } +} +func (srv *Functions) WithUpdateRuntimeSpecification(v string) UpdateOption { + return func(o *UpdateOptions) { + o.RuntimeSpecification = v + o.enabledSetters["RuntimeSpecification"] = true + } +} +func (srv *Functions) WithUpdateDeploymentRetention(v int) UpdateOption { + return func(o *UpdateOptions) { + o.DeploymentRetention = v + o.enabledSetters["DeploymentRetention"] = true } } @@ -609,8 +649,14 @@ func (srv *Functions) Update(FunctionId string, Name string, optionalSetters ... if options.enabledSetters["ProviderRootDirectory"] { params["providerRootDirectory"] = options.ProviderRootDirectory } - if options.enabledSetters["Specification"] { - params["specification"] = options.Specification + if options.enabledSetters["BuildSpecification"] { + params["buildSpecification"] = options.BuildSpecification + } + if options.enabledSetters["RuntimeSpecification"] { + params["runtimeSpecification"] = options.RuntimeSpecification + } + if options.enabledSetters["DeploymentRetention"] { + params["deploymentRetention"] = options.DeploymentRetention } headers := map[string]interface{}{ "content-type": "application/json", @@ -1202,6 +1248,30 @@ func (srv *Functions) GetDeploymentDownload(FunctionId string, DeploymentId stri return &parsed, nil } +// GetDeploymentDownloadURL get a function deployment content by its unique +// ID. The endpoint response return with a 'Content-Disposition: attachment' +// header that tells the browser to start downloading the file to user +// downloads directory. +// Returns the URL for the resource instead of the content. +func (srv *Functions) GetDeploymentDownloadURL(FunctionId string, DeploymentId string, optionalSetters ...GetDeploymentDownloadOption) (*string, error) { + r := strings.NewReplacer("{functionId}", FunctionId, "{deploymentId}", DeploymentId) + path := r.Replace("/functions/{functionId}/deployments/{deploymentId}/download") + options := GetDeploymentDownloadOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Type"] { + q.Set("type", fmt.Sprintf("%v", options.Type)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} // UpdateDeploymentStatus cancel an ongoing function deployment build. If the // build is already in progress, it will be stopped and marked as canceled. If diff --git a/models/attribute_object.go b/models/attribute_object.go new file mode 100644 index 00000000..b2608ecc --- /dev/null +++ b/models/attribute_object.go @@ -0,0 +1,49 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// AttributeObject Model +type AttributeObject struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"type"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"error"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + + // Used by Decode() method + data []byte +} + +func (model AttributeObject) New(data []byte) *AttributeObject { + model.data = data + return &model +} + +func (model *AttributeObject) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/attribute_vector.go b/models/attribute_vector.go new file mode 100644 index 00000000..6e96a011 --- /dev/null +++ b/models/attribute_vector.go @@ -0,0 +1,51 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// AttributeVector Model +type AttributeVector struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"type"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"error"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Vector dimensions. + Size int `json:"size"` + + // Used by Decode() method + data []byte +} + +func (model AttributeVector) New(data []byte) *AttributeVector { + model.data = data + return &model +} + +func (model *AttributeVector) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/document.go b/models/document.go index 1dcaa7a3..955f75da 100644 --- a/models/document.go +++ b/models/document.go @@ -10,7 +10,7 @@ type Document struct { // Document ID. Id string `json:"$id"` // Document sequence ID. - Sequence int `json:"$sequence"` + Sequence string `json:"$sequence"` // Collection ID. CollectionId string `json:"$collectionId"` // Database ID. diff --git a/models/embedding.go b/models/embedding.go new file mode 100644 index 00000000..157111af --- /dev/null +++ b/models/embedding.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Embedding Model +type Embedding struct { + // Embedding model used to generate embeddings. + Model string `json:"model"` + // Number of dimensions for each embedding vector. + Dimension int `json:"dimension"` + // Embedding vector values. If an error occurs, this will be an empty array. + Embedding []float64 `json:"embedding"` + // Error message if embedding generation fails. Empty string if no error. + Error string `json:"error"` + + // Used by Decode() method + data []byte +} + +func (model Embedding) New(data []byte) *Embedding { + model.data = data + return &model +} + +func (model *Embedding) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/embedding_list.go b/models/embedding_list.go new file mode 100644 index 00000000..ec72e308 --- /dev/null +++ b/models/embedding_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// EmbeddingList Model +type EmbeddingList struct { + // Total number of embeddings that matched your query. + Total int `json:"total"` + // List of embeddings. + Embeddings []Embedding `json:"embeddings"` + + // Used by Decode() method + data []byte +} + +func (model EmbeddingList) New(data []byte) *EmbeddingList { + model.data = data + return &model +} + +func (model *EmbeddingList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/function.go b/models/function.go index 18e817b8..26b0359c 100644 --- a/models/function.go +++ b/models/function.go @@ -29,6 +29,9 @@ type Function struct { Logging bool `json:"logging"` // Function execution and build runtime. Runtime string `json:"runtime"` + // How many days to keep the non-active deployments before they will be + // automatically deleted. + DeploymentRetention int `json:"deploymentRetention"` // Function's active deployment ID. DeploymentId string `json:"deploymentId"` // Active deployment creation date in ISO 8601 format. @@ -68,8 +71,10 @@ type Function struct { // silence mode, no comments will be posted on the repository pull or merge // requests ProviderSilentMode bool `json:"providerSilentMode"` - // Machine specification for builds and executions. - Specification string `json:"specification"` + // Machine specification for deployment builds. + BuildSpecification string `json:"buildSpecification"` + // Machine specification for executions. + RuntimeSpecification string `json:"runtimeSpecification"` // Used by Decode() method data []byte diff --git a/models/log.go b/models/log.go index 027f3bad..734ae0b8 100644 --- a/models/log.go +++ b/models/log.go @@ -9,11 +9,14 @@ import ( type Log struct { // Event name. Event string `json:"event"` - // User ID. + // User ID of the actor recorded for this log. During impersonation, this is + // the original impersonator, not the impersonated target user. UserId string `json:"userId"` - // User Email. + // User email of the actor recorded for this log. During impersonation, this + // is the original impersonator. UserEmail string `json:"userEmail"` - // User Name. + // User name of the actor recorded for this log. During impersonation, this is + // the original impersonator. UserName string `json:"userName"` // API mode when event triggered. Mode string `json:"mode"` diff --git a/models/row.go b/models/row.go index cf3343d6..5b61961a 100644 --- a/models/row.go +++ b/models/row.go @@ -10,7 +10,7 @@ type Row struct { // Row ID. Id string `json:"$id"` // Row sequence ID. - Sequence int `json:"$sequence"` + Sequence string `json:"$sequence"` // Table ID. TableId string `json:"$tableId"` // Database ID. diff --git a/models/site.go b/models/site.go index e332f260..542ec016 100644 --- a/models/site.go +++ b/models/site.go @@ -27,6 +27,9 @@ type Site struct { Logging bool `json:"logging"` // Site framework. Framework string `json:"framework"` + // How many days to keep the non-active deployments before they will be + // automatically deleted. + DeploymentRetention int `json:"deploymentRetention"` // Site's active deployment ID. DeploymentId string `json:"deploymentId"` // Active deployment creation date in ISO 8601 format. @@ -50,6 +53,8 @@ type Site struct { InstallCommand string `json:"installCommand"` // The build command used to build the site. BuildCommand string `json:"buildCommand"` + // Custom command to use when starting site runtime. + StartCommand string `json:"startCommand"` // The directory where the site build output is located. OutputDirectory string `json:"outputDirectory"` // Site VCS (Version Control System) installation id. @@ -64,8 +69,10 @@ type Site struct { // silence mode, no comments will be posted on the repository pull or merge // requests ProviderSilentMode bool `json:"providerSilentMode"` - // Machine specification for builds and executions. - Specification string `json:"specification"` + // Machine specification for deployment builds. + BuildSpecification string `json:"buildSpecification"` + // Machine specification for SSR executions. + RuntimeSpecification string `json:"runtimeSpecification"` // Site build runtime. BuildRuntime string `json:"buildRuntime"` // Site framework adapter. diff --git a/models/user.go b/models/user.go index e70c8ad4..e924624d 100644 --- a/models/user.go +++ b/models/user.go @@ -47,6 +47,13 @@ type User struct { // Most recent access date in ISO 8601 format. This attribute is only updated // again after 24 hours. AccessedAt string `json:"accessedAt"` + // Whether the user can impersonate other users. + Impersonator bool `json:"impersonator"` + // ID of the original actor performing the impersonation. Present only when + // the current request is impersonating another user. Internal audit logs + // attribute the action to this user, while the impersonated target is + // recorded only in internal audit payload data. + ImpersonatorUserId string `json:"impersonatorUserId"` // Used by Decode() method data []byte diff --git a/models/vectorsdb_collection.go b/models/vectorsdb_collection.go new file mode 100644 index 00000000..8657ed71 --- /dev/null +++ b/models/vectorsdb_collection.go @@ -0,0 +1,61 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// VectorsDBCollection Model +type VectorsdbCollection struct { + // Collection ID. + Id string `json:"$id"` + // Collection creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Collection update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Collection permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []string `json:"$permissions"` + // Database ID. + DatabaseId string `json:"databaseId"` + // Collection name. + Name string `json:"name"` + // Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the + // collection is inaccessible to users, but remains accessible to Server SDKs + // using API keys. + Enabled bool `json:"enabled"` + // Whether document-level permissions are enabled. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + DocumentSecurity bool `json:"documentSecurity"` + // Collection attributes. + Attributes []map[string]any `json:"attributes"` + // Collection indexes. + Indexes []Index `json:"indexes"` + // Maximum document size in bytes. Returns 0 when no limit applies. + BytesMax int `json:"bytesMax"` + // Currently used document size in bytes based on defined attributes. + BytesUsed int `json:"bytesUsed"` + // Embedding dimension. + Dimension int `json:"dimension"` + + // Used by Decode() method + data []byte +} + +func (model VectorsdbCollection) New(data []byte) *VectorsdbCollection { + model.data = data + return &model +} + +func (model *VectorsdbCollection) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/vectorsdb_collection_list.go b/models/vectorsdb_collection_list.go new file mode 100644 index 00000000..000ded6f --- /dev/null +++ b/models/vectorsdb_collection_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// VectorsDBCollectionsList Model +type VectorsdbCollectionList struct { + // Total number of collections that matched your query. + Total int `json:"total"` + // List of collections. + Collections []VectorsdbCollection `json:"collections"` + + // Used by Decode() method + data []byte +} + +func (model VectorsdbCollectionList) New(data []byte) *VectorsdbCollectionList { + model.data = data + return &model +} + +func (model *VectorsdbCollectionList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/webhook.go b/models/webhook.go new file mode 100644 index 00000000..b9acbe14 --- /dev/null +++ b/models/webhook.go @@ -0,0 +1,57 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Webhook Model +type Webhook struct { + // Webhook ID. + Id string `json:"$id"` + // Webhook creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Webhook update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Webhook name. + Name string `json:"name"` + // Webhook URL endpoint. + Url string `json:"url"` + // Webhook trigger events. + Events []string `json:"events"` + // Indicated if SSL / TLS Certificate verification is enabled. + Security bool `json:"security"` + // HTTP basic authentication username. + HttpUser string `json:"httpUser"` + // HTTP basic authentication password. + HttpPass string `json:"httpPass"` + // Signature key which can be used to validated incoming + SignatureKey string `json:"signatureKey"` + // Indicates if this webhook is enabled. + Enabled bool `json:"enabled"` + // Webhook error logs from the most recent failure. + Logs string `json:"logs"` + // Number of consecutive failed webhook attempts. + Attempts int `json:"attempts"` + + // Used by Decode() method + data []byte +} + +func (model Webhook) New(data []byte) *Webhook { + model.data = data + return &model +} + +func (model *Webhook) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/webhook_list.go b/models/webhook_list.go new file mode 100644 index 00000000..047de6a7 --- /dev/null +++ b/models/webhook_list.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// WebhooksList Model +type WebhookList struct { + // Total number of webhooks that matched your query. + Total int `json:"total"` + // List of webhooks. + Webhooks []Webhook `json:"webhooks"` + + // Used by Decode() method + data []byte +} + +func (model WebhookList) New(data []byte) *WebhookList { + model.data = data + return &model +} + +func (model *WebhookList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/project/project.go b/project/project.go new file mode 100644 index 00000000..e887c917 --- /dev/null +++ b/project/project.go @@ -0,0 +1,298 @@ +package project + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Project service +type Project struct { + client client.Client +} + +func New(clt client.Client) *Project { + return &Project{ + client: clt, + } +} + +type ListVariablesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListVariablesOptions) New() *ListVariablesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListVariablesOption func(*ListVariablesOptions) +func (srv *Project) WithListVariablesQueries(v []string) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Project) WithListVariablesTotal(v bool) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListVariables get a list of all project environment variables. +func (srv *Project) ListVariables(optionalSetters ...ListVariablesOption)(*models.VariableList, error) { + path := "/project/variables" + options := ListVariablesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.VariableList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.VariableList + parsed, ok := resp.Result.(models.VariableList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateVariableOptions struct { + Secret bool + enabledSetters map[string]bool +} +func (options CreateVariableOptions) New() *CreateVariableOptions { + options.enabledSetters = map[string]bool{ + "Secret": false, + } + return &options +} +type CreateVariableOption func(*CreateVariableOptions) +func (srv *Project) WithCreateVariableSecret(v bool) CreateVariableOption { + return func(o *CreateVariableOptions) { + o.Secret = v + o.enabledSetters["Secret"] = true + } +} + +// CreateVariable create a new project environment variable. These variables +// can be accessed by all functions and sites in the project. +func (srv *Project) CreateVariable(VariableId string, Key string, Value string, optionalSetters ...CreateVariableOption)(*models.Variable, error) { + path := "/project/variables" + options := CreateVariableOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["variableId"] = VariableId + params["key"] = Key + params["value"] = Value + if options.enabledSetters["Secret"] { + params["secret"] = options.Secret + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Variable{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Variable + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetVariable get a variable by its unique ID. +func (srv *Project) GetVariable(VariableId string)(*models.Variable, error) { + r := strings.NewReplacer("{variableId}", VariableId) + path := r.Replace("/project/variables/{variableId}") + params := map[string]interface{}{} + params["variableId"] = VariableId + 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.Variable{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Variable + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateVariableOptions struct { + Key string + Value string + Secret bool + enabledSetters map[string]bool +} +func (options UpdateVariableOptions) New() *UpdateVariableOptions { + options.enabledSetters = map[string]bool{ + "Key": false, + "Value": false, + "Secret": false, + } + return &options +} +type UpdateVariableOption func(*UpdateVariableOptions) +func (srv *Project) WithUpdateVariableKey(v string) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Key = v + o.enabledSetters["Key"] = true + } +} +func (srv *Project) WithUpdateVariableValue(v string) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Value = v + o.enabledSetters["Value"] = true + } +} +func (srv *Project) WithUpdateVariableSecret(v bool) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Secret = v + o.enabledSetters["Secret"] = true + } +} + +// UpdateVariable update variable by its unique ID. +func (srv *Project) UpdateVariable(VariableId string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { + r := strings.NewReplacer("{variableId}", VariableId) + path := r.Replace("/project/variables/{variableId}") + options := UpdateVariableOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["variableId"] = VariableId + if options.enabledSetters["Key"] { + params["key"] = options.Key + } + if options.enabledSetters["Value"] { + params["value"] = options.Value + } + if options.enabledSetters["Secret"] { + params["secret"] = options.Secret + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Variable{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Variable + parsed, ok := resp.Result.(models.Variable) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteVariable delete a variable by its unique ID. +func (srv *Project) DeleteVariable(VariableId string)(*interface{}, error) { + r := strings.NewReplacer("{variableId}", VariableId) + path := r.Replace("/project/variables/{variableId}") + params := map[string]interface{}{} + params["variableId"] = VariableId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/sites/sites.go b/sites/sites.go index 567b62e6..b5fc27e3 100644 --- a/sites/sites.go +++ b/sites/sites.go @@ -6,6 +6,8 @@ import ( "github.com/appwrite/sdk-for-go/client" "github.com/appwrite/sdk-for-go/models" "github.com/appwrite/sdk-for-go/file" + "net/url" + "fmt" "strings" ) @@ -105,6 +107,7 @@ type CreateOptions struct { Timeout int InstallCommand string BuildCommand string + StartCommand string OutputDirectory string Adapter string InstallationId string @@ -113,7 +116,9 @@ type CreateOptions struct { ProviderBranch string ProviderSilentMode bool ProviderRootDirectory string - Specification string + BuildSpecification string + RuntimeSpecification string + DeploymentRetention int enabledSetters map[string]bool } func (options CreateOptions) New() *CreateOptions { @@ -123,6 +128,7 @@ func (options CreateOptions) New() *CreateOptions { "Timeout": false, "InstallCommand": false, "BuildCommand": false, + "StartCommand": false, "OutputDirectory": false, "Adapter": false, "InstallationId": false, @@ -131,7 +137,9 @@ func (options CreateOptions) New() *CreateOptions { "ProviderBranch": false, "ProviderSilentMode": false, "ProviderRootDirectory": false, - "Specification": false, + "BuildSpecification": false, + "RuntimeSpecification": false, + "DeploymentRetention": false, } return &options } @@ -166,6 +174,12 @@ func (srv *Sites) WithCreateBuildCommand(v string) CreateOption { o.enabledSetters["BuildCommand"] = true } } +func (srv *Sites) WithCreateStartCommand(v string) CreateOption { + return func(o *CreateOptions) { + o.StartCommand = v + o.enabledSetters["StartCommand"] = true + } +} func (srv *Sites) WithCreateOutputDirectory(v string) CreateOption { return func(o *CreateOptions) { o.OutputDirectory = v @@ -214,10 +228,22 @@ func (srv *Sites) WithCreateProviderRootDirectory(v string) CreateOption { o.enabledSetters["ProviderRootDirectory"] = true } } -func (srv *Sites) WithCreateSpecification(v string) CreateOption { +func (srv *Sites) WithCreateBuildSpecification(v string) CreateOption { + return func(o *CreateOptions) { + o.BuildSpecification = v + o.enabledSetters["BuildSpecification"] = true + } +} +func (srv *Sites) WithCreateRuntimeSpecification(v string) CreateOption { + return func(o *CreateOptions) { + o.RuntimeSpecification = v + o.enabledSetters["RuntimeSpecification"] = true + } +} +func (srv *Sites) WithCreateDeploymentRetention(v int) CreateOption { return func(o *CreateOptions) { - o.Specification = v - o.enabledSetters["Specification"] = true + o.DeploymentRetention = v + o.enabledSetters["DeploymentRetention"] = true } } @@ -248,6 +274,9 @@ func (srv *Sites) Create(SiteId string, Name string, Framework string, BuildRunt if options.enabledSetters["BuildCommand"] { params["buildCommand"] = options.BuildCommand } + if options.enabledSetters["StartCommand"] { + params["startCommand"] = options.StartCommand + } if options.enabledSetters["OutputDirectory"] { params["outputDirectory"] = options.OutputDirectory } @@ -272,8 +301,14 @@ func (srv *Sites) Create(SiteId string, Name string, Framework string, BuildRunt if options.enabledSetters["ProviderRootDirectory"] { params["providerRootDirectory"] = options.ProviderRootDirectory } - if options.enabledSetters["Specification"] { - params["specification"] = options.Specification + if options.enabledSetters["BuildSpecification"] { + params["buildSpecification"] = options.BuildSpecification + } + if options.enabledSetters["RuntimeSpecification"] { + params["runtimeSpecification"] = options.RuntimeSpecification + } + if options.enabledSetters["DeploymentRetention"] { + params["deploymentRetention"] = options.DeploymentRetention } headers := map[string]interface{}{ "content-type": "application/json", @@ -408,6 +443,7 @@ type UpdateOptions struct { Timeout int InstallCommand string BuildCommand string + StartCommand string OutputDirectory string BuildRuntime string Adapter string @@ -417,7 +453,9 @@ type UpdateOptions struct { ProviderBranch string ProviderSilentMode bool ProviderRootDirectory string - Specification string + BuildSpecification string + RuntimeSpecification string + DeploymentRetention int enabledSetters map[string]bool } func (options UpdateOptions) New() *UpdateOptions { @@ -427,6 +465,7 @@ func (options UpdateOptions) New() *UpdateOptions { "Timeout": false, "InstallCommand": false, "BuildCommand": false, + "StartCommand": false, "OutputDirectory": false, "BuildRuntime": false, "Adapter": false, @@ -436,7 +475,9 @@ func (options UpdateOptions) New() *UpdateOptions { "ProviderBranch": false, "ProviderSilentMode": false, "ProviderRootDirectory": false, - "Specification": false, + "BuildSpecification": false, + "RuntimeSpecification": false, + "DeploymentRetention": false, } return &options } @@ -471,6 +512,12 @@ func (srv *Sites) WithUpdateBuildCommand(v string) UpdateOption { o.enabledSetters["BuildCommand"] = true } } +func (srv *Sites) WithUpdateStartCommand(v string) UpdateOption { + return func(o *UpdateOptions) { + o.StartCommand = v + o.enabledSetters["StartCommand"] = true + } +} func (srv *Sites) WithUpdateOutputDirectory(v string) UpdateOption { return func(o *UpdateOptions) { o.OutputDirectory = v @@ -525,10 +572,22 @@ func (srv *Sites) WithUpdateProviderRootDirectory(v string) UpdateOption { o.enabledSetters["ProviderRootDirectory"] = true } } -func (srv *Sites) WithUpdateSpecification(v string) UpdateOption { +func (srv *Sites) WithUpdateBuildSpecification(v string) UpdateOption { + return func(o *UpdateOptions) { + o.BuildSpecification = v + o.enabledSetters["BuildSpecification"] = true + } +} +func (srv *Sites) WithUpdateRuntimeSpecification(v string) UpdateOption { return func(o *UpdateOptions) { - o.Specification = v - o.enabledSetters["Specification"] = true + o.RuntimeSpecification = v + o.enabledSetters["RuntimeSpecification"] = true + } +} +func (srv *Sites) WithUpdateDeploymentRetention(v int) UpdateOption { + return func(o *UpdateOptions) { + o.DeploymentRetention = v + o.enabledSetters["DeploymentRetention"] = true } } @@ -559,6 +618,9 @@ func (srv *Sites) Update(SiteId string, Name string, Framework string, optionalS if options.enabledSetters["BuildCommand"] { params["buildCommand"] = options.BuildCommand } + if options.enabledSetters["StartCommand"] { + params["startCommand"] = options.StartCommand + } if options.enabledSetters["OutputDirectory"] { params["outputDirectory"] = options.OutputDirectory } @@ -586,8 +648,14 @@ func (srv *Sites) Update(SiteId string, Name string, Framework string, optionalS if options.enabledSetters["ProviderRootDirectory"] { params["providerRootDirectory"] = options.ProviderRootDirectory } - if options.enabledSetters["Specification"] { - params["specification"] = options.Specification + if options.enabledSetters["BuildSpecification"] { + params["buildSpecification"] = options.BuildSpecification + } + if options.enabledSetters["RuntimeSpecification"] { + params["runtimeSpecification"] = options.RuntimeSpecification + } + if options.enabledSetters["DeploymentRetention"] { + params["deploymentRetention"] = options.DeploymentRetention } headers := map[string]interface{}{ "content-type": "application/json", @@ -1168,6 +1236,30 @@ func (srv *Sites) GetDeploymentDownload(SiteId string, DeploymentId string, opti return &parsed, nil } +// GetDeploymentDownloadURL get a site deployment content by its unique ID. +// The endpoint response return with a 'Content-Disposition: attachment' +// header that tells the browser to start downloading the file to user +// downloads directory. +// Returns the URL for the resource instead of the content. +func (srv *Sites) GetDeploymentDownloadURL(SiteId string, DeploymentId string, optionalSetters ...GetDeploymentDownloadOption) (*string, error) { + r := strings.NewReplacer("{siteId}", SiteId, "{deploymentId}", DeploymentId) + path := r.Replace("/sites/{siteId}/deployments/{deploymentId}/download") + options := GetDeploymentDownloadOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Type"] { + q.Set("type", fmt.Sprintf("%v", options.Type)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} // UpdateDeploymentStatus cancel an ongoing site deployment build. If the // build is already in progress, it will be stopped and marked as canceled. If diff --git a/storage/storage.go b/storage/storage.go index 0a19a5ee..d7d2ffe3 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -6,6 +6,8 @@ import ( "github.com/appwrite/sdk-for-go/client" "github.com/appwrite/sdk-for-go/models" "github.com/appwrite/sdk-for-go/file" + "net/url" + "fmt" "strings" ) @@ -825,6 +827,29 @@ func (srv *Storage) GetFileDownload(BucketId string, FileId string, optionalSett return &parsed, nil } +// GetFileDownloadURL get a file content by its unique ID. The endpoint +// response return with a 'Content-Disposition: attachment' header that tells +// the browser to start downloading the file to user downloads directory. +// Returns the URL for the resource instead of the content. +func (srv *Storage) GetFileDownloadURL(BucketId string, FileId string, optionalSetters ...GetFileDownloadOption) (*string, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/download") + options := GetFileDownloadOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Token"] { + q.Set("token", fmt.Sprintf("%v", options.Token)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetFilePreviewOptions struct { Width int Height int @@ -1008,6 +1033,64 @@ func (srv *Storage) GetFilePreview(BucketId string, FileId string, optionalSette return &parsed, nil } +// GetFilePreviewURL get a file preview image. Currently, this method supports +// preview for image files (jpg, png, and gif), other supported formats, like +// pdf, docs, slides, and spreadsheets, will return the file icon image. You +// can also pass query string arguments for cutting and resizing your preview +// image. Preview is supported only for image files smaller than 10MB. +// Returns the URL for the resource instead of the content. +func (srv *Storage) GetFilePreviewURL(BucketId string, FileId string, optionalSetters ...GetFilePreviewOption) (*string, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/preview") + options := GetFilePreviewOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Width"] { + q.Set("width", fmt.Sprintf("%v", options.Width)) + } + if options.enabledSetters["Height"] { + q.Set("height", fmt.Sprintf("%v", options.Height)) + } + if options.enabledSetters["Gravity"] { + q.Set("gravity", fmt.Sprintf("%v", options.Gravity)) + } + if options.enabledSetters["Quality"] { + q.Set("quality", fmt.Sprintf("%v", options.Quality)) + } + if options.enabledSetters["BorderWidth"] { + q.Set("borderWidth", fmt.Sprintf("%v", options.BorderWidth)) + } + if options.enabledSetters["BorderColor"] { + q.Set("borderColor", fmt.Sprintf("%v", options.BorderColor)) + } + if options.enabledSetters["BorderRadius"] { + q.Set("borderRadius", fmt.Sprintf("%v", options.BorderRadius)) + } + if options.enabledSetters["Opacity"] { + q.Set("opacity", fmt.Sprintf("%v", options.Opacity)) + } + if options.enabledSetters["Rotation"] { + q.Set("rotation", fmt.Sprintf("%v", options.Rotation)) + } + if options.enabledSetters["Background"] { + q.Set("background", fmt.Sprintf("%v", options.Background)) + } + if options.enabledSetters["Output"] { + q.Set("output", fmt.Sprintf("%v", options.Output)) + } + if options.enabledSetters["Token"] { + q.Set("token", fmt.Sprintf("%v", options.Token)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} type GetFileViewOptions struct { Token string enabledSetters map[string]bool @@ -1068,3 +1151,26 @@ func (srv *Storage) GetFileView(BucketId string, FileId string, optionalSetters return &parsed, nil } +// GetFileViewURL get a file content by its unique ID. This endpoint is +// similar to the download method but returns with no 'Content-Disposition: +// attachment' header. +// Returns the URL for the resource instead of the content. +func (srv *Storage) GetFileViewURL(BucketId string, FileId string, optionalSetters ...GetFileViewOption) (*string, error) { + r := strings.NewReplacer("{bucketId}", BucketId, "{fileId}", FileId) + path := r.Replace("/storage/buckets/{bucketId}/files/{fileId}/view") + options := GetFileViewOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + u, err := url.Parse(srv.client.Endpoint + path) + if err != nil { + return nil, err + } + q := u.Query() + if options.enabledSetters["Token"] { + q.Set("token", fmt.Sprintf("%v", options.Token)) + } + u.RawQuery = q.Encode() + result := u.String() + return &result, nil +} diff --git a/users/users.go b/users/users.go index d1535383..a15070df 100644 --- a/users/users.go +++ b/users/users.go @@ -871,6 +871,46 @@ func (srv *Users) UpdateEmail(UserId string, Email string)(*models.User, error) } return &parsed, nil +} + +// UpdateImpersonator enable or disable whether a user can impersonate other +// users. When impersonation headers are used, the request runs as the target +// user for API behavior, while internal audit logs still attribute the action +// to the original impersonator and store the impersonated target details only +// in internal audit payload data. +func (srv *Users) UpdateImpersonator(UserId string, Impersonator bool)(*models.User, error) { + r := strings.NewReplacer("{userId}", UserId) + path := r.Replace("/users/{userId}/impersonator") + params := map[string]interface{}{} + params["userId"] = UserId + params["impersonator"] = Impersonator + 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.User{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.User + parsed, ok := resp.Result.(models.User) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + } type CreateJWTOptions struct { SessionId string diff --git a/vectorsdb/vectors_db.go b/vectorsdb/vectors_db.go new file mode 100644 index 00000000..df2b3661 --- /dev/null +++ b/vectorsdb/vectors_db.go @@ -0,0 +1,1900 @@ +package vectorsdb + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// VectorsDB service +type VectorsDB struct { + client client.Client +} + +func New(clt client.Client) *VectorsDB { + return &VectorsDB{ + client: clt, + } +} + +type ListOptions struct { + Queries []string + Search string + Total bool + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + "Total": false, + } + return &options +} +type ListOption func(*ListOptions) +func (srv *VectorsDB) WithListQueries(v []string) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithListSearch(v string) ListOption { + return func(o *ListOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} +func (srv *VectorsDB) WithListTotal(v bool) ListOption { + return func(o *ListOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// List +func (srv *VectorsDB) List(optionalSetters ...ListOption)(*models.DatabaseList, error) { + path := "/vectorsdb" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.DatabaseList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DatabaseList + parsed, ok := resp.Result.(models.DatabaseList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func (srv *VectorsDB) WithCreateEnabled(v bool) CreateOption { + return func(o *CreateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Create +func (srv *VectorsDB) Create(DatabaseId string, Name string, optionalSetters ...CreateOption)(*models.Database, error) { + path := "/vectorsdb" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateTextEmbeddingsOptions struct { + Model string + enabledSetters map[string]bool +} +func (options CreateTextEmbeddingsOptions) New() *CreateTextEmbeddingsOptions { + options.enabledSetters = map[string]bool{ + "Model": false, + } + return &options +} +type CreateTextEmbeddingsOption func(*CreateTextEmbeddingsOptions) +func (srv *VectorsDB) WithCreateTextEmbeddingsModel(v string) CreateTextEmbeddingsOption { + return func(o *CreateTextEmbeddingsOptions) { + o.Model = v + o.enabledSetters["Model"] = true + } +} + +// CreateTextEmbeddings +func (srv *VectorsDB) CreateTextEmbeddings(Texts []string, optionalSetters ...CreateTextEmbeddingsOption)(*models.EmbeddingList, error) { + path := "/vectorsdb/embeddings/text" + options := CreateTextEmbeddingsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["texts"] = Texts + if options.enabledSetters["Model"] { + params["model"] = options.Model + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.EmbeddingList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.EmbeddingList + parsed, ok := resp.Result.(models.EmbeddingList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListTransactionsOptions struct { + Queries []string + enabledSetters map[string]bool +} +func (options ListTransactionsOptions) New() *ListTransactionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + } + return &options +} +type ListTransactionsOption func(*ListTransactionsOptions) +func (srv *VectorsDB) WithListTransactionsQueries(v []string) ListTransactionsOption { + return func(o *ListTransactionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} + +// ListTransactions +func (srv *VectorsDB) ListTransactions(optionalSetters ...ListTransactionsOption)(*models.TransactionList, error) { + path := "/vectorsdb/transactions" + options := ListTransactionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + 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.TransactionList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.TransactionList + parsed, ok := resp.Result.(models.TransactionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateTransactionOptions struct { + Ttl int + enabledSetters map[string]bool +} +func (options CreateTransactionOptions) New() *CreateTransactionOptions { + options.enabledSetters = map[string]bool{ + "Ttl": false, + } + return &options +} +type CreateTransactionOption func(*CreateTransactionOptions) +func (srv *VectorsDB) WithCreateTransactionTtl(v int) CreateTransactionOption { + return func(o *CreateTransactionOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} + +// CreateTransaction +func (srv *VectorsDB) CreateTransaction(optionalSetters ...CreateTransactionOption)(*models.Transaction, error) { + path := "/vectorsdb/transactions" + options := CreateTransactionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetTransaction +func (srv *VectorsDB) GetTransaction(TransactionId string)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/vectorsdb/transactions/{transactionId}") + params := map[string]interface{}{} + params["transactionId"] = TransactionId + 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.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateTransactionOptions struct { + Commit bool + Rollback bool + enabledSetters map[string]bool +} +func (options UpdateTransactionOptions) New() *UpdateTransactionOptions { + options.enabledSetters = map[string]bool{ + "Commit": false, + "Rollback": false, + } + return &options +} +type UpdateTransactionOption func(*UpdateTransactionOptions) +func (srv *VectorsDB) WithUpdateTransactionCommit(v bool) UpdateTransactionOption { + return func(o *UpdateTransactionOptions) { + o.Commit = v + o.enabledSetters["Commit"] = true + } +} +func (srv *VectorsDB) WithUpdateTransactionRollback(v bool) UpdateTransactionOption { + return func(o *UpdateTransactionOptions) { + o.Rollback = v + o.enabledSetters["Rollback"] = true + } +} + +// UpdateTransaction +func (srv *VectorsDB) UpdateTransaction(TransactionId string, optionalSetters ...UpdateTransactionOption)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/vectorsdb/transactions/{transactionId}") + options := UpdateTransactionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["transactionId"] = TransactionId + if options.enabledSetters["Commit"] { + params["commit"] = options.Commit + } + if options.enabledSetters["Rollback"] { + params["rollback"] = options.Rollback + } + 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.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteTransaction +func (srv *VectorsDB) DeleteTransaction(TransactionId string)(*interface{}, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/vectorsdb/transactions/{transactionId}") + params := map[string]interface{}{} + params["transactionId"] = TransactionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateOperationsOptions struct { + Operations []interface{} + enabledSetters map[string]bool +} +func (options CreateOperationsOptions) New() *CreateOperationsOptions { + options.enabledSetters = map[string]bool{ + "Operations": false, + } + return &options +} +type CreateOperationsOption func(*CreateOperationsOptions) +func (srv *VectorsDB) WithCreateOperationsOperations(v []interface{}) CreateOperationsOption { + return func(o *CreateOperationsOptions) { + o.Operations = v + o.enabledSetters["Operations"] = true + } +} + +// CreateOperations +func (srv *VectorsDB) CreateOperations(TransactionId string, optionalSetters ...CreateOperationsOption)(*models.Transaction, error) { + r := strings.NewReplacer("{transactionId}", TransactionId) + path := r.Replace("/vectorsdb/transactions/{transactionId}/operations") + options := CreateOperationsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["transactionId"] = TransactionId + if options.enabledSetters["Operations"] { + params["operations"] = options.Operations + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Transaction{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Transaction + parsed, ok := resp.Result.(models.Transaction) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get +func (srv *VectorsDB) Get(DatabaseId string)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/vectorsdb/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + 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.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOptions struct { + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOptions) New() *UpdateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + } + return &options +} +type UpdateOption func(*UpdateOptions) +func (srv *VectorsDB) WithUpdateEnabled(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// Update +func (srv *VectorsDB) Update(DatabaseId string, Name string, optionalSetters ...UpdateOption)(*models.Database, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/vectorsdb/{databaseId}") + options := UpdateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["name"] = Name + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Database{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Database + parsed, ok := resp.Result.(models.Database) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete +func (srv *VectorsDB) Delete(DatabaseId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/vectorsdb/{databaseId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListCollectionsOptions struct { + Queries []string + Search string + Total bool + enabledSetters map[string]bool +} +func (options ListCollectionsOptions) New() *ListCollectionsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Search": false, + "Total": false, + } + return &options +} +type ListCollectionsOption func(*ListCollectionsOptions) +func (srv *VectorsDB) WithListCollectionsQueries(v []string) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithListCollectionsSearch(v string) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Search = v + o.enabledSetters["Search"] = true + } +} +func (srv *VectorsDB) WithListCollectionsTotal(v bool) ListCollectionsOption { + return func(o *ListCollectionsOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListCollections +func (srv *VectorsDB) ListCollections(DatabaseId string, optionalSetters ...ListCollectionsOption)(*models.VectorsdbCollectionList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/vectorsdb/{databaseId}/collections") + options := ListCollectionsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Search"] { + params["search"] = options.Search + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.VectorsdbCollectionList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.VectorsdbCollectionList + parsed, ok := resp.Result.(models.VectorsdbCollectionList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateCollectionOptions struct { + Permissions []string + DocumentSecurity bool + Enabled bool + enabledSetters map[string]bool +} +func (options CreateCollectionOptions) New() *CreateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + } + return &options +} +type CreateCollectionOption func(*CreateCollectionOptions) +func (srv *VectorsDB) WithCreateCollectionPermissions(v []string) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *VectorsDB) WithCreateCollectionDocumentSecurity(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func (srv *VectorsDB) WithCreateCollectionEnabled(v bool) CreateCollectionOption { + return func(o *CreateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// CreateCollection +func (srv *VectorsDB) CreateCollection(DatabaseId string, CollectionId string, Name string, Dimension int, optionalSetters ...CreateCollectionOption)(*models.VectorsdbCollection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId) + path := r.Replace("/vectorsdb/{databaseId}/collections") + options := CreateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + params["dimension"] = Dimension + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.VectorsdbCollection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.VectorsdbCollection + parsed, ok := resp.Result.(models.VectorsdbCollection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetCollection +func (srv *VectorsDB) GetCollection(DatabaseId string, CollectionId string)(*models.VectorsdbCollection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + 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.VectorsdbCollection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.VectorsdbCollection + parsed, ok := resp.Result.(models.VectorsdbCollection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateCollectionOptions struct { + Dimension int + Permissions []string + DocumentSecurity bool + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateCollectionOptions) New() *UpdateCollectionOptions { + options.enabledSetters = map[string]bool{ + "Dimension": false, + "Permissions": false, + "DocumentSecurity": false, + "Enabled": false, + } + return &options +} +type UpdateCollectionOption func(*UpdateCollectionOptions) +func (srv *VectorsDB) WithUpdateCollectionDimension(v int) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Dimension = v + o.enabledSetters["Dimension"] = true + } +} +func (srv *VectorsDB) WithUpdateCollectionPermissions(v []string) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *VectorsDB) WithUpdateCollectionDocumentSecurity(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.DocumentSecurity = v + o.enabledSetters["DocumentSecurity"] = true + } +} +func (srv *VectorsDB) WithUpdateCollectionEnabled(v bool) UpdateCollectionOption { + return func(o *UpdateCollectionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateCollection +func (srv *VectorsDB) UpdateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...UpdateCollectionOption)(*models.VectorsdbCollection, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") + options := UpdateCollectionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["name"] = Name + if options.enabledSetters["Dimension"] { + params["dimension"] = options.Dimension + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["DocumentSecurity"] { + params["documentSecurity"] = options.DocumentSecurity + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.VectorsdbCollection{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.VectorsdbCollection + parsed, ok := resp.Result.(models.VectorsdbCollection) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteCollection +func (srv *VectorsDB) DeleteCollection(DatabaseId string, CollectionId string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + 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 +} +type ListDocumentsOption func(*ListDocumentsOptions) +func (srv *VectorsDB) WithListDocumentsQueries(v []string) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithListDocumentsTransactionId(v string) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} +func (srv *VectorsDB) WithListDocumentsTotal(v bool) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} +func (srv *VectorsDB) WithListDocumentsTtl(v int) ListDocumentsOption { + return func(o *ListDocumentsOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} + +// ListDocuments +func (srv *VectorsDB) ListDocuments(DatabaseId string, CollectionId string, optionalSetters ...ListDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + options := ListDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } + 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.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateDocumentOptions struct { + Permissions []string + enabledSetters map[string]bool +} +func (options CreateDocumentOptions) New() *CreateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + } + return &options +} +type CreateDocumentOption func(*CreateDocumentOptions) +func (srv *VectorsDB) WithCreateDocumentPermissions(v []string) CreateDocumentOption { + return func(o *CreateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} + +// CreateDocument +func (srv *VectorsDB) CreateDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...CreateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + options := CreateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + params["data"] = Data + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateDocuments +func (srv *VectorsDB) CreateDocuments(DatabaseId string, CollectionId string, Documents []interface{})(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documents"] = Documents + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpsertDocumentsOptions struct { + TransactionId string + enabledSetters map[string]bool +} +func (options UpsertDocumentsOptions) New() *UpsertDocumentsOptions { + options.enabledSetters = map[string]bool{ + "TransactionId": false, + } + return &options +} +type UpsertDocumentsOption func(*UpsertDocumentsOptions) +func (srv *VectorsDB) WithUpsertDocumentsTransactionId(v string) UpsertDocumentsOption { + return func(o *UpsertDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpsertDocuments +func (srv *VectorsDB) UpsertDocuments(DatabaseId string, CollectionId string, Documents []interface{}, optionalSetters ...UpsertDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + options := UpsertDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documents"] = Documents + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateDocumentsOptions struct { + Data interface{} + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpdateDocumentsOptions) New() *UpdateDocumentsOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Queries": false, + "TransactionId": false, + } + return &options +} +type UpdateDocumentsOption func(*UpdateDocumentsOptions) +func (srv *VectorsDB) WithUpdateDocumentsData(v interface{}) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *VectorsDB) WithUpdateDocumentsQueries(v []string) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithUpdateDocumentsTransactionId(v string) UpdateDocumentsOption { + return func(o *UpdateDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpdateDocuments +func (srv *VectorsDB) UpdateDocuments(DatabaseId string, CollectionId string, optionalSetters ...UpdateDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + options := UpdateDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type DeleteDocumentsOptions struct { + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options DeleteDocumentsOptions) New() *DeleteDocumentsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "TransactionId": false, + } + return &options +} +type DeleteDocumentsOption func(*DeleteDocumentsOptions) +func (srv *VectorsDB) WithDeleteDocumentsQueries(v []string) DeleteDocumentsOption { + return func(o *DeleteDocumentsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithDeleteDocumentsTransactionId(v string) DeleteDocumentsOption { + return func(o *DeleteDocumentsOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// DeleteDocuments +func (srv *VectorsDB) DeleteDocuments(DatabaseId string, CollectionId string, optionalSetters ...DeleteDocumentsOption)(*models.DocumentList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") + options := DeleteDocumentsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.DocumentList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.DocumentList + parsed, ok := resp.Result.(models.DocumentList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type GetDocumentOptions struct { + Queries []string + TransactionId string + enabledSetters map[string]bool +} +func (options GetDocumentOptions) New() *GetDocumentOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "TransactionId": false, + } + return &options +} +type GetDocumentOption func(*GetDocumentOptions) +func (srv *VectorsDB) WithGetDocumentQueries(v []string) GetDocumentOption { + return func(o *GetDocumentOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithGetDocumentTransactionId(v string) GetDocumentOption { + return func(o *GetDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// GetDocument +func (srv *VectorsDB) GetDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...GetDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := GetDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpsertDocumentOptions struct { + Data interface{} + Permissions []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpsertDocumentOptions) New() *UpsertDocumentOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Permissions": false, + "TransactionId": false, + } + return &options +} +type UpsertDocumentOption func(*UpsertDocumentOptions) +func (srv *VectorsDB) WithUpsertDocumentData(v interface{}) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *VectorsDB) WithUpsertDocumentPermissions(v []string) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *VectorsDB) WithUpsertDocumentTransactionId(v string) UpsertDocumentOption { + return func(o *UpsertDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpsertDocument +func (srv *VectorsDB) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := UpsertDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateDocumentOptions struct { + Data interface{} + Permissions []string + TransactionId string + enabledSetters map[string]bool +} +func (options UpdateDocumentOptions) New() *UpdateDocumentOptions { + options.enabledSetters = map[string]bool{ + "Data": false, + "Permissions": false, + "TransactionId": false, + } + return &options +} +type UpdateDocumentOption func(*UpdateDocumentOptions) +func (srv *VectorsDB) WithUpdateDocumentData(v interface{}) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Data = v + o.enabledSetters["Data"] = true + } +} +func (srv *VectorsDB) WithUpdateDocumentPermissions(v []string) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *VectorsDB) WithUpdateDocumentTransactionId(v string) UpdateDocumentOption { + return func(o *UpdateDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// UpdateDocument +func (srv *VectorsDB) UpdateDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpdateDocumentOption)(*models.Document, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := UpdateDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["Data"] { + params["data"] = options.Data + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + 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.Document{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Document + parsed, ok := resp.Result.(models.Document) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type DeleteDocumentOptions struct { + TransactionId string + enabledSetters map[string]bool +} +func (options DeleteDocumentOptions) New() *DeleteDocumentOptions { + options.enabledSetters = map[string]bool{ + "TransactionId": false, + } + return &options +} +type DeleteDocumentOption func(*DeleteDocumentOptions) +func (srv *VectorsDB) WithDeleteDocumentTransactionId(v string) DeleteDocumentOption { + return func(o *DeleteDocumentOptions) { + o.TransactionId = v + o.enabledSetters["TransactionId"] = true + } +} + +// DeleteDocument +func (srv *VectorsDB) DeleteDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...DeleteDocumentOption)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") + options := DeleteDocumentOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["documentId"] = DocumentId + if options.enabledSetters["TransactionId"] { + params["transactionId"] = options.TransactionId + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListIndexesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListIndexesOptions) New() *ListIndexesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListIndexesOption func(*ListIndexesOptions) +func (srv *VectorsDB) WithListIndexesQueries(v []string) ListIndexesOption { + return func(o *ListIndexesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *VectorsDB) WithListIndexesTotal(v bool) ListIndexesOption { + return func(o *ListIndexesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListIndexes +func (srv *VectorsDB) ListIndexes(DatabaseId string, CollectionId string, optionalSetters ...ListIndexesOption)(*models.IndexList, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes") + options := ListIndexesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.IndexList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.IndexList + parsed, ok := resp.Result.(models.IndexList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateIndexOptions struct { + Orders []string + Lengths []int + enabledSetters map[string]bool +} +func (options CreateIndexOptions) New() *CreateIndexOptions { + options.enabledSetters = map[string]bool{ + "Orders": false, + "Lengths": false, + } + return &options +} +type CreateIndexOption func(*CreateIndexOptions) +func (srv *VectorsDB) WithCreateIndexOrders(v []string) CreateIndexOption { + return func(o *CreateIndexOptions) { + o.Orders = v + o.enabledSetters["Orders"] = true + } +} +func (srv *VectorsDB) WithCreateIndexLengths(v []int) CreateIndexOption { + return func(o *CreateIndexOptions) { + o.Lengths = v + o.enabledSetters["Lengths"] = true + } +} + +// CreateIndex +func (srv *VectorsDB) CreateIndex(DatabaseId string, CollectionId string, Key string, Type string, Attributes []string, optionalSetters ...CreateIndexOption)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes") + options := CreateIndexOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["type"] = Type + params["attributes"] = Attributes + if options.enabledSetters["Orders"] { + params["orders"] = options.Orders + } + if options.enabledSetters["Lengths"] { + params["lengths"] = options.Lengths + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Index{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Index + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetIndex +func (srv *VectorsDB) GetIndex(DatabaseId string, CollectionId string, Key string)(*models.Index, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + 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.Index{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Index + parsed, ok := resp.Result.(models.Index) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteIndex +func (srv *VectorsDB) DeleteIndex(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes/{key}") + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/webhooks/webhooks.go b/webhooks/webhooks.go new file mode 100644 index 00000000..d36bd35f --- /dev/null +++ b/webhooks/webhooks.go @@ -0,0 +1,387 @@ +package webhooks + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/client" + "github.com/appwrite/sdk-for-go/models" + "strings" +) + +// Webhooks service +type Webhooks struct { + client client.Client +} + +func New(clt client.Client) *Webhooks { + return &Webhooks{ + client: clt, + } +} + +type ListOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListOption func(*ListOptions) +func (srv *Webhooks) WithListQueries(v []string) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Webhooks) WithListTotal(v bool) ListOption { + return func(o *ListOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// List get a list of all webhooks belonging to the project. You can use the +// query params to filter your results. +func (srv *Webhooks) List(optionalSetters ...ListOption)(*models.WebhookList, error) { + path := "/webhooks" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + 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.WebhookList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.WebhookList + parsed, ok := resp.Result.(models.WebhookList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateOptions struct { + Enabled bool + Security bool + HttpUser string + HttpPass string + enabledSetters map[string]bool +} +func (options CreateOptions) New() *CreateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + "Security": false, + "HttpUser": false, + "HttpPass": false, + } + return &options +} +type CreateOption func(*CreateOptions) +func (srv *Webhooks) WithCreateEnabled(v bool) CreateOption { + return func(o *CreateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func (srv *Webhooks) WithCreateSecurity(v bool) CreateOption { + return func(o *CreateOptions) { + o.Security = v + o.enabledSetters["Security"] = true + } +} +func (srv *Webhooks) WithCreateHttpUser(v string) CreateOption { + return func(o *CreateOptions) { + o.HttpUser = v + o.enabledSetters["HttpUser"] = true + } +} +func (srv *Webhooks) WithCreateHttpPass(v string) CreateOption { + return func(o *CreateOptions) { + o.HttpPass = v + o.enabledSetters["HttpPass"] = true + } +} + +// Create create a new webhook. Use this endpoint to configure a URL that will +// receive events from Appwrite when specific events occur. +func (srv *Webhooks) Create(WebhookId string, Url string, Name string, Events []string, optionalSetters ...CreateOption)(*models.Webhook, error) { + path := "/webhooks" + options := CreateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["webhookId"] = WebhookId + params["url"] = Url + params["name"] = Name + params["events"] = Events + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Security"] { + params["security"] = options.Security + } + if options.enabledSetters["HttpUser"] { + params["httpUser"] = options.HttpUser + } + if options.enabledSetters["HttpPass"] { + params["httpPass"] = options.HttpPass + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Webhook{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Webhook + parsed, ok := resp.Result.(models.Webhook) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a webhook by its unique ID. This endpoint returns details about a +// specific webhook configured for a project. +func (srv *Webhooks) Get(WebhookId string)(*models.Webhook, error) { + r := strings.NewReplacer("{webhookId}", WebhookId) + path := r.Replace("/webhooks/{webhookId}") + params := map[string]interface{}{} + params["webhookId"] = WebhookId + 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.Webhook{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Webhook + parsed, ok := resp.Result.(models.Webhook) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOptions struct { + Enabled bool + Security bool + HttpUser string + HttpPass string + enabledSetters map[string]bool +} +func (options UpdateOptions) New() *UpdateOptions { + options.enabledSetters = map[string]bool{ + "Enabled": false, + "Security": false, + "HttpUser": false, + "HttpPass": false, + } + return &options +} +type UpdateOption func(*UpdateOptions) +func (srv *Webhooks) WithUpdateEnabled(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} +func (srv *Webhooks) WithUpdateSecurity(v bool) UpdateOption { + return func(o *UpdateOptions) { + o.Security = v + o.enabledSetters["Security"] = true + } +} +func (srv *Webhooks) WithUpdateHttpUser(v string) UpdateOption { + return func(o *UpdateOptions) { + o.HttpUser = v + o.enabledSetters["HttpUser"] = true + } +} +func (srv *Webhooks) WithUpdateHttpPass(v string) UpdateOption { + return func(o *UpdateOptions) { + o.HttpPass = v + o.enabledSetters["HttpPass"] = true + } +} + +// Update update a webhook by its unique ID. Use this endpoint to update the +// URL, events, or status of an existing webhook. +func (srv *Webhooks) Update(WebhookId string, Name string, Url string, Events []string, optionalSetters ...UpdateOption)(*models.Webhook, error) { + r := strings.NewReplacer("{webhookId}", WebhookId) + path := r.Replace("/webhooks/{webhookId}") + options := UpdateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["webhookId"] = WebhookId + params["name"] = Name + params["url"] = Url + params["events"] = Events + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + if options.enabledSetters["Security"] { + params["security"] = options.Security + } + if options.enabledSetters["HttpUser"] { + params["httpUser"] = options.HttpUser + } + if options.enabledSetters["HttpPass"] { + params["httpPass"] = options.HttpPass + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Webhook{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Webhook + parsed, ok := resp.Result.(models.Webhook) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a webhook by its unique ID. Once deleted, the webhook will no +// longer receive project events. +func (srv *Webhooks) Delete(WebhookId string)(*interface{}, error) { + r := strings.NewReplacer("{webhookId}", WebhookId) + path := r.Replace("/webhooks/{webhookId}") + params := map[string]interface{}{} + params["webhookId"] = WebhookId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateSignature update the webhook signature key. This endpoint can be used +// to regenerate the signature key used to sign and validate payload +// deliveries for a specific webhook. +func (srv *Webhooks) UpdateSignature(WebhookId string)(*models.Webhook, error) { + r := strings.NewReplacer("{webhookId}", WebhookId) + path := r.Replace("/webhooks/{webhookId}/signature") + params := map[string]interface{}{} + params["webhookId"] = WebhookId + 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.Webhook{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Webhook + parsed, ok := resp.Result.(models.Webhook) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} From e1c9b86ba3e8d01639c77d50fbeffce968ce5bf2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 04:26:05 +0000 Subject: [PATCH 2/6] chore: update Go SDK to v0.18.0 --- CHANGELOG.md | 3 ++- README.md | 2 +- client/client.go | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 644245d3..ded1808b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 0.18.0 -* Added `NewDocumentsDB`, `NewProject`, `NewVectorsDB`, and `NewWebhooks` client constructors +* [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents +* Added `NewProject` and `NewWebhooks` client constructors * Added impersonation helpers `WithImpersonateUserId`, `WithImpersonateUserEmail`, `WithImpersonateUserPhone` * Added avatar URL helpers: `GetBrowserURL`, `GetCreditCardURL`, `GetFaviconURL`, `GetFlagURL`, `GetImageURL`, `GetInitialsURL`, `GetQRURL`, `GetScreenshotURL` * Updated README badge to API version 1.9.0 diff --git a/README.md b/README.md index 54a69930..4e1a34f2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![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.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/client/client.go b/client/client.go index b7f2768e..52f8b23d 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/0.18.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.18.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "0.18.0", + "x-sdk-version": "v0.18.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { From be57fc56a3b65be7898f21fbb27961b577bb712c Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 05:27:57 +0000 Subject: [PATCH 3/6] chore: update Go SDK to v0.18.0 --- appwrite/appwrite.go | 8 - .../examples/documentsdb/create-collection.md | 28 - docs/examples/documentsdb/create-document.md | 31 - docs/examples/documentsdb/create-documents.md | 23 - docs/examples/documentsdb/create-index.md | 27 - .../examples/documentsdb/create-operations.md | 32 - .../documentsdb/create-transaction.md | 21 - docs/examples/documentsdb/create.md | 23 - .../decrement-document-attribute.md | 27 - .../examples/documentsdb/delete-collection.md | 22 - docs/examples/documentsdb/delete-document.md | 24 - docs/examples/documentsdb/delete-documents.md | 24 - docs/examples/documentsdb/delete-index.md | 23 - .../documentsdb/delete-transaction.md | 21 - docs/examples/documentsdb/delete.md | 21 - docs/examples/documentsdb/get-collection.md | 22 - docs/examples/documentsdb/get-document.md | 25 - docs/examples/documentsdb/get-index.md | 23 - docs/examples/documentsdb/get-transaction.md | 21 - docs/examples/documentsdb/get.md | 21 - .../increment-document-attribute.md | 27 - docs/examples/documentsdb/list-collections.md | 24 - docs/examples/documentsdb/list-documents.md | 26 - docs/examples/documentsdb/list-indexes.md | 24 - .../examples/documentsdb/list-transactions.md | 21 - docs/examples/documentsdb/list.md | 23 - .../examples/documentsdb/update-collection.md | 26 - docs/examples/documentsdb/update-document.md | 26 - docs/examples/documentsdb/update-documents.md | 25 - .../documentsdb/update-transaction.md | 23 - docs/examples/documentsdb/update.md | 23 - docs/examples/documentsdb/upsert-document.md | 26 - docs/examples/documentsdb/upsert-documents.md | 24 - docs/examples/vectorsdb/create-collection.md | 27 - docs/examples/vectorsdb/create-document.md | 35 - docs/examples/vectorsdb/create-documents.md | 23 - docs/examples/vectorsdb/create-index.md | 27 - docs/examples/vectorsdb/create-operations.md | 32 - .../vectorsdb/create-text-embeddings.md | 22 - docs/examples/vectorsdb/create-transaction.md | 21 - docs/examples/vectorsdb/create.md | 23 - docs/examples/vectorsdb/delete-collection.md | 22 - docs/examples/vectorsdb/delete-document.md | 24 - docs/examples/vectorsdb/delete-documents.md | 24 - docs/examples/vectorsdb/delete-index.md | 23 - docs/examples/vectorsdb/delete-transaction.md | 21 - docs/examples/vectorsdb/delete.md | 21 - docs/examples/vectorsdb/get-collection.md | 22 - docs/examples/vectorsdb/get-document.md | 25 - docs/examples/vectorsdb/get-index.md | 23 - docs/examples/vectorsdb/get-transaction.md | 21 - docs/examples/vectorsdb/get.md | 21 - docs/examples/vectorsdb/list-collections.md | 24 - docs/examples/vectorsdb/list-documents.md | 26 - docs/examples/vectorsdb/list-indexes.md | 24 - docs/examples/vectorsdb/list-transactions.md | 21 - docs/examples/vectorsdb/list.md | 23 - docs/examples/vectorsdb/update-collection.md | 27 - docs/examples/vectorsdb/update-document.md | 26 - docs/examples/vectorsdb/update-documents.md | 25 - docs/examples/vectorsdb/update-transaction.md | 23 - docs/examples/vectorsdb/update.md | 23 - docs/examples/vectorsdb/upsert-document.md | 26 - docs/examples/vectorsdb/upsert-documents.md | 24 - documentsdb/documents_db.go | 2051 ----------------- vectorsdb/vectors_db.go | 1900 --------------- 66 files changed, 5485 deletions(-) delete mode 100644 docs/examples/documentsdb/create-collection.md delete mode 100644 docs/examples/documentsdb/create-document.md delete mode 100644 docs/examples/documentsdb/create-documents.md delete mode 100644 docs/examples/documentsdb/create-index.md delete mode 100644 docs/examples/documentsdb/create-operations.md delete mode 100644 docs/examples/documentsdb/create-transaction.md delete mode 100644 docs/examples/documentsdb/create.md delete mode 100644 docs/examples/documentsdb/decrement-document-attribute.md delete mode 100644 docs/examples/documentsdb/delete-collection.md delete mode 100644 docs/examples/documentsdb/delete-document.md delete mode 100644 docs/examples/documentsdb/delete-documents.md delete mode 100644 docs/examples/documentsdb/delete-index.md delete mode 100644 docs/examples/documentsdb/delete-transaction.md delete mode 100644 docs/examples/documentsdb/delete.md delete mode 100644 docs/examples/documentsdb/get-collection.md delete mode 100644 docs/examples/documentsdb/get-document.md delete mode 100644 docs/examples/documentsdb/get-index.md delete mode 100644 docs/examples/documentsdb/get-transaction.md delete mode 100644 docs/examples/documentsdb/get.md delete mode 100644 docs/examples/documentsdb/increment-document-attribute.md delete mode 100644 docs/examples/documentsdb/list-collections.md delete mode 100644 docs/examples/documentsdb/list-documents.md delete mode 100644 docs/examples/documentsdb/list-indexes.md delete mode 100644 docs/examples/documentsdb/list-transactions.md delete mode 100644 docs/examples/documentsdb/list.md delete mode 100644 docs/examples/documentsdb/update-collection.md delete mode 100644 docs/examples/documentsdb/update-document.md delete mode 100644 docs/examples/documentsdb/update-documents.md delete mode 100644 docs/examples/documentsdb/update-transaction.md delete mode 100644 docs/examples/documentsdb/update.md delete mode 100644 docs/examples/documentsdb/upsert-document.md delete mode 100644 docs/examples/documentsdb/upsert-documents.md delete mode 100644 docs/examples/vectorsdb/create-collection.md delete mode 100644 docs/examples/vectorsdb/create-document.md delete mode 100644 docs/examples/vectorsdb/create-documents.md delete mode 100644 docs/examples/vectorsdb/create-index.md delete mode 100644 docs/examples/vectorsdb/create-operations.md delete mode 100644 docs/examples/vectorsdb/create-text-embeddings.md delete mode 100644 docs/examples/vectorsdb/create-transaction.md delete mode 100644 docs/examples/vectorsdb/create.md delete mode 100644 docs/examples/vectorsdb/delete-collection.md delete mode 100644 docs/examples/vectorsdb/delete-document.md delete mode 100644 docs/examples/vectorsdb/delete-documents.md delete mode 100644 docs/examples/vectorsdb/delete-index.md delete mode 100644 docs/examples/vectorsdb/delete-transaction.md delete mode 100644 docs/examples/vectorsdb/delete.md delete mode 100644 docs/examples/vectorsdb/get-collection.md delete mode 100644 docs/examples/vectorsdb/get-document.md delete mode 100644 docs/examples/vectorsdb/get-index.md delete mode 100644 docs/examples/vectorsdb/get-transaction.md delete mode 100644 docs/examples/vectorsdb/get.md delete mode 100644 docs/examples/vectorsdb/list-collections.md delete mode 100644 docs/examples/vectorsdb/list-documents.md delete mode 100644 docs/examples/vectorsdb/list-indexes.md delete mode 100644 docs/examples/vectorsdb/list-transactions.md delete mode 100644 docs/examples/vectorsdb/list.md delete mode 100644 docs/examples/vectorsdb/update-collection.md delete mode 100644 docs/examples/vectorsdb/update-document.md delete mode 100644 docs/examples/vectorsdb/update-documents.md delete mode 100644 docs/examples/vectorsdb/update-transaction.md delete mode 100644 docs/examples/vectorsdb/update.md delete mode 100644 docs/examples/vectorsdb/upsert-document.md delete mode 100644 docs/examples/vectorsdb/upsert-documents.md delete mode 100644 documentsdb/documents_db.go delete mode 100644 vectorsdb/vectors_db.go diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index b34e3e7b..1f965dbb 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -9,7 +9,6 @@ import ( "github.com/appwrite/sdk-for-go/avatars" "github.com/appwrite/sdk-for-go/backups" "github.com/appwrite/sdk-for-go/databases" - "github.com/appwrite/sdk-for-go/documentsdb" "github.com/appwrite/sdk-for-go/functions" "github.com/appwrite/sdk-for-go/graphql" "github.com/appwrite/sdk-for-go/health" @@ -22,7 +21,6 @@ import ( "github.com/appwrite/sdk-for-go/teams" "github.com/appwrite/sdk-for-go/tokens" "github.com/appwrite/sdk-for-go/users" - "github.com/appwrite/sdk-for-go/vectorsdb" "github.com/appwrite/sdk-for-go/webhooks" ) @@ -41,9 +39,6 @@ func NewBackups(clt client.Client) *backups.Backups { func NewDatabases(clt client.Client) *databases.Databases { return databases.New(clt) } -func NewDocumentsDB(clt client.Client) *documentsdb.DocumentsDB { - return documentsdb.New(clt) -} func NewFunctions(clt client.Client) *functions.Functions { return functions.New(clt) } @@ -80,9 +75,6 @@ func NewTokens(clt client.Client) *tokens.Tokens { func NewUsers(clt client.Client) *users.Users { return users.New(clt) } -func NewVectorsDB(clt client.Client) *vectorsdb.VectorsDB { - return vectorsdb.New(clt) -} func NewWebhooks(clt client.Client) *webhooks.Webhooks { return webhooks.New(clt) } diff --git a/docs/examples/documentsdb/create-collection.md b/docs/examples/documentsdb/create-collection.md deleted file mode 100644 index e70d6e18..00000000 --- a/docs/examples/documentsdb/create-collection.md +++ /dev/null @@ -1,28 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.CreateCollection( - "", - "", - "", - documentsdb.WithCreateCollectionPermissions(interface{}{"read("any")"}), - documentsdb.WithCreateCollectionDocumentSecurity(false), - documentsdb.WithCreateCollectionEnabled(false), - documentsdb.WithCreateCollectionAttributes([]interface{}{}), - documentsdb.WithCreateCollectionIndexes([]interface{}{}), -) -``` diff --git a/docs/examples/documentsdb/create-document.md b/docs/examples/documentsdb/create-document.md deleted file mode 100644 index 3d9bef2f..00000000 --- a/docs/examples/documentsdb/create-document.md +++ /dev/null @@ -1,31 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.CreateDocument( - "", - "", - "", - map[string]interface{}{ - "username": "walter.obrien", - "email": "walter.obrien@example.com", - "fullName": "Walter O'Brien", - "age": 30, - "isAdmin": false - }, - documentsdb.WithCreateDocumentPermissions(interface{}{"read("any")"}), -) -``` diff --git a/docs/examples/documentsdb/create-documents.md b/docs/examples/documentsdb/create-documents.md deleted file mode 100644 index aaa7ae80..00000000 --- a/docs/examples/documentsdb/create-documents.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.CreateDocuments( - "", - "", - []interface{}{}, -) -``` diff --git a/docs/examples/documentsdb/create-index.md b/docs/examples/documentsdb/create-index.md deleted file mode 100644 index e76d2417..00000000 --- a/docs/examples/documentsdb/create-index.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.CreateIndex( - "", - "", - "", - "key", - []interface{}{}, - documentsdb.WithCreateIndexOrders([]interface{}{}), - documentsdb.WithCreateIndexLengths([]interface{}{}), -) -``` diff --git a/docs/examples/documentsdb/create-operations.md b/docs/examples/documentsdb/create-operations.md deleted file mode 100644 index aaeae14c..00000000 --- a/docs/examples/documentsdb/create-operations.md +++ /dev/null @@ -1,32 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.CreateOperations( - "", - documentsdb.WithCreateOperationsOperations(interface{}{ - { - "action": "create", - "databaseId": "", - "collectionId": "", - "documentId": "", - "data": { - "name": "Walter O'Brien" - } - } - }), -) -``` diff --git a/docs/examples/documentsdb/create-transaction.md b/docs/examples/documentsdb/create-transaction.md deleted file mode 100644 index 5521a0d5..00000000 --- a/docs/examples/documentsdb/create-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.CreateTransaction( - documentsdb.WithCreateTransactionTtl(60), -) -``` diff --git a/docs/examples/documentsdb/create.md b/docs/examples/documentsdb/create.md deleted file mode 100644 index d4bd107c..00000000 --- a/docs/examples/documentsdb/create.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.Create( - "", - "", - documentsdb.WithCreateEnabled(false), -) -``` diff --git a/docs/examples/documentsdb/decrement-document-attribute.md b/docs/examples/documentsdb/decrement-document-attribute.md deleted file mode 100644 index a4d2306f..00000000 --- a/docs/examples/documentsdb/decrement-document-attribute.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.DecrementDocumentAttribute( - "", - "", - "", - "", - documentsdb.WithDecrementDocumentAttributeValue(0), - documentsdb.WithDecrementDocumentAttributeMin(0), - documentsdb.WithDecrementDocumentAttributeTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/delete-collection.md b/docs/examples/documentsdb/delete-collection.md deleted file mode 100644 index 80e5b0db..00000000 --- a/docs/examples/documentsdb/delete-collection.md +++ /dev/null @@ -1,22 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.DeleteCollection( - "", - "", -) -``` diff --git a/docs/examples/documentsdb/delete-document.md b/docs/examples/documentsdb/delete-document.md deleted file mode 100644 index 866134a6..00000000 --- a/docs/examples/documentsdb/delete-document.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.DeleteDocument( - "", - "", - "", - documentsdb.WithDeleteDocumentTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/delete-documents.md b/docs/examples/documentsdb/delete-documents.md deleted file mode 100644 index 7a60da37..00000000 --- a/docs/examples/documentsdb/delete-documents.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.DeleteDocuments( - "", - "", - documentsdb.WithDeleteDocumentsQueries([]interface{}{}), - documentsdb.WithDeleteDocumentsTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/delete-index.md b/docs/examples/documentsdb/delete-index.md deleted file mode 100644 index a7d84588..00000000 --- a/docs/examples/documentsdb/delete-index.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.DeleteIndex( - "", - "", - "", -) -``` diff --git a/docs/examples/documentsdb/delete-transaction.md b/docs/examples/documentsdb/delete-transaction.md deleted file mode 100644 index f809346c..00000000 --- a/docs/examples/documentsdb/delete-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.DeleteTransaction( - "", -) -``` diff --git a/docs/examples/documentsdb/delete.md b/docs/examples/documentsdb/delete.md deleted file mode 100644 index aeeb848f..00000000 --- a/docs/examples/documentsdb/delete.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.Delete( - "", -) -``` diff --git a/docs/examples/documentsdb/get-collection.md b/docs/examples/documentsdb/get-collection.md deleted file mode 100644 index a8d8ee67..00000000 --- a/docs/examples/documentsdb/get-collection.md +++ /dev/null @@ -1,22 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.GetCollection( - "", - "", -) -``` diff --git a/docs/examples/documentsdb/get-document.md b/docs/examples/documentsdb/get-document.md deleted file mode 100644 index bed4178c..00000000 --- a/docs/examples/documentsdb/get-document.md +++ /dev/null @@ -1,25 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.GetDocument( - "", - "", - "", - documentsdb.WithGetDocumentQueries([]interface{}{}), - documentsdb.WithGetDocumentTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/get-index.md b/docs/examples/documentsdb/get-index.md deleted file mode 100644 index 6def9a71..00000000 --- a/docs/examples/documentsdb/get-index.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.GetIndex( - "", - "", - "", -) -``` diff --git a/docs/examples/documentsdb/get-transaction.md b/docs/examples/documentsdb/get-transaction.md deleted file mode 100644 index bc2b00d2..00000000 --- a/docs/examples/documentsdb/get-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.GetTransaction( - "", -) -``` diff --git a/docs/examples/documentsdb/get.md b/docs/examples/documentsdb/get.md deleted file mode 100644 index 45a17357..00000000 --- a/docs/examples/documentsdb/get.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.Get( - "", -) -``` diff --git a/docs/examples/documentsdb/increment-document-attribute.md b/docs/examples/documentsdb/increment-document-attribute.md deleted file mode 100644 index 8c16ee5b..00000000 --- a/docs/examples/documentsdb/increment-document-attribute.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.IncrementDocumentAttribute( - "", - "", - "", - "", - documentsdb.WithIncrementDocumentAttributeValue(0), - documentsdb.WithIncrementDocumentAttributeMax(0), - documentsdb.WithIncrementDocumentAttributeTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/list-collections.md b/docs/examples/documentsdb/list-collections.md deleted file mode 100644 index 132a545b..00000000 --- a/docs/examples/documentsdb/list-collections.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.ListCollections( - "", - documentsdb.WithListCollectionsQueries([]interface{}{}), - documentsdb.WithListCollectionsSearch(""), - documentsdb.WithListCollectionsTotal(false), -) -``` diff --git a/docs/examples/documentsdb/list-documents.md b/docs/examples/documentsdb/list-documents.md deleted file mode 100644 index 729fac74..00000000 --- a/docs/examples/documentsdb/list-documents.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.ListDocuments( - "", - "", - documentsdb.WithListDocumentsQueries([]interface{}{}), - documentsdb.WithListDocumentsTransactionId(""), - documentsdb.WithListDocumentsTotal(false), - documentsdb.WithListDocumentsTtl(0), -) -``` diff --git a/docs/examples/documentsdb/list-indexes.md b/docs/examples/documentsdb/list-indexes.md deleted file mode 100644 index 130a37aa..00000000 --- a/docs/examples/documentsdb/list-indexes.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.ListIndexes( - "", - "", - documentsdb.WithListIndexesQueries([]interface{}{}), - documentsdb.WithListIndexesTotal(false), -) -``` diff --git a/docs/examples/documentsdb/list-transactions.md b/docs/examples/documentsdb/list-transactions.md deleted file mode 100644 index 88ab51d8..00000000 --- a/docs/examples/documentsdb/list-transactions.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.ListTransactions( - documentsdb.WithListTransactionsQueries([]interface{}{}), -) -``` diff --git a/docs/examples/documentsdb/list.md b/docs/examples/documentsdb/list.md deleted file mode 100644 index b8abf051..00000000 --- a/docs/examples/documentsdb/list.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.List( - documentsdb.WithListQueries([]interface{}{}), - documentsdb.WithListSearch(""), - documentsdb.WithListTotal(false), -) -``` diff --git a/docs/examples/documentsdb/update-collection.md b/docs/examples/documentsdb/update-collection.md deleted file mode 100644 index 4b7818cf..00000000 --- a/docs/examples/documentsdb/update-collection.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.UpdateCollection( - "", - "", - "", - documentsdb.WithUpdateCollectionPermissions(interface{}{"read("any")"}), - documentsdb.WithUpdateCollectionDocumentSecurity(false), - documentsdb.WithUpdateCollectionEnabled(false), -) -``` diff --git a/docs/examples/documentsdb/update-document.md b/docs/examples/documentsdb/update-document.md deleted file mode 100644 index d2f1e291..00000000 --- a/docs/examples/documentsdb/update-document.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.UpdateDocument( - "", - "", - "", - documentsdb.WithUpdateDocumentData(map[string]interface{}{}), - documentsdb.WithUpdateDocumentPermissions(interface{}{"read("any")"}), - documentsdb.WithUpdateDocumentTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/update-documents.md b/docs/examples/documentsdb/update-documents.md deleted file mode 100644 index 7f08b6e4..00000000 --- a/docs/examples/documentsdb/update-documents.md +++ /dev/null @@ -1,25 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.UpdateDocuments( - "", - "", - documentsdb.WithUpdateDocumentsData(map[string]interface{}{}), - documentsdb.WithUpdateDocumentsQueries([]interface{}{}), - documentsdb.WithUpdateDocumentsTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/update-transaction.md b/docs/examples/documentsdb/update-transaction.md deleted file mode 100644 index 1e486544..00000000 --- a/docs/examples/documentsdb/update-transaction.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.UpdateTransaction( - "", - documentsdb.WithUpdateTransactionCommit(false), - documentsdb.WithUpdateTransactionRollback(false), -) -``` diff --git a/docs/examples/documentsdb/update.md b/docs/examples/documentsdb/update.md deleted file mode 100644 index 5adf7265..00000000 --- a/docs/examples/documentsdb/update.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.Update( - "", - "", - documentsdb.WithUpdateEnabled(false), -) -``` diff --git a/docs/examples/documentsdb/upsert-document.md b/docs/examples/documentsdb/upsert-document.md deleted file mode 100644 index 5ef42be1..00000000 --- a/docs/examples/documentsdb/upsert-document.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := documentsdb.New(client) - -response, error := service.UpsertDocument( - "", - "", - "", - documentsdb.WithUpsertDocumentData(map[string]interface{}{}), - documentsdb.WithUpsertDocumentPermissions(interface{}{"read("any")"}), - documentsdb.WithUpsertDocumentTransactionId(""), -) -``` diff --git a/docs/examples/documentsdb/upsert-documents.md b/docs/examples/documentsdb/upsert-documents.md deleted file mode 100644 index 03ec1ff1..00000000 --- a/docs/examples/documentsdb/upsert-documents.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/documentsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := documentsdb.New(client) - -response, error := service.UpsertDocuments( - "", - "", - []interface{}{}, - documentsdb.WithUpsertDocumentsTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/create-collection.md b/docs/examples/vectorsdb/create-collection.md deleted file mode 100644 index 59e6af99..00000000 --- a/docs/examples/vectorsdb/create-collection.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateCollection( - "", - "", - "", - 1, - vectorsdb.WithCreateCollectionPermissions(interface{}{"read("any")"}), - vectorsdb.WithCreateCollectionDocumentSecurity(false), - vectorsdb.WithCreateCollectionEnabled(false), -) -``` diff --git a/docs/examples/vectorsdb/create-document.md b/docs/examples/vectorsdb/create-document.md deleted file mode 100644 index 0b859790..00000000 --- a/docs/examples/vectorsdb/create-document.md +++ /dev/null @@ -1,35 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateDocument( - "", - "", - "", - map[string]interface{}{ - "embeddings": [ - 0.12, - -0.55, - 0.88, - 1.02 - ], - "metadata": { - "key": "value" - } - }, - vectorsdb.WithCreateDocumentPermissions(interface{}{"read("any")"}), -) -``` diff --git a/docs/examples/vectorsdb/create-documents.md b/docs/examples/vectorsdb/create-documents.md deleted file mode 100644 index 861974ec..00000000 --- a/docs/examples/vectorsdb/create-documents.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateDocuments( - "", - "", - []interface{}{}, -) -``` diff --git a/docs/examples/vectorsdb/create-index.md b/docs/examples/vectorsdb/create-index.md deleted file mode 100644 index 5cf29cec..00000000 --- a/docs/examples/vectorsdb/create-index.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateIndex( - "", - "", - "", - "hnsw_euclidean", - []interface{}{}, - vectorsdb.WithCreateIndexOrders([]interface{}{}), - vectorsdb.WithCreateIndexLengths([]interface{}{}), -) -``` diff --git a/docs/examples/vectorsdb/create-operations.md b/docs/examples/vectorsdb/create-operations.md deleted file mode 100644 index 4237e435..00000000 --- a/docs/examples/vectorsdb/create-operations.md +++ /dev/null @@ -1,32 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateOperations( - "", - vectorsdb.WithCreateOperationsOperations(interface{}{ - { - "action": "create", - "databaseId": "", - "collectionId": "", - "documentId": "", - "data": { - "name": "Walter O'Brien" - } - } - }), -) -``` diff --git a/docs/examples/vectorsdb/create-text-embeddings.md b/docs/examples/vectorsdb/create-text-embeddings.md deleted file mode 100644 index ec998970..00000000 --- a/docs/examples/vectorsdb/create-text-embeddings.md +++ /dev/null @@ -1,22 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateTextEmbeddings( - []interface{}{}, - vectorsdb.WithCreateTextEmbeddingsModel("embeddinggemma"), -) -``` diff --git a/docs/examples/vectorsdb/create-transaction.md b/docs/examples/vectorsdb/create-transaction.md deleted file mode 100644 index 28e1bc7a..00000000 --- a/docs/examples/vectorsdb/create-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.CreateTransaction( - vectorsdb.WithCreateTransactionTtl(60), -) -``` diff --git a/docs/examples/vectorsdb/create.md b/docs/examples/vectorsdb/create.md deleted file mode 100644 index fbc2ebdd..00000000 --- a/docs/examples/vectorsdb/create.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.Create( - "", - "", - vectorsdb.WithCreateEnabled(false), -) -``` diff --git a/docs/examples/vectorsdb/delete-collection.md b/docs/examples/vectorsdb/delete-collection.md deleted file mode 100644 index edc10b22..00000000 --- a/docs/examples/vectorsdb/delete-collection.md +++ /dev/null @@ -1,22 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.DeleteCollection( - "", - "", -) -``` diff --git a/docs/examples/vectorsdb/delete-document.md b/docs/examples/vectorsdb/delete-document.md deleted file mode 100644 index c6eba01a..00000000 --- a/docs/examples/vectorsdb/delete-document.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.DeleteDocument( - "", - "", - "", - vectorsdb.WithDeleteDocumentTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/delete-documents.md b/docs/examples/vectorsdb/delete-documents.md deleted file mode 100644 index 925b9d0b..00000000 --- a/docs/examples/vectorsdb/delete-documents.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.DeleteDocuments( - "", - "", - vectorsdb.WithDeleteDocumentsQueries([]interface{}{}), - vectorsdb.WithDeleteDocumentsTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/delete-index.md b/docs/examples/vectorsdb/delete-index.md deleted file mode 100644 index 67767694..00000000 --- a/docs/examples/vectorsdb/delete-index.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.DeleteIndex( - "", - "", - "", -) -``` diff --git a/docs/examples/vectorsdb/delete-transaction.md b/docs/examples/vectorsdb/delete-transaction.md deleted file mode 100644 index e0f69c58..00000000 --- a/docs/examples/vectorsdb/delete-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.DeleteTransaction( - "", -) -``` diff --git a/docs/examples/vectorsdb/delete.md b/docs/examples/vectorsdb/delete.md deleted file mode 100644 index 432b05b5..00000000 --- a/docs/examples/vectorsdb/delete.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.Delete( - "", -) -``` diff --git a/docs/examples/vectorsdb/get-collection.md b/docs/examples/vectorsdb/get-collection.md deleted file mode 100644 index 80b7546d..00000000 --- a/docs/examples/vectorsdb/get-collection.md +++ /dev/null @@ -1,22 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.GetCollection( - "", - "", -) -``` diff --git a/docs/examples/vectorsdb/get-document.md b/docs/examples/vectorsdb/get-document.md deleted file mode 100644 index 95704a68..00000000 --- a/docs/examples/vectorsdb/get-document.md +++ /dev/null @@ -1,25 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.GetDocument( - "", - "", - "", - vectorsdb.WithGetDocumentQueries([]interface{}{}), - vectorsdb.WithGetDocumentTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/get-index.md b/docs/examples/vectorsdb/get-index.md deleted file mode 100644 index 229ac812..00000000 --- a/docs/examples/vectorsdb/get-index.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.GetIndex( - "", - "", - "", -) -``` diff --git a/docs/examples/vectorsdb/get-transaction.md b/docs/examples/vectorsdb/get-transaction.md deleted file mode 100644 index 4eff8fd4..00000000 --- a/docs/examples/vectorsdb/get-transaction.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.GetTransaction( - "", -) -``` diff --git a/docs/examples/vectorsdb/get.md b/docs/examples/vectorsdb/get.md deleted file mode 100644 index 4ebc8208..00000000 --- a/docs/examples/vectorsdb/get.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.Get( - "", -) -``` diff --git a/docs/examples/vectorsdb/list-collections.md b/docs/examples/vectorsdb/list-collections.md deleted file mode 100644 index e9911dee..00000000 --- a/docs/examples/vectorsdb/list-collections.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.ListCollections( - "", - vectorsdb.WithListCollectionsQueries([]interface{}{}), - vectorsdb.WithListCollectionsSearch(""), - vectorsdb.WithListCollectionsTotal(false), -) -``` diff --git a/docs/examples/vectorsdb/list-documents.md b/docs/examples/vectorsdb/list-documents.md deleted file mode 100644 index 213cc08c..00000000 --- a/docs/examples/vectorsdb/list-documents.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.ListDocuments( - "", - "", - vectorsdb.WithListDocumentsQueries([]interface{}{}), - vectorsdb.WithListDocumentsTransactionId(""), - vectorsdb.WithListDocumentsTotal(false), - vectorsdb.WithListDocumentsTtl(0), -) -``` diff --git a/docs/examples/vectorsdb/list-indexes.md b/docs/examples/vectorsdb/list-indexes.md deleted file mode 100644 index 0bb7f137..00000000 --- a/docs/examples/vectorsdb/list-indexes.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.ListIndexes( - "", - "", - vectorsdb.WithListIndexesQueries([]interface{}{}), - vectorsdb.WithListIndexesTotal(false), -) -``` diff --git a/docs/examples/vectorsdb/list-transactions.md b/docs/examples/vectorsdb/list-transactions.md deleted file mode 100644 index 5e99c3e2..00000000 --- a/docs/examples/vectorsdb/list-transactions.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.ListTransactions( - vectorsdb.WithListTransactionsQueries([]interface{}{}), -) -``` diff --git a/docs/examples/vectorsdb/list.md b/docs/examples/vectorsdb/list.md deleted file mode 100644 index 8b0cfd5c..00000000 --- a/docs/examples/vectorsdb/list.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.List( - vectorsdb.WithListQueries([]interface{}{}), - vectorsdb.WithListSearch(""), - vectorsdb.WithListTotal(false), -) -``` diff --git a/docs/examples/vectorsdb/update-collection.md b/docs/examples/vectorsdb/update-collection.md deleted file mode 100644 index 41c76930..00000000 --- a/docs/examples/vectorsdb/update-collection.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.UpdateCollection( - "", - "", - "", - vectorsdb.WithUpdateCollectionDimension(1), - vectorsdb.WithUpdateCollectionPermissions(interface{}{"read("any")"}), - vectorsdb.WithUpdateCollectionDocumentSecurity(false), - vectorsdb.WithUpdateCollectionEnabled(false), -) -``` diff --git a/docs/examples/vectorsdb/update-document.md b/docs/examples/vectorsdb/update-document.md deleted file mode 100644 index 00cb38e4..00000000 --- a/docs/examples/vectorsdb/update-document.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.UpdateDocument( - "", - "", - "", - vectorsdb.WithUpdateDocumentData(map[string]interface{}{}), - vectorsdb.WithUpdateDocumentPermissions(interface{}{"read("any")"}), - vectorsdb.WithUpdateDocumentTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/update-documents.md b/docs/examples/vectorsdb/update-documents.md deleted file mode 100644 index f44e9f95..00000000 --- a/docs/examples/vectorsdb/update-documents.md +++ /dev/null @@ -1,25 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.UpdateDocuments( - "", - "", - vectorsdb.WithUpdateDocumentsData(map[string]interface{}{}), - vectorsdb.WithUpdateDocumentsQueries([]interface{}{}), - vectorsdb.WithUpdateDocumentsTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/update-transaction.md b/docs/examples/vectorsdb/update-transaction.md deleted file mode 100644 index 349913b8..00000000 --- a/docs/examples/vectorsdb/update-transaction.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.UpdateTransaction( - "", - vectorsdb.WithUpdateTransactionCommit(false), - vectorsdb.WithUpdateTransactionRollback(false), -) -``` diff --git a/docs/examples/vectorsdb/update.md b/docs/examples/vectorsdb/update.md deleted file mode 100644 index c4591fd4..00000000 --- a/docs/examples/vectorsdb/update.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.Update( - "", - "", - vectorsdb.WithUpdateEnabled(false), -) -``` diff --git a/docs/examples/vectorsdb/upsert-document.md b/docs/examples/vectorsdb/upsert-document.md deleted file mode 100644 index 0e824161..00000000 --- a/docs/examples/vectorsdb/upsert-document.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithSession("") -) - -service := vectorsdb.New(client) - -response, error := service.UpsertDocument( - "", - "", - "", - vectorsdb.WithUpsertDocumentData(map[string]interface{}{}), - vectorsdb.WithUpsertDocumentPermissions(interface{}{"read("any")"}), - vectorsdb.WithUpsertDocumentTransactionId(""), -) -``` diff --git a/docs/examples/vectorsdb/upsert-documents.md b/docs/examples/vectorsdb/upsert-documents.md deleted file mode 100644 index b53f316b..00000000 --- a/docs/examples/vectorsdb/upsert-documents.md +++ /dev/null @@ -1,24 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/vectorsdb" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := vectorsdb.New(client) - -response, error := service.UpsertDocuments( - "", - "", - []interface{}{}, - vectorsdb.WithUpsertDocumentsTransactionId(""), -) -``` diff --git a/documentsdb/documents_db.go b/documentsdb/documents_db.go deleted file mode 100644 index 53faff2c..00000000 --- a/documentsdb/documents_db.go +++ /dev/null @@ -1,2051 +0,0 @@ -package documentsdb - -import ( - "encoding/json" - "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" - "strings" -) - -// DocumentsDB service -type DocumentsDB struct { - client client.Client -} - -func New(clt client.Client) *DocumentsDB { - return &DocumentsDB{ - client: clt, - } -} - -type ListOptions struct { - Queries []string - Search string - Total bool - enabledSetters map[string]bool -} -func (options ListOptions) New() *ListOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Search": false, - "Total": false, - } - return &options -} -type ListOption func(*ListOptions) -func (srv *DocumentsDB) WithListQueries(v []string) ListOption { - return func(o *ListOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithListSearch(v string) ListOption { - return func(o *ListOptions) { - o.Search = v - o.enabledSetters["Search"] = true - } -} -func (srv *DocumentsDB) WithListTotal(v bool) ListOption { - return func(o *ListOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// List get a list of all databases from the current Appwrite project. You can -// use the search parameter to filter your results. -func (srv *DocumentsDB) List(optionalSetters ...ListOption)(*models.DatabaseList, error) { - path := "/documentsdb" - options := ListOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Search"] { - params["search"] = options.Search - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.DatabaseList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DatabaseList - parsed, ok := resp.Result.(models.DatabaseList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateOptions struct { - Enabled bool - enabledSetters map[string]bool -} -func (options CreateOptions) New() *CreateOptions { - options.enabledSetters = map[string]bool{ - "Enabled": false, - } - return &options -} -type CreateOption func(*CreateOptions) -func (srv *DocumentsDB) WithCreateEnabled(v bool) CreateOption { - return func(o *CreateOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// Create create a new Database. -func (srv *DocumentsDB) Create(DatabaseId string, Name string, optionalSetters ...CreateOption)(*models.Database, error) { - path := "/documentsdb" - options := CreateOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["name"] = Name - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListTransactionsOptions struct { - Queries []string - enabledSetters map[string]bool -} -func (options ListTransactionsOptions) New() *ListTransactionsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - } - return &options -} -type ListTransactionsOption func(*ListTransactionsOptions) -func (srv *DocumentsDB) WithListTransactionsQueries(v []string) ListTransactionsOption { - return func(o *ListTransactionsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} - -// ListTransactions -func (srv *DocumentsDB) ListTransactions(optionalSetters ...ListTransactionsOption)(*models.TransactionList, error) { - path := "/documentsdb/transactions" - options := ListTransactionsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - 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.TransactionList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.TransactionList - parsed, ok := resp.Result.(models.TransactionList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateTransactionOptions struct { - Ttl int - enabledSetters map[string]bool -} -func (options CreateTransactionOptions) New() *CreateTransactionOptions { - options.enabledSetters = map[string]bool{ - "Ttl": false, - } - return &options -} -type CreateTransactionOption func(*CreateTransactionOptions) -func (srv *DocumentsDB) WithCreateTransactionTtl(v int) CreateTransactionOption { - return func(o *CreateTransactionOptions) { - o.Ttl = v - o.enabledSetters["Ttl"] = true - } -} - -// CreateTransaction -func (srv *DocumentsDB) CreateTransaction(optionalSetters ...CreateTransactionOption)(*models.Transaction, error) { - path := "/documentsdb/transactions" - options := CreateTransactionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Ttl"] { - params["ttl"] = options.Ttl - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetTransaction -func (srv *DocumentsDB) GetTransaction(TransactionId string)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/documentsdb/transactions/{transactionId}") - params := map[string]interface{}{} - params["transactionId"] = TransactionId - 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.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateTransactionOptions struct { - Commit bool - Rollback bool - enabledSetters map[string]bool -} -func (options UpdateTransactionOptions) New() *UpdateTransactionOptions { - options.enabledSetters = map[string]bool{ - "Commit": false, - "Rollback": false, - } - return &options -} -type UpdateTransactionOption func(*UpdateTransactionOptions) -func (srv *DocumentsDB) WithUpdateTransactionCommit(v bool) UpdateTransactionOption { - return func(o *UpdateTransactionOptions) { - o.Commit = v - o.enabledSetters["Commit"] = true - } -} -func (srv *DocumentsDB) WithUpdateTransactionRollback(v bool) UpdateTransactionOption { - return func(o *UpdateTransactionOptions) { - o.Rollback = v - o.enabledSetters["Rollback"] = true - } -} - -// UpdateTransaction -func (srv *DocumentsDB) UpdateTransaction(TransactionId string, optionalSetters ...UpdateTransactionOption)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/documentsdb/transactions/{transactionId}") - options := UpdateTransactionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["transactionId"] = TransactionId - if options.enabledSetters["Commit"] { - params["commit"] = options.Commit - } - if options.enabledSetters["Rollback"] { - params["rollback"] = options.Rollback - } - 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.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteTransaction -func (srv *DocumentsDB) DeleteTransaction(TransactionId string)(*interface{}, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/documentsdb/transactions/{transactionId}") - params := map[string]interface{}{} - params["transactionId"] = TransactionId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateOperationsOptions struct { - Operations []interface{} - enabledSetters map[string]bool -} -func (options CreateOperationsOptions) New() *CreateOperationsOptions { - options.enabledSetters = map[string]bool{ - "Operations": false, - } - return &options -} -type CreateOperationsOption func(*CreateOperationsOptions) -func (srv *DocumentsDB) WithCreateOperationsOperations(v []interface{}) CreateOperationsOption { - return func(o *CreateOperationsOptions) { - o.Operations = v - o.enabledSetters["Operations"] = true - } -} - -// CreateOperations -func (srv *DocumentsDB) CreateOperations(TransactionId string, optionalSetters ...CreateOperationsOption)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/documentsdb/transactions/{transactionId}/operations") - options := CreateOperationsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["transactionId"] = TransactionId - if options.enabledSetters["Operations"] { - params["operations"] = options.Operations - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Get get a database by its unique ID. This endpoint response returns a JSON -// object with the database metadata. -func (srv *DocumentsDB) Get(DatabaseId string)(*models.Database, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/documentsdb/{databaseId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - 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.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateOptions struct { - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOptions) New() *UpdateOptions { - options.enabledSetters = map[string]bool{ - "Enabled": false, - } - return &options -} -type UpdateOption func(*UpdateOptions) -func (srv *DocumentsDB) WithUpdateEnabled(v bool) UpdateOption { - return func(o *UpdateOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// Update update a database by its unique ID. -func (srv *DocumentsDB) Update(DatabaseId string, Name string, optionalSetters ...UpdateOption)(*models.Database, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/documentsdb/{databaseId}") - options := UpdateOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["name"] = Name - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Delete delete a database by its unique ID. Only API keys with with -// databases.write scope can delete a database. -func (srv *DocumentsDB) Delete(DatabaseId string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/documentsdb/{databaseId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListCollectionsOptions struct { - Queries []string - Search string - Total bool - enabledSetters map[string]bool -} -func (options ListCollectionsOptions) New() *ListCollectionsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Search": false, - "Total": false, - } - return &options -} -type ListCollectionsOption func(*ListCollectionsOptions) -func (srv *DocumentsDB) WithListCollectionsQueries(v []string) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithListCollectionsSearch(v string) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Search = v - o.enabledSetters["Search"] = true - } -} -func (srv *DocumentsDB) WithListCollectionsTotal(v bool) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// ListCollections get a list of all collections that belong to the provided -// databaseId. You can use the search parameter to filter your results. -func (srv *DocumentsDB) ListCollections(DatabaseId string, optionalSetters ...ListCollectionsOption)(*models.CollectionList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/documentsdb/{databaseId}/collections") - options := ListCollectionsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Search"] { - params["search"] = options.Search - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.CollectionList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.CollectionList - parsed, ok := resp.Result.(models.CollectionList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateCollectionOptions struct { - Permissions []string - DocumentSecurity bool - Enabled bool - Attributes []interface{} - Indexes []interface{} - enabledSetters map[string]bool -} -func (options CreateCollectionOptions) New() *CreateCollectionOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - "DocumentSecurity": false, - "Enabled": false, - "Attributes": false, - "Indexes": false, - } - return &options -} -type CreateCollectionOption func(*CreateCollectionOptions) -func (srv *DocumentsDB) WithCreateCollectionPermissions(v []string) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *DocumentsDB) WithCreateCollectionDocumentSecurity(v bool) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.DocumentSecurity = v - o.enabledSetters["DocumentSecurity"] = true - } -} -func (srv *DocumentsDB) WithCreateCollectionEnabled(v bool) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} -func (srv *DocumentsDB) WithCreateCollectionAttributes(v []interface{}) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Attributes = v - o.enabledSetters["Attributes"] = true - } -} -func (srv *DocumentsDB) WithCreateCollectionIndexes(v []interface{}) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Indexes = v - o.enabledSetters["Indexes"] = true - } -} - -// CreateCollection create a new Collection. Before using this route, you -// should create a new database resource using either a [server -// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) -// API or directly from your database console. -func (srv *DocumentsDB) CreateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...CreateCollectionOption)(*models.Collection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/documentsdb/{databaseId}/collections") - options := CreateCollectionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["name"] = Name - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["DocumentSecurity"] { - params["documentSecurity"] = options.DocumentSecurity - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - if options.enabledSetters["Attributes"] { - params["attributes"] = options.Attributes - } - if options.enabledSetters["Indexes"] { - params["indexes"] = options.Indexes - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Collection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Collection - parsed, ok := resp.Result.(models.Collection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetCollection get a collection by its unique ID. This endpoint response -// returns a JSON object with the collection metadata. -func (srv *DocumentsDB) GetCollection(DatabaseId string, CollectionId string)(*models.Collection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - 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.Collection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Collection - parsed, ok := resp.Result.(models.Collection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateCollectionOptions struct { - Permissions []string - DocumentSecurity bool - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateCollectionOptions) New() *UpdateCollectionOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - "DocumentSecurity": false, - "Enabled": false, - } - return &options -} -type UpdateCollectionOption func(*UpdateCollectionOptions) -func (srv *DocumentsDB) WithUpdateCollectionPermissions(v []string) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *DocumentsDB) WithUpdateCollectionDocumentSecurity(v bool) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.DocumentSecurity = v - o.enabledSetters["DocumentSecurity"] = true - } -} -func (srv *DocumentsDB) WithUpdateCollectionEnabled(v bool) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateCollection update a collection by its unique ID. -func (srv *DocumentsDB) UpdateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...UpdateCollectionOption)(*models.Collection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") - options := UpdateCollectionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["name"] = Name - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["DocumentSecurity"] { - params["documentSecurity"] = options.DocumentSecurity - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Collection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Collection - parsed, ok := resp.Result.(models.Collection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteCollection delete a collection by its unique ID. Only users with -// write permissions have access to delete this resource. -func (srv *DocumentsDB) DeleteCollection(DatabaseId string, CollectionId string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - 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 -} -type ListDocumentsOption func(*ListDocumentsOptions) -func (srv *DocumentsDB) WithListDocumentsQueries(v []string) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithListDocumentsTransactionId(v string) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} -func (srv *DocumentsDB) WithListDocumentsTotal(v bool) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} -func (srv *DocumentsDB) 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. -func (srv *DocumentsDB) ListDocuments(DatabaseId string, CollectionId string, optionalSetters ...ListDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - options := ListDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - if options.enabledSetters["Ttl"] { - params["ttl"] = options.Ttl - } - 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.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateDocumentOptions struct { - Permissions []string - enabledSetters map[string]bool -} -func (options CreateDocumentOptions) New() *CreateDocumentOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - } - return &options -} -type CreateDocumentOption func(*CreateDocumentOptions) -func (srv *DocumentsDB) WithCreateDocumentPermissions(v []string) CreateDocumentOption { - return func(o *CreateDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} - -// CreateDocument create a new Document. Before using this route, you should -// create a new collection resource using either a [server -// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) -// API or directly from your database console. -func (srv *DocumentsDB) CreateDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...CreateDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - options := CreateDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - params["data"] = Data - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// CreateDocuments 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#documentsDBCreateCollection) -// API or directly from your database console. -func (srv *DocumentsDB) CreateDocuments(DatabaseId string, CollectionId string, Documents []interface{})(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documents"] = Documents - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpsertDocumentsOptions struct { - TransactionId string - enabledSetters map[string]bool -} -func (options UpsertDocumentsOptions) New() *UpsertDocumentsOptions { - options.enabledSetters = map[string]bool{ - "TransactionId": false, - } - return &options -} -type UpsertDocumentsOption func(*UpsertDocumentsOptions) -func (srv *DocumentsDB) WithUpsertDocumentsTransactionId(v string) UpsertDocumentsOption { - return func(o *UpsertDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpsertDocuments 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#documentsDBCreateCollection) -// API or directly from your database console. -func (srv *DocumentsDB) UpsertDocuments(DatabaseId string, CollectionId string, Documents []interface{}, optionalSetters ...UpsertDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - options := UpsertDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documents"] = Documents - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateDocumentsOptions struct { - Data interface{} - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpdateDocumentsOptions) New() *UpdateDocumentsOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Queries": false, - "TransactionId": false, - } - return &options -} -type UpdateDocumentsOption func(*UpdateDocumentsOptions) -func (srv *DocumentsDB) WithUpdateDocumentsData(v interface{}) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *DocumentsDB) WithUpdateDocumentsQueries(v []string) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithUpdateDocumentsTransactionId(v string) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpdateDocuments 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. -func (srv *DocumentsDB) UpdateDocuments(DatabaseId string, CollectionId string, optionalSetters ...UpdateDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - options := UpdateDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type DeleteDocumentsOptions struct { - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options DeleteDocumentsOptions) New() *DeleteDocumentsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "TransactionId": false, - } - return &options -} -type DeleteDocumentsOption func(*DeleteDocumentsOptions) -func (srv *DocumentsDB) WithDeleteDocumentsQueries(v []string) DeleteDocumentsOption { - return func(o *DeleteDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithDeleteDocumentsTransactionId(v string) DeleteDocumentsOption { - return func(o *DeleteDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// DeleteDocuments bulk delete documents using queries, if no queries are -// passed then all documents are deleted. -func (srv *DocumentsDB) DeleteDocuments(DatabaseId string, CollectionId string, optionalSetters ...DeleteDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents") - options := DeleteDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type GetDocumentOptions struct { - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options GetDocumentOptions) New() *GetDocumentOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "TransactionId": false, - } - return &options -} -type GetDocumentOption func(*GetDocumentOptions) -func (srv *DocumentsDB) WithGetDocumentQueries(v []string) GetDocumentOption { - return func(o *GetDocumentOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithGetDocumentTransactionId(v string) GetDocumentOption { - return func(o *GetDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// GetDocument get a document by its unique ID. This endpoint response returns -// a JSON object with the document data. -func (srv *DocumentsDB) GetDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...GetDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := GetDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpsertDocumentOptions struct { - Data interface{} - Permissions []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpsertDocumentOptions) New() *UpsertDocumentOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Permissions": false, - "TransactionId": false, - } - return &options -} -type UpsertDocumentOption func(*UpsertDocumentOptions) -func (srv *DocumentsDB) WithUpsertDocumentData(v interface{}) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *DocumentsDB) WithUpsertDocumentPermissions(v []string) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *DocumentsDB) WithUpsertDocumentTransactionId(v string) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpsertDocument create or update a Document. Before using this route, you -// should create a new collection resource using either a [server -// integration](https://appwrite.io/docs/server/databases#documentsDBCreateCollection) -// API or directly from your database console. -func (srv *DocumentsDB) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := UpsertDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateDocumentOptions struct { - Data interface{} - Permissions []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpdateDocumentOptions) New() *UpdateDocumentOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Permissions": false, - "TransactionId": false, - } - return &options -} -type UpdateDocumentOption func(*UpdateDocumentOptions) -func (srv *DocumentsDB) WithUpdateDocumentData(v interface{}) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *DocumentsDB) WithUpdateDocumentPermissions(v []string) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *DocumentsDB) WithUpdateDocumentTransactionId(v string) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpdateDocument update a document by its unique ID. Using the patch method -// you can pass only specific fields that will get updated. -func (srv *DocumentsDB) UpdateDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpdateDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := UpdateDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type DeleteDocumentOptions struct { - TransactionId string - enabledSetters map[string]bool -} -func (options DeleteDocumentOptions) New() *DeleteDocumentOptions { - options.enabledSetters = map[string]bool{ - "TransactionId": false, - } - return &options -} -type DeleteDocumentOption func(*DeleteDocumentOptions) -func (srv *DocumentsDB) WithDeleteDocumentTransactionId(v string) DeleteDocumentOption { - return func(o *DeleteDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// DeleteDocument delete a document by its unique ID. -func (srv *DocumentsDB) DeleteDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...DeleteDocumentOption)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := DeleteDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type DecrementDocumentAttributeOptions struct { - Value float64 - Min float64 - TransactionId string - enabledSetters map[string]bool -} -func (options DecrementDocumentAttributeOptions) New() *DecrementDocumentAttributeOptions { - options.enabledSetters = map[string]bool{ - "Value": false, - "Min": false, - "TransactionId": false, - } - return &options -} -type DecrementDocumentAttributeOption func(*DecrementDocumentAttributeOptions) -func (srv *DocumentsDB) WithDecrementDocumentAttributeValue(v float64) DecrementDocumentAttributeOption { - return func(o *DecrementDocumentAttributeOptions) { - o.Value = v - o.enabledSetters["Value"] = true - } -} -func (srv *DocumentsDB) WithDecrementDocumentAttributeMin(v float64) DecrementDocumentAttributeOption { - return func(o *DecrementDocumentAttributeOptions) { - o.Min = v - o.enabledSetters["Min"] = true - } -} -func (srv *DocumentsDB) WithDecrementDocumentAttributeTransactionId(v string) DecrementDocumentAttributeOption { - return func(o *DecrementDocumentAttributeOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// DecrementDocumentAttribute decrement a specific column of a row by a given -// value. -func (srv *DocumentsDB) DecrementDocumentAttribute(DatabaseId string, CollectionId string, DocumentId string, Attribute string, optionalSetters ...DecrementDocumentAttributeOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId, "{attribute}", Attribute) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement") - options := DecrementDocumentAttributeOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - params["attribute"] = Attribute - if options.enabledSetters["Value"] { - params["value"] = options.Value - } - if options.enabledSetters["Min"] { - params["min"] = options.Min - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type IncrementDocumentAttributeOptions struct { - Value float64 - Max float64 - TransactionId string - enabledSetters map[string]bool -} -func (options IncrementDocumentAttributeOptions) New() *IncrementDocumentAttributeOptions { - options.enabledSetters = map[string]bool{ - "Value": false, - "Max": false, - "TransactionId": false, - } - return &options -} -type IncrementDocumentAttributeOption func(*IncrementDocumentAttributeOptions) -func (srv *DocumentsDB) WithIncrementDocumentAttributeValue(v float64) IncrementDocumentAttributeOption { - return func(o *IncrementDocumentAttributeOptions) { - o.Value = v - o.enabledSetters["Value"] = true - } -} -func (srv *DocumentsDB) WithIncrementDocumentAttributeMax(v float64) IncrementDocumentAttributeOption { - return func(o *IncrementDocumentAttributeOptions) { - o.Max = v - o.enabledSetters["Max"] = true - } -} -func (srv *DocumentsDB) WithIncrementDocumentAttributeTransactionId(v string) IncrementDocumentAttributeOption { - return func(o *IncrementDocumentAttributeOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// IncrementDocumentAttribute increment a specific column of a row by a given -// value. -func (srv *DocumentsDB) IncrementDocumentAttribute(DatabaseId string, CollectionId string, DocumentId string, Attribute string, optionalSetters ...IncrementDocumentAttributeOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId, "{attribute}", Attribute) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment") - options := IncrementDocumentAttributeOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - params["attribute"] = Attribute - if options.enabledSetters["Value"] { - params["value"] = options.Value - } - if options.enabledSetters["Max"] { - params["max"] = options.Max - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListIndexesOptions struct { - Queries []string - Total bool - enabledSetters map[string]bool -} -func (options ListIndexesOptions) New() *ListIndexesOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Total": false, - } - return &options -} -type ListIndexesOption func(*ListIndexesOptions) -func (srv *DocumentsDB) WithListIndexesQueries(v []string) ListIndexesOption { - return func(o *ListIndexesOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *DocumentsDB) WithListIndexesTotal(v bool) ListIndexesOption { - return func(o *ListIndexesOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// ListIndexes list indexes in the collection. -func (srv *DocumentsDB) ListIndexes(DatabaseId string, CollectionId string, optionalSetters ...ListIndexesOption)(*models.IndexList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes") - options := ListIndexesOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.IndexList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.IndexList - parsed, ok := resp.Result.(models.IndexList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateIndexOptions struct { - Orders []string - Lengths []int - enabledSetters map[string]bool -} -func (options CreateIndexOptions) New() *CreateIndexOptions { - options.enabledSetters = map[string]bool{ - "Orders": false, - "Lengths": false, - } - return &options -} -type CreateIndexOption func(*CreateIndexOptions) -func (srv *DocumentsDB) WithCreateIndexOrders(v []string) CreateIndexOption { - return func(o *CreateIndexOptions) { - o.Orders = v - o.enabledSetters["Orders"] = true - } -} -func (srv *DocumentsDB) WithCreateIndexLengths(v []int) CreateIndexOption { - return func(o *CreateIndexOptions) { - o.Lengths = v - o.enabledSetters["Lengths"] = true - } -} - -// CreateIndex creates an index on the attributes listed. Your index should -// include all the attributes you will query in a single request. -// Attributes can be `key`, `fulltext`, and `unique`. -func (srv *DocumentsDB) CreateIndex(DatabaseId string, CollectionId string, Key string, Type string, Attributes []string, optionalSetters ...CreateIndexOption)(*models.Index, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes") - options := CreateIndexOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - params["type"] = Type - params["attributes"] = Attributes - if options.enabledSetters["Orders"] { - params["orders"] = options.Orders - } - if options.enabledSetters["Lengths"] { - params["lengths"] = options.Lengths - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Index{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Index - parsed, ok := resp.Result.(models.Index) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetIndex get index by ID. -func (srv *DocumentsDB) GetIndex(DatabaseId string, CollectionId string, Key string)(*models.Index, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes/{key}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - 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.Index{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Index - parsed, ok := resp.Result.(models.Index) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteIndex delete an index. -func (srv *DocumentsDB) DeleteIndex(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) - path := r.Replace("/documentsdb/{databaseId}/collections/{collectionId}/indexes/{key}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} diff --git a/vectorsdb/vectors_db.go b/vectorsdb/vectors_db.go deleted file mode 100644 index df2b3661..00000000 --- a/vectorsdb/vectors_db.go +++ /dev/null @@ -1,1900 +0,0 @@ -package vectorsdb - -import ( - "encoding/json" - "errors" - "github.com/appwrite/sdk-for-go/client" - "github.com/appwrite/sdk-for-go/models" - "strings" -) - -// VectorsDB service -type VectorsDB struct { - client client.Client -} - -func New(clt client.Client) *VectorsDB { - return &VectorsDB{ - client: clt, - } -} - -type ListOptions struct { - Queries []string - Search string - Total bool - enabledSetters map[string]bool -} -func (options ListOptions) New() *ListOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Search": false, - "Total": false, - } - return &options -} -type ListOption func(*ListOptions) -func (srv *VectorsDB) WithListQueries(v []string) ListOption { - return func(o *ListOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithListSearch(v string) ListOption { - return func(o *ListOptions) { - o.Search = v - o.enabledSetters["Search"] = true - } -} -func (srv *VectorsDB) WithListTotal(v bool) ListOption { - return func(o *ListOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// List -func (srv *VectorsDB) List(optionalSetters ...ListOption)(*models.DatabaseList, error) { - path := "/vectorsdb" - options := ListOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Search"] { - params["search"] = options.Search - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.DatabaseList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DatabaseList - parsed, ok := resp.Result.(models.DatabaseList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateOptions struct { - Enabled bool - enabledSetters map[string]bool -} -func (options CreateOptions) New() *CreateOptions { - options.enabledSetters = map[string]bool{ - "Enabled": false, - } - return &options -} -type CreateOption func(*CreateOptions) -func (srv *VectorsDB) WithCreateEnabled(v bool) CreateOption { - return func(o *CreateOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// Create -func (srv *VectorsDB) Create(DatabaseId string, Name string, optionalSetters ...CreateOption)(*models.Database, error) { - path := "/vectorsdb" - options := CreateOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["name"] = Name - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateTextEmbeddingsOptions struct { - Model string - enabledSetters map[string]bool -} -func (options CreateTextEmbeddingsOptions) New() *CreateTextEmbeddingsOptions { - options.enabledSetters = map[string]bool{ - "Model": false, - } - return &options -} -type CreateTextEmbeddingsOption func(*CreateTextEmbeddingsOptions) -func (srv *VectorsDB) WithCreateTextEmbeddingsModel(v string) CreateTextEmbeddingsOption { - return func(o *CreateTextEmbeddingsOptions) { - o.Model = v - o.enabledSetters["Model"] = true - } -} - -// CreateTextEmbeddings -func (srv *VectorsDB) CreateTextEmbeddings(Texts []string, optionalSetters ...CreateTextEmbeddingsOption)(*models.EmbeddingList, error) { - path := "/vectorsdb/embeddings/text" - options := CreateTextEmbeddingsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["texts"] = Texts - if options.enabledSetters["Model"] { - params["model"] = options.Model - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.EmbeddingList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.EmbeddingList - parsed, ok := resp.Result.(models.EmbeddingList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListTransactionsOptions struct { - Queries []string - enabledSetters map[string]bool -} -func (options ListTransactionsOptions) New() *ListTransactionsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - } - return &options -} -type ListTransactionsOption func(*ListTransactionsOptions) -func (srv *VectorsDB) WithListTransactionsQueries(v []string) ListTransactionsOption { - return func(o *ListTransactionsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} - -// ListTransactions -func (srv *VectorsDB) ListTransactions(optionalSetters ...ListTransactionsOption)(*models.TransactionList, error) { - path := "/vectorsdb/transactions" - options := ListTransactionsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - 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.TransactionList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.TransactionList - parsed, ok := resp.Result.(models.TransactionList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateTransactionOptions struct { - Ttl int - enabledSetters map[string]bool -} -func (options CreateTransactionOptions) New() *CreateTransactionOptions { - options.enabledSetters = map[string]bool{ - "Ttl": false, - } - return &options -} -type CreateTransactionOption func(*CreateTransactionOptions) -func (srv *VectorsDB) WithCreateTransactionTtl(v int) CreateTransactionOption { - return func(o *CreateTransactionOptions) { - o.Ttl = v - o.enabledSetters["Ttl"] = true - } -} - -// CreateTransaction -func (srv *VectorsDB) CreateTransaction(optionalSetters ...CreateTransactionOption)(*models.Transaction, error) { - path := "/vectorsdb/transactions" - options := CreateTransactionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Ttl"] { - params["ttl"] = options.Ttl - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetTransaction -func (srv *VectorsDB) GetTransaction(TransactionId string)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/vectorsdb/transactions/{transactionId}") - params := map[string]interface{}{} - params["transactionId"] = TransactionId - 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.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateTransactionOptions struct { - Commit bool - Rollback bool - enabledSetters map[string]bool -} -func (options UpdateTransactionOptions) New() *UpdateTransactionOptions { - options.enabledSetters = map[string]bool{ - "Commit": false, - "Rollback": false, - } - return &options -} -type UpdateTransactionOption func(*UpdateTransactionOptions) -func (srv *VectorsDB) WithUpdateTransactionCommit(v bool) UpdateTransactionOption { - return func(o *UpdateTransactionOptions) { - o.Commit = v - o.enabledSetters["Commit"] = true - } -} -func (srv *VectorsDB) WithUpdateTransactionRollback(v bool) UpdateTransactionOption { - return func(o *UpdateTransactionOptions) { - o.Rollback = v - o.enabledSetters["Rollback"] = true - } -} - -// UpdateTransaction -func (srv *VectorsDB) UpdateTransaction(TransactionId string, optionalSetters ...UpdateTransactionOption)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/vectorsdb/transactions/{transactionId}") - options := UpdateTransactionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["transactionId"] = TransactionId - if options.enabledSetters["Commit"] { - params["commit"] = options.Commit - } - if options.enabledSetters["Rollback"] { - params["rollback"] = options.Rollback - } - 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.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteTransaction -func (srv *VectorsDB) DeleteTransaction(TransactionId string)(*interface{}, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/vectorsdb/transactions/{transactionId}") - params := map[string]interface{}{} - params["transactionId"] = TransactionId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateOperationsOptions struct { - Operations []interface{} - enabledSetters map[string]bool -} -func (options CreateOperationsOptions) New() *CreateOperationsOptions { - options.enabledSetters = map[string]bool{ - "Operations": false, - } - return &options -} -type CreateOperationsOption func(*CreateOperationsOptions) -func (srv *VectorsDB) WithCreateOperationsOperations(v []interface{}) CreateOperationsOption { - return func(o *CreateOperationsOptions) { - o.Operations = v - o.enabledSetters["Operations"] = true - } -} - -// CreateOperations -func (srv *VectorsDB) CreateOperations(TransactionId string, optionalSetters ...CreateOperationsOption)(*models.Transaction, error) { - r := strings.NewReplacer("{transactionId}", TransactionId) - path := r.Replace("/vectorsdb/transactions/{transactionId}/operations") - options := CreateOperationsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["transactionId"] = TransactionId - if options.enabledSetters["Operations"] { - params["operations"] = options.Operations - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Transaction{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Transaction - parsed, ok := resp.Result.(models.Transaction) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Get -func (srv *VectorsDB) Get(DatabaseId string)(*models.Database, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/vectorsdb/{databaseId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - 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.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateOptions struct { - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOptions) New() *UpdateOptions { - options.enabledSetters = map[string]bool{ - "Enabled": false, - } - return &options -} -type UpdateOption func(*UpdateOptions) -func (srv *VectorsDB) WithUpdateEnabled(v bool) UpdateOption { - return func(o *UpdateOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// Update -func (srv *VectorsDB) Update(DatabaseId string, Name string, optionalSetters ...UpdateOption)(*models.Database, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/vectorsdb/{databaseId}") - options := UpdateOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["name"] = Name - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Database{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Database - parsed, ok := resp.Result.(models.Database) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Delete -func (srv *VectorsDB) Delete(DatabaseId string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/vectorsdb/{databaseId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListCollectionsOptions struct { - Queries []string - Search string - Total bool - enabledSetters map[string]bool -} -func (options ListCollectionsOptions) New() *ListCollectionsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Search": false, - "Total": false, - } - return &options -} -type ListCollectionsOption func(*ListCollectionsOptions) -func (srv *VectorsDB) WithListCollectionsQueries(v []string) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithListCollectionsSearch(v string) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Search = v - o.enabledSetters["Search"] = true - } -} -func (srv *VectorsDB) WithListCollectionsTotal(v bool) ListCollectionsOption { - return func(o *ListCollectionsOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// ListCollections -func (srv *VectorsDB) ListCollections(DatabaseId string, optionalSetters ...ListCollectionsOption)(*models.VectorsdbCollectionList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/vectorsdb/{databaseId}/collections") - options := ListCollectionsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Search"] { - params["search"] = options.Search - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.VectorsdbCollectionList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.VectorsdbCollectionList - parsed, ok := resp.Result.(models.VectorsdbCollectionList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateCollectionOptions struct { - Permissions []string - DocumentSecurity bool - Enabled bool - enabledSetters map[string]bool -} -func (options CreateCollectionOptions) New() *CreateCollectionOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - "DocumentSecurity": false, - "Enabled": false, - } - return &options -} -type CreateCollectionOption func(*CreateCollectionOptions) -func (srv *VectorsDB) WithCreateCollectionPermissions(v []string) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *VectorsDB) WithCreateCollectionDocumentSecurity(v bool) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.DocumentSecurity = v - o.enabledSetters["DocumentSecurity"] = true - } -} -func (srv *VectorsDB) WithCreateCollectionEnabled(v bool) CreateCollectionOption { - return func(o *CreateCollectionOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// CreateCollection -func (srv *VectorsDB) CreateCollection(DatabaseId string, CollectionId string, Name string, Dimension int, optionalSetters ...CreateCollectionOption)(*models.VectorsdbCollection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId) - path := r.Replace("/vectorsdb/{databaseId}/collections") - options := CreateCollectionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["name"] = Name - params["dimension"] = Dimension - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["DocumentSecurity"] { - params["documentSecurity"] = options.DocumentSecurity - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.VectorsdbCollection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.VectorsdbCollection - parsed, ok := resp.Result.(models.VectorsdbCollection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetCollection -func (srv *VectorsDB) GetCollection(DatabaseId string, CollectionId string)(*models.VectorsdbCollection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - 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.VectorsdbCollection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.VectorsdbCollection - parsed, ok := resp.Result.(models.VectorsdbCollection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateCollectionOptions struct { - Dimension int - Permissions []string - DocumentSecurity bool - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateCollectionOptions) New() *UpdateCollectionOptions { - options.enabledSetters = map[string]bool{ - "Dimension": false, - "Permissions": false, - "DocumentSecurity": false, - "Enabled": false, - } - return &options -} -type UpdateCollectionOption func(*UpdateCollectionOptions) -func (srv *VectorsDB) WithUpdateCollectionDimension(v int) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.Dimension = v - o.enabledSetters["Dimension"] = true - } -} -func (srv *VectorsDB) WithUpdateCollectionPermissions(v []string) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *VectorsDB) WithUpdateCollectionDocumentSecurity(v bool) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.DocumentSecurity = v - o.enabledSetters["DocumentSecurity"] = true - } -} -func (srv *VectorsDB) WithUpdateCollectionEnabled(v bool) UpdateCollectionOption { - return func(o *UpdateCollectionOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateCollection -func (srv *VectorsDB) UpdateCollection(DatabaseId string, CollectionId string, Name string, optionalSetters ...UpdateCollectionOption)(*models.VectorsdbCollection, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") - options := UpdateCollectionOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["name"] = Name - if options.enabledSetters["Dimension"] { - params["dimension"] = options.Dimension - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["DocumentSecurity"] { - params["documentSecurity"] = options.DocumentSecurity - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.VectorsdbCollection{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.VectorsdbCollection - parsed, ok := resp.Result.(models.VectorsdbCollection) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteCollection -func (srv *VectorsDB) DeleteCollection(DatabaseId string, CollectionId string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - 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 -} -type ListDocumentsOption func(*ListDocumentsOptions) -func (srv *VectorsDB) WithListDocumentsQueries(v []string) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithListDocumentsTransactionId(v string) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} -func (srv *VectorsDB) WithListDocumentsTotal(v bool) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} -func (srv *VectorsDB) WithListDocumentsTtl(v int) ListDocumentsOption { - return func(o *ListDocumentsOptions) { - o.Ttl = v - o.enabledSetters["Ttl"] = true - } -} - -// ListDocuments -func (srv *VectorsDB) ListDocuments(DatabaseId string, CollectionId string, optionalSetters ...ListDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - options := ListDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - if options.enabledSetters["Ttl"] { - params["ttl"] = options.Ttl - } - 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.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateDocumentOptions struct { - Permissions []string - enabledSetters map[string]bool -} -func (options CreateDocumentOptions) New() *CreateDocumentOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - } - return &options -} -type CreateDocumentOption func(*CreateDocumentOptions) -func (srv *VectorsDB) WithCreateDocumentPermissions(v []string) CreateDocumentOption { - return func(o *CreateDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} - -// CreateDocument -func (srv *VectorsDB) CreateDocument(DatabaseId string, CollectionId string, DocumentId string, Data interface{}, optionalSetters ...CreateDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - options := CreateDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - params["data"] = Data - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// CreateDocuments -func (srv *VectorsDB) CreateDocuments(DatabaseId string, CollectionId string, Documents []interface{})(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documents"] = Documents - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpsertDocumentsOptions struct { - TransactionId string - enabledSetters map[string]bool -} -func (options UpsertDocumentsOptions) New() *UpsertDocumentsOptions { - options.enabledSetters = map[string]bool{ - "TransactionId": false, - } - return &options -} -type UpsertDocumentsOption func(*UpsertDocumentsOptions) -func (srv *VectorsDB) WithUpsertDocumentsTransactionId(v string) UpsertDocumentsOption { - return func(o *UpsertDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpsertDocuments -func (srv *VectorsDB) UpsertDocuments(DatabaseId string, CollectionId string, Documents []interface{}, optionalSetters ...UpsertDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - options := UpsertDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documents"] = Documents - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateDocumentsOptions struct { - Data interface{} - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpdateDocumentsOptions) New() *UpdateDocumentsOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Queries": false, - "TransactionId": false, - } - return &options -} -type UpdateDocumentsOption func(*UpdateDocumentsOptions) -func (srv *VectorsDB) WithUpdateDocumentsData(v interface{}) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *VectorsDB) WithUpdateDocumentsQueries(v []string) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithUpdateDocumentsTransactionId(v string) UpdateDocumentsOption { - return func(o *UpdateDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpdateDocuments -func (srv *VectorsDB) UpdateDocuments(DatabaseId string, CollectionId string, optionalSetters ...UpdateDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - options := UpdateDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type DeleteDocumentsOptions struct { - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options DeleteDocumentsOptions) New() *DeleteDocumentsOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "TransactionId": false, - } - return &options -} -type DeleteDocumentsOption func(*DeleteDocumentsOptions) -func (srv *VectorsDB) WithDeleteDocumentsQueries(v []string) DeleteDocumentsOption { - return func(o *DeleteDocumentsOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithDeleteDocumentsTransactionId(v string) DeleteDocumentsOption { - return func(o *DeleteDocumentsOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// DeleteDocuments -func (srv *VectorsDB) DeleteDocuments(DatabaseId string, CollectionId string, optionalSetters ...DeleteDocumentsOption)(*models.DocumentList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents") - options := DeleteDocumentsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.DocumentList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.DocumentList - parsed, ok := resp.Result.(models.DocumentList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type GetDocumentOptions struct { - Queries []string - TransactionId string - enabledSetters map[string]bool -} -func (options GetDocumentOptions) New() *GetDocumentOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "TransactionId": false, - } - return &options -} -type GetDocumentOption func(*GetDocumentOptions) -func (srv *VectorsDB) WithGetDocumentQueries(v []string) GetDocumentOption { - return func(o *GetDocumentOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithGetDocumentTransactionId(v string) GetDocumentOption { - return func(o *GetDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// GetDocument -func (srv *VectorsDB) GetDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...GetDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := GetDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpsertDocumentOptions struct { - Data interface{} - Permissions []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpsertDocumentOptions) New() *UpsertDocumentOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Permissions": false, - "TransactionId": false, - } - return &options -} -type UpsertDocumentOption func(*UpsertDocumentOptions) -func (srv *VectorsDB) WithUpsertDocumentData(v interface{}) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *VectorsDB) WithUpsertDocumentPermissions(v []string) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *VectorsDB) WithUpsertDocumentTransactionId(v string) UpsertDocumentOption { - return func(o *UpsertDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpsertDocument -func (srv *VectorsDB) UpsertDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpsertDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := UpsertDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateDocumentOptions struct { - Data interface{} - Permissions []string - TransactionId string - enabledSetters map[string]bool -} -func (options UpdateDocumentOptions) New() *UpdateDocumentOptions { - options.enabledSetters = map[string]bool{ - "Data": false, - "Permissions": false, - "TransactionId": false, - } - return &options -} -type UpdateDocumentOption func(*UpdateDocumentOptions) -func (srv *VectorsDB) WithUpdateDocumentData(v interface{}) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.Data = v - o.enabledSetters["Data"] = true - } -} -func (srv *VectorsDB) WithUpdateDocumentPermissions(v []string) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *VectorsDB) WithUpdateDocumentTransactionId(v string) UpdateDocumentOption { - return func(o *UpdateDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// UpdateDocument -func (srv *VectorsDB) UpdateDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...UpdateDocumentOption)(*models.Document, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := UpdateDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["Data"] { - params["data"] = options.Data - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - 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.Document{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Document - parsed, ok := resp.Result.(models.Document) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type DeleteDocumentOptions struct { - TransactionId string - enabledSetters map[string]bool -} -func (options DeleteDocumentOptions) New() *DeleteDocumentOptions { - options.enabledSetters = map[string]bool{ - "TransactionId": false, - } - return &options -} -type DeleteDocumentOption func(*DeleteDocumentOptions) -func (srv *VectorsDB) WithDeleteDocumentTransactionId(v string) DeleteDocumentOption { - return func(o *DeleteDocumentOptions) { - o.TransactionId = v - o.enabledSetters["TransactionId"] = true - } -} - -// DeleteDocument -func (srv *VectorsDB) DeleteDocument(DatabaseId string, CollectionId string, DocumentId string, optionalSetters ...DeleteDocumentOption)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{documentId}", DocumentId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/documents/{documentId}") - options := DeleteDocumentOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["documentId"] = DocumentId - if options.enabledSetters["TransactionId"] { - params["transactionId"] = options.TransactionId - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type ListIndexesOptions struct { - Queries []string - Total bool - enabledSetters map[string]bool -} -func (options ListIndexesOptions) New() *ListIndexesOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Total": false, - } - return &options -} -type ListIndexesOption func(*ListIndexesOptions) -func (srv *VectorsDB) WithListIndexesQueries(v []string) ListIndexesOption { - return func(o *ListIndexesOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *VectorsDB) WithListIndexesTotal(v bool) ListIndexesOption { - return func(o *ListIndexesOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} - -// ListIndexes -func (srv *VectorsDB) ListIndexes(DatabaseId string, CollectionId string, optionalSetters ...ListIndexesOption)(*models.IndexList, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes") - options := ListIndexesOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - 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.IndexList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.IndexList - parsed, ok := resp.Result.(models.IndexList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type CreateIndexOptions struct { - Orders []string - Lengths []int - enabledSetters map[string]bool -} -func (options CreateIndexOptions) New() *CreateIndexOptions { - options.enabledSetters = map[string]bool{ - "Orders": false, - "Lengths": false, - } - return &options -} -type CreateIndexOption func(*CreateIndexOptions) -func (srv *VectorsDB) WithCreateIndexOrders(v []string) CreateIndexOption { - return func(o *CreateIndexOptions) { - o.Orders = v - o.enabledSetters["Orders"] = true - } -} -func (srv *VectorsDB) WithCreateIndexLengths(v []int) CreateIndexOption { - return func(o *CreateIndexOptions) { - o.Lengths = v - o.enabledSetters["Lengths"] = true - } -} - -// CreateIndex -func (srv *VectorsDB) CreateIndex(DatabaseId string, CollectionId string, Key string, Type string, Attributes []string, optionalSetters ...CreateIndexOption)(*models.Index, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes") - options := CreateIndexOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - params["type"] = Type - params["attributes"] = Attributes - if options.enabledSetters["Orders"] { - params["orders"] = options.Orders - } - if options.enabledSetters["Lengths"] { - params["lengths"] = options.Lengths - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Index{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Index - parsed, ok := resp.Result.(models.Index) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// GetIndex -func (srv *VectorsDB) GetIndex(DatabaseId string, CollectionId string, Key string)(*models.Index, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes/{key}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - 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.Index{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Index - parsed, ok := resp.Result.(models.Index) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// DeleteIndex -func (srv *VectorsDB) DeleteIndex(DatabaseId string, CollectionId string, Key string)(*interface{}, error) { - r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) - path := r.Replace("/vectorsdb/{databaseId}/collections/{collectionId}/indexes/{key}") - params := map[string]interface{}{} - params["databaseId"] = DatabaseId - params["collectionId"] = CollectionId - params["key"] = Key - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} From 5e2b9160efd19640297840f982be7adf7488bc96 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 06:43:57 +0000 Subject: [PATCH 4/6] chore: update Go SDK to v0.18.0 --- health/health.go | 280 ---------------------------- models/attribute_object.go | 49 ----- models/attribute_vector.go | 51 ----- models/embedding.go | 39 ---- models/embedding_list.go | 35 ---- models/vectorsdb_collection.go | 61 ------ models/vectorsdb_collection_list.go | 35 ---- 7 files changed, 550 deletions(-) delete mode 100644 models/attribute_object.go delete mode 100644 models/attribute_vector.go delete mode 100644 models/embedding.go delete mode 100644 models/embedding_list.go delete mode 100644 models/vectorsdb_collection.go delete mode 100644 models/vectorsdb_collection_list.go diff --git a/health/health.go b/health/health.go index 873f3975..6cbe5af2 100644 --- a/health/health.go +++ b/health/health.go @@ -364,118 +364,6 @@ func (srv *Health) GetQueueAudits(optionalSetters ...GetQueueAuditsOption)(*mode } return &parsed, nil -} -type GetQueueBillingProjectAggregationOptions struct { - Threshold int - enabledSetters map[string]bool -} -func (options GetQueueBillingProjectAggregationOptions) New() *GetQueueBillingProjectAggregationOptions { - options.enabledSetters = map[string]bool{ - "Threshold": false, - } - return &options -} -type GetQueueBillingProjectAggregationOption func(*GetQueueBillingProjectAggregationOptions) -func (srv *Health) WithGetQueueBillingProjectAggregationThreshold(v int) GetQueueBillingProjectAggregationOption { - return func(o *GetQueueBillingProjectAggregationOptions) { - o.Threshold = v - o.enabledSetters["Threshold"] = true - } -} - -// GetQueueBillingProjectAggregation get billing project aggregation queue. -func (srv *Health) GetQueueBillingProjectAggregation(optionalSetters ...GetQueueBillingProjectAggregationOption)(*models.HealthQueue, error) { - path := "/health/queue/billing-project-aggregation" - options := GetQueueBillingProjectAggregationOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Threshold"] { - params["threshold"] = options.Threshold - } - 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.HealthQueue{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.HealthQueue - parsed, ok := resp.Result.(models.HealthQueue) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type GetQueueBillingTeamAggregationOptions struct { - Threshold int - enabledSetters map[string]bool -} -func (options GetQueueBillingTeamAggregationOptions) New() *GetQueueBillingTeamAggregationOptions { - options.enabledSetters = map[string]bool{ - "Threshold": false, - } - return &options -} -type GetQueueBillingTeamAggregationOption func(*GetQueueBillingTeamAggregationOptions) -func (srv *Health) WithGetQueueBillingTeamAggregationThreshold(v int) GetQueueBillingTeamAggregationOption { - return func(o *GetQueueBillingTeamAggregationOptions) { - o.Threshold = v - o.enabledSetters["Threshold"] = true - } -} - -// GetQueueBillingTeamAggregation get billing team aggregation queue. -func (srv *Health) GetQueueBillingTeamAggregation(optionalSetters ...GetQueueBillingTeamAggregationOption)(*models.HealthQueue, error) { - path := "/health/queue/billing-team-aggregation" - options := GetQueueBillingTeamAggregationOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Threshold"] { - params["threshold"] = options.Threshold - } - 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.HealthQueue{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.HealthQueue - parsed, ok := resp.Result.(models.HealthQueue) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - } type GetQueueBuildsOptions struct { Threshold int @@ -533,62 +421,6 @@ func (srv *Health) GetQueueBuilds(optionalSetters ...GetQueueBuildsOption)(*mode } return &parsed, nil -} -type GetQueuePriorityBuildsOptions struct { - Threshold int - enabledSetters map[string]bool -} -func (options GetQueuePriorityBuildsOptions) New() *GetQueuePriorityBuildsOptions { - options.enabledSetters = map[string]bool{ - "Threshold": false, - } - return &options -} -type GetQueuePriorityBuildsOption func(*GetQueuePriorityBuildsOptions) -func (srv *Health) WithGetQueuePriorityBuildsThreshold(v int) GetQueuePriorityBuildsOption { - return func(o *GetQueuePriorityBuildsOptions) { - o.Threshold = v - o.enabledSetters["Threshold"] = true - } -} - -// GetQueuePriorityBuilds get the priority builds queue size. -func (srv *Health) GetQueuePriorityBuilds(optionalSetters ...GetQueuePriorityBuildsOption)(*models.HealthQueue, error) { - path := "/health/queue/builds-priority" - options := GetQueuePriorityBuildsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Threshold"] { - params["threshold"] = options.Threshold - } - 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.HealthQueue{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.HealthQueue - parsed, ok := resp.Result.(models.HealthQueue) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - } type GetQueueCertificatesOptions struct { Threshold int @@ -1115,62 +947,6 @@ func (srv *Health) GetQueueMigrations(optionalSetters ...GetQueueMigrationsOptio } return &parsed, nil -} -type GetQueueRegionManagerOptions struct { - Threshold int - enabledSetters map[string]bool -} -func (options GetQueueRegionManagerOptions) New() *GetQueueRegionManagerOptions { - options.enabledSetters = map[string]bool{ - "Threshold": false, - } - return &options -} -type GetQueueRegionManagerOption func(*GetQueueRegionManagerOptions) -func (srv *Health) WithGetQueueRegionManagerThreshold(v int) GetQueueRegionManagerOption { - return func(o *GetQueueRegionManagerOptions) { - o.Threshold = v - o.enabledSetters["Threshold"] = true - } -} - -// GetQueueRegionManager get region manager queue. -func (srv *Health) GetQueueRegionManager(optionalSetters ...GetQueueRegionManagerOption)(*models.HealthQueue, error) { - path := "/health/queue/region-manager" - options := GetQueueRegionManagerOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Threshold"] { - params["threshold"] = options.Threshold - } - 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.HealthQueue{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.HealthQueue - parsed, ok := resp.Result.(models.HealthQueue) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - } type GetQueueStatsResourcesOptions struct { Threshold int @@ -1285,62 +1061,6 @@ func (srv *Health) GetQueueUsage(optionalSetters ...GetQueueUsageOption)(*models } return &parsed, nil -} -type GetQueueThreatsOptions struct { - Threshold int - enabledSetters map[string]bool -} -func (options GetQueueThreatsOptions) New() *GetQueueThreatsOptions { - options.enabledSetters = map[string]bool{ - "Threshold": false, - } - return &options -} -type GetQueueThreatsOption func(*GetQueueThreatsOptions) -func (srv *Health) WithGetQueueThreatsThreshold(v int) GetQueueThreatsOption { - return func(o *GetQueueThreatsOptions) { - o.Threshold = v - o.enabledSetters["Threshold"] = true - } -} - -// GetQueueThreats get threats queue. -func (srv *Health) GetQueueThreats(optionalSetters ...GetQueueThreatsOption)(*models.HealthQueue, error) { - path := "/health/queue/threats" - options := GetQueueThreatsOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Threshold"] { - params["threshold"] = options.Threshold - } - 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.HealthQueue{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.HealthQueue - parsed, ok := resp.Result.(models.HealthQueue) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - } type GetQueueWebhooksOptions struct { Threshold int diff --git a/models/attribute_object.go b/models/attribute_object.go deleted file mode 100644 index b2608ecc..00000000 --- a/models/attribute_object.go +++ /dev/null @@ -1,49 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// AttributeObject Model -type AttributeObject struct { - // Attribute Key. - Key string `json:"key"` - // Attribute type. - Type string `json:"type"` - // Attribute status. Possible values: `available`, `processing`, `deleting`, - // `stuck`, or `failed` - Status string `json:"status"` - // Error message. Displays error generated on failure of creating or deleting - // an attribute. - Error string `json:"error"` - // Is attribute required? - Required bool `json:"required"` - // Is attribute an array? - Array bool `json:"array"` - // Attribute creation date in ISO 8601 format. - CreatedAt string `json:"$createdAt"` - // Attribute update date in ISO 8601 format. - UpdatedAt string `json:"$updatedAt"` - - // Used by Decode() method - data []byte -} - -func (model AttributeObject) New(data []byte) *AttributeObject { - model.data = data - return &model -} - -func (model *AttributeObject) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/attribute_vector.go b/models/attribute_vector.go deleted file mode 100644 index 6e96a011..00000000 --- a/models/attribute_vector.go +++ /dev/null @@ -1,51 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// AttributeVector Model -type AttributeVector struct { - // Attribute Key. - Key string `json:"key"` - // Attribute type. - Type string `json:"type"` - // Attribute status. Possible values: `available`, `processing`, `deleting`, - // `stuck`, or `failed` - Status string `json:"status"` - // Error message. Displays error generated on failure of creating or deleting - // an attribute. - Error string `json:"error"` - // Is attribute required? - Required bool `json:"required"` - // Is attribute an array? - Array bool `json:"array"` - // Attribute creation date in ISO 8601 format. - CreatedAt string `json:"$createdAt"` - // Attribute update date in ISO 8601 format. - UpdatedAt string `json:"$updatedAt"` - // Vector dimensions. - Size int `json:"size"` - - // Used by Decode() method - data []byte -} - -func (model AttributeVector) New(data []byte) *AttributeVector { - model.data = data - return &model -} - -func (model *AttributeVector) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/embedding.go b/models/embedding.go deleted file mode 100644 index 157111af..00000000 --- a/models/embedding.go +++ /dev/null @@ -1,39 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// Embedding Model -type Embedding struct { - // Embedding model used to generate embeddings. - Model string `json:"model"` - // Number of dimensions for each embedding vector. - Dimension int `json:"dimension"` - // Embedding vector values. If an error occurs, this will be an empty array. - Embedding []float64 `json:"embedding"` - // Error message if embedding generation fails. Empty string if no error. - Error string `json:"error"` - - // Used by Decode() method - data []byte -} - -func (model Embedding) New(data []byte) *Embedding { - model.data = data - return &model -} - -func (model *Embedding) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/embedding_list.go b/models/embedding_list.go deleted file mode 100644 index ec72e308..00000000 --- a/models/embedding_list.go +++ /dev/null @@ -1,35 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// EmbeddingList Model -type EmbeddingList struct { - // Total number of embeddings that matched your query. - Total int `json:"total"` - // List of embeddings. - Embeddings []Embedding `json:"embeddings"` - - // Used by Decode() method - data []byte -} - -func (model EmbeddingList) New(data []byte) *EmbeddingList { - model.data = data - return &model -} - -func (model *EmbeddingList) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/vectorsdb_collection.go b/models/vectorsdb_collection.go deleted file mode 100644 index 8657ed71..00000000 --- a/models/vectorsdb_collection.go +++ /dev/null @@ -1,61 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// VectorsDBCollection Model -type VectorsdbCollection struct { - // Collection ID. - Id string `json:"$id"` - // Collection creation date in ISO 8601 format. - CreatedAt string `json:"$createdAt"` - // Collection update date in ISO 8601 format. - UpdatedAt string `json:"$updatedAt"` - // Collection permissions. [Learn more about - // permissions](https://appwrite.io/docs/permissions). - Permissions []string `json:"$permissions"` - // Database ID. - DatabaseId string `json:"databaseId"` - // Collection name. - Name string `json:"name"` - // Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the - // collection is inaccessible to users, but remains accessible to Server SDKs - // using API keys. - Enabled bool `json:"enabled"` - // Whether document-level permissions are enabled. [Learn more about - // permissions](https://appwrite.io/docs/permissions). - DocumentSecurity bool `json:"documentSecurity"` - // Collection attributes. - Attributes []map[string]any `json:"attributes"` - // Collection indexes. - Indexes []Index `json:"indexes"` - // Maximum document size in bytes. Returns 0 when no limit applies. - BytesMax int `json:"bytesMax"` - // Currently used document size in bytes based on defined attributes. - BytesUsed int `json:"bytesUsed"` - // Embedding dimension. - Dimension int `json:"dimension"` - - // Used by Decode() method - data []byte -} - -func (model VectorsdbCollection) New(data []byte) *VectorsdbCollection { - model.data = data - return &model -} - -func (model *VectorsdbCollection) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/vectorsdb_collection_list.go b/models/vectorsdb_collection_list.go deleted file mode 100644 index 000ded6f..00000000 --- a/models/vectorsdb_collection_list.go +++ /dev/null @@ -1,35 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// VectorsDBCollectionsList Model -type VectorsdbCollectionList struct { - // Total number of collections that matched your query. - Total int `json:"total"` - // List of collections. - Collections []VectorsdbCollection `json:"collections"` - - // Used by Decode() method - data []byte -} - -func (model VectorsdbCollectionList) New(data []byte) *VectorsdbCollectionList { - model.data = data - return &model -} - -func (model *VectorsdbCollectionList) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file From 33cc8b017e75a9483cc5cd1d583bab4c5a887ba0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 05:07:06 +0000 Subject: [PATCH 5/6] chore: update Go SDK to v0.18.0 --- docs/examples/databases/upsert-documents.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples/databases/upsert-documents.md b/docs/examples/databases/upsert-documents.md index 4424405e..71d5a175 100644 --- a/docs/examples/databases/upsert-documents.md +++ b/docs/examples/databases/upsert-documents.md @@ -10,7 +10,7 @@ import ( client := client.New( client.WithEndpoint("https://.cloud.appwrite.io/v1") client.WithProject("") - client.WithSession("") + client.WithKey("") ) service := databases.New(client) From 5cfc290009e715cc114f024bdeda9ab9de74623c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Mar 2026 05:40:04 +0000 Subject: [PATCH 6/6] chore: update Go SDK to v2.0.0 --- CHANGELOG.md | 12 ++++++++++-- client/client.go | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ded1808b..c6683fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## 0.18.0 +## v2.0.0 * [BREAKING] Changed `$sequence` type from `int` to `string` for rows and documents * Added `NewProject` and `NewWebhooks` client constructors @@ -8,7 +8,15 @@ * Added avatar URL helpers: `GetBrowserURL`, `GetCreditCardURL`, `GetFaviconURL`, `GetFlagURL`, `GetImageURL`, `GetInitialsURL`, `GetQRURL`, `GetScreenshotURL` * Updated README badge to API version 1.9.0 -## 0.17.0 +## 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. + +## v0.17.0 * Added new Activities service to the Go SDK with a NewActivities constructor to access Activities endpoints. * Extended Databases attribute APIs to support encryption: introduced Encrypt option for Longtext, Mediumtext, Text, and Varchar attributes, along with corresponding New/Create option builders (WithCreateLongtextAttributeEncrypt, WithCreateMediumtextAttributeEncrypt, WithCreateTextAttributeEncrypt, WithCreateVarcharAttributeEncrypt) and wiring to send the encrypt parameter when enabled. diff --git a/client/client.go b/client/client.go index 52f8b23d..0cf9bb3e 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.0", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v0.18.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v2.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v0.18.0", + "x-sdk-version": "v2.0.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil {