kontenbase

package module
v0.0.0-...-fff8c72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 1 Imported by: 0

README

Kontenbase

This is the official Go SDK for Kontenbase API.

Kontenbase is a no-code backend API platform or Backend as a Service (BaaS) that allows you to create a backend API as fast as possible. We make it easy for developers to build backend API without having to touch backend code at all.

Visit Kontenbase for more information and see our documentation for more technical details.

API Documentation

For API documentation, visit Kontenbase API Reference.

Installation

go get -u github.com/kontenbase/kontenbase-go

Usage

Before you begin, you need to sign up on Kontenbase Dashboard to retrieve an API key of your project.

Create a client
client := kontenbase.NewClient("YOUR_API_KEY", kontenbase.DefaultURL())

Authentication

Register
resp, err := client.Auth.Register(client.RegisterParams{
  Email: "user@mail.com",
  Password: "password",
  FirstName: "Ega",
})
Login
resp, err := client.Auth.Login(client.LoginParams{
  Email: "user@mail.com",
  Password: "password",
})
Get user info
resp, err := client.Auth.User()
Update user info
resp, err := client.Auth.Update(map[string]interface{}{
  "firstName": "Ega",
})
Logout
resp, err := client.Auth.Logout()

Database

Create a new record
resp, err := client.Service("posts").Create(map[string]interface{}{
  "name" : "Post 1",
  "notes": "Hello Kontenbase",
})
Get a record by Id
resp, err := client.Service("posts").GetByID("605a251d7b8678bf6811k3b1")
Find records

Get all records

resp, err := client.Service("posts").Find()

Find records and modify the result

resp, err := client.Service("posts").Find()
  .SetLimit(10)
  .SetSkip(10)
  .SetSelect([]interface{}{"name", "notes"})
  .SetLookup("*")

Find records with criteria

resp, err := client.Service("posts").Find()
  .SetWhere(map[string]interface{}{
    "name": "Ega",
    "notes": map[string]interface{}{
      "$contains": "hello",
    },
    "number": map[string]interface{}{
      "$gte": 10,
    },
    "status" map[string]interface{}{
      "$in": []interface{}{"todo", "done"},
    },
  })
Update record
resp, err := client.Service("posts").UpdateByID("605a251d7b8678bf6811k3b1", map[string]interface{}{
    "notes": "Hello world",
})
Delete record
resp, err := client.Service("posts").DeleteByID("605a251d7b8678bf6811k3b1")
resp, err := client.Service("posts").Link("605a251d7b8678bf6811k3b1", map[string]interface{}{
    "categories": "61d26e8e2adb12b85c33029c",
})
resp, err := client.Service("posts").Unlink("605a251d7b8678bf6811k3b1", map[string]interface{}{
    "categories": "61d26e8e2adb12b85c33029c",
})
Count total records

Count all records

resp, err := client.Service("posts").Count()

Count records that match given criteria

resp, err := client.Service("posts").Count().SetWhere(map[string]interface{}{
    "name": "Ega",
  })

Storage

Upload a file
file, err := os.Open("your_file.txt")
if err != nil {
  return err
}

defer file.Close()

resp, err := client.Storage.Upload(file)

Realtime

Subscribe
func onMessage (event string, payload map[string]interface{}) error {
  fmt.Println(event)
	return nil
}

func onError (event string, payload map[string]interface{}) error {
  fmt.Println(payload)
	return nil
}

func main() {
  key, err := client.Realtime.Subscribe("Movies", options.SubscribeOptions{
    Event:     options.RealtimeAll,
    OnMessage: onMessage,
    OnError:   onError,
  })
}
Unsubscribe
err := client.Realtime.Unsubsribe(key)
if err != nil {
  return err
}

Feedback

Please use our GitHub Issues for high-level feedback. Also you can join our Discord server.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultURL

func DefaultURL() string

Types

type Client

type Client struct {
	Auth     *client.AuthClient
	Storage  *client.StorageClient
	Realtime *client.RealtimeClient
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, url string) *Client

func (*Client) Service

func (c *Client) Service(name string) *client.QueryClient

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL