turso

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

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 13 Imported by: 0

README

turso-go

⚠️ This SDK is still in development and is not ready for production use.

Installation

go get github.com/alehechka/turso-go

Usage

package main

import (
    "context"
    "github.com/alehechka/turso-go"
)

func main() {
    ctx := context.Background()

    client, err := turso.New("my-token", "my-org")
}

The SDK includes a discoverable API for each area available in the Turso Platform API, options include:

client.Instances.List(ctx, "db-name")
client.Databases.List(ctx)
client.Feedback.Submit(ctx, "summary", "feedback")
client.Organizations.List(ctx)
client.ApiTokens.List(ctx)
client.Locations.List(ctx)
client.Tokens.Validate(ctx, "my-token")
client.Users.GetUser(ctx)
client.Plans.List(ctx)
client.Subscriptions.Get(ctx)
client.Billing.Portal(ctx)
client.Groups.List(ctx)
client.Invoices.List(ctx)

Documentation

Index

Constants

View Source
const BaseURL = "https://api.turso.tech"

Variables

View Source
var (
	ErrMissingBaseURL    = errors.New("no baseUrl set")
	ErrMissingAPIToken   = errors.New("no API token set")
	ErrMissingHTTPClient = errors.New("no httpClient set")
)
View Source
var ErrPaymentRequired = errors.New("payment required")

Functions

This section is empty.

Types

type ApiToken

type ApiToken struct {
	ID     string `json:"dbId"`
	Name   string
	Owner  uint
	PubKey []byte
}

type ApiTokensClient

type ApiTokensClient client

func (*ApiTokensClient) Create

func (c *ApiTokensClient) Create(ctx context.Context, name string) (CreateApiToken, error)

func (*ApiTokensClient) List

func (c *ApiTokensClient) List(ctx context.Context) ([]ApiToken, error)

func (*ApiTokensClient) Revoke

func (c *ApiTokensClient) Revoke(ctx context.Context, name string) error

type BillingAddress

type BillingAddress struct {
	Line1      string `json:"line1"`
	Line2      string `json:"line2"`
	City       string `json:"city"`
	State      string `json:"state"`
	PostalCode string `json:"postal_code"`
	Country    string `json:"country"`
}

type BillingClient

type BillingClient client

func (*BillingClient) CreateStripeCustomer

func (c *BillingClient) CreateStripeCustomer(ctx context.Context, name string) (string, error)

func (*BillingClient) GetBillingCustomer

func (c *BillingClient) GetBillingCustomer(ctx context.Context) (BillingCustomer, error)

func (*BillingClient) HasPaymentMethod

func (c *BillingClient) HasPaymentMethod(ctx context.Context) (bool, error)

func (*BillingClient) HasPaymentMethodWithStripeId

func (c *BillingClient) HasPaymentMethodWithStripeId(ctx context.Context, stripeId string) (bool, error)

func (*BillingClient) Portal

func (c *BillingClient) Portal(ctx context.Context) (Portal, error)

func (*BillingClient) PortalForStripeId

func (c *BillingClient) PortalForStripeId(ctx context.Context, stripeId string) (Portal, error)

func (*BillingClient) UpdateBillingCustomer

func (c *BillingClient) UpdateBillingCustomer(ctx context.Context, customer BillingCustomer) error

type BillingCustomer

type BillingCustomer struct {
	Name           string         `json:"name"`
	Email          string         `json:"email"`
	TaxID          TaxID          `json:"tax_id"`
	BillingAddress BillingAddress `json:"billing_address"`
}

type Body

type Body struct {
	Org string `json:"org"`
}

type Client

type Client struct {
	Org string

	Instances     *InstancesClient
	Databases     *DatabasesClient
	Feedback      *FeedbackClient
	Organizations *OrganizationsClient
	ApiTokens     *ApiTokensClient
	Locations     *LocationsClient
	Tokens        *TokensClient
	Users         *UsersClient
	Plans         *PlansClient
	Subscriptions *SubscriptionClient
	Billing       *BillingClient
	Groups        *GroupsClient
	Invoices      *InvoicesClient
	// contains filtered or unexported fields
}

Collection of all turso clients

func New

func New(token string, org string, options ...ClientOption) (*Client, error)

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, body io.Reader) (*http.Response, error)

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, body io.Reader) (*http.Response, error)

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlPath string, body io.Reader) (*http.Request, error)

func (*Client) Patch

func (c *Client) Patch(ctx context.Context, path string, body io.Reader) (*http.Response, error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body io.Reader) (*http.Response, error)

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body io.Reader) (*http.Response, error)

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, path string, fileData *os.File) (*http.Response, error)

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

func WithBaseUrl

func WithBaseUrl(baseUrl string) ClientOption

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

type ClosestLocationResponse

type ClosestLocationResponse struct {
	Server string
}

type CreateApiToken

type CreateApiToken struct {
	Name  string `json:"name"`
	ID    string `json:"id"`
	Value string `json:"value"`
}

type CreateDatabaseBody

type CreateDatabaseBody struct {
	Name       string  `json:"name"`
	Location   string  `json:"location"`
	Image      string  `json:"image,omitempty"`
	Extensions string  `json:"extensions,omitempty"`
	Group      string  `json:"group,omitempty"`
	Seed       *DBSeed `json:"seed,omitempty"`
	Schema     string  `json:"schema,omitempty"`
	IsSchema   bool    `json:"is_schema,omitempty"`
}

type CreateDatabaseResponse

type CreateDatabaseResponse struct {
	Database Database
	Username string
}

type CreateInstanceLocationError

type CreateInstanceLocationError struct {
	// contains filtered or unexported fields
}

func (*CreateInstanceLocationError) Error

type DBSeed

type DBSeed struct {
	Type      string     `json:"type"`
	Name      string     `json:"value,omitempty"`
	URL       string     `json:"url,omitempty"`
	Timestamp *time.Time `json:"timestamp,omitempty"`
}

type Database

type Database struct {
	ID            string `json:"dbId" mapstructure:"dbId"`
	Name          string
	Regions       []string
	PrimaryRegion string
	Hostname      string
	Version       string
	Group         string
	Sleeping      bool
}

type DatabaseConfig

type DatabaseConfig struct {
	AllowAttach bool `json:"allow_attach"`
}

type DatabaseTokenRequest

type DatabaseTokenRequest struct {
	Permissions *PermissionsClaim `json:"permissions,omitempty"`
}

type DatabasesClient

type DatabasesClient client

func (*DatabasesClient) Create

func (c *DatabasesClient) Create(ctx context.Context, name, location, image, extensions, group string, schema string, isSchema bool, seed *DBSeed) (*CreateDatabaseResponse, error)

func (*DatabasesClient) Delete

func (c *DatabasesClient) Delete(ctx context.Context, database string) error

func (*DatabasesClient) GetConfig

func (c *DatabasesClient) GetConfig(ctx context.Context, database string) (DatabaseConfig, error)

func (*DatabasesClient) List

func (c *DatabasesClient) List(ctx context.Context) ([]Database, error)

func (*DatabasesClient) Rotate

func (c *DatabasesClient) Rotate(ctx context.Context, database string) error

func (*DatabasesClient) Seed

func (c *DatabasesClient) Seed(ctx context.Context, name string, dbFile *os.File) error

func (*DatabasesClient) Stats

func (c *DatabasesClient) Stats(ctx context.Context, database string) (Stats, error)

func (*DatabasesClient) Token

func (c *DatabasesClient) Token(ctx context.Context, database string, expiration string, readOnly bool, permissions *PermissionsClaim) (string, error)

func (*DatabasesClient) Transfer

func (c *DatabasesClient) Transfer(ctx context.Context, database, org string) error

func (*DatabasesClient) URL

func (c *DatabasesClient) URL(suffix string) string

func (*DatabasesClient) Update

func (c *DatabasesClient) Update(ctx context.Context, database string, group bool) error

func (*DatabasesClient) UpdateConfig

func (c *DatabasesClient) UpdateConfig(ctx context.Context, database string, config DatabaseConfig) error

func (*DatabasesClient) UploadDump

func (c *DatabasesClient) UploadDump(ctx context.Context, dbFile *os.File) (string, error)

func (*DatabasesClient) Usage

func (c *DatabasesClient) Usage(ctx context.Context, database string) (DbUsage, error)

func (*DatabasesClient) Wakeup

func (c *DatabasesClient) Wakeup(ctx context.Context, database string) error

type DbUsage

type DbUsage struct {
	UUID      string          `json:"uuid,omitempty"`
	Instances []InstanceUsage `json:"instances"`
	Usage     Usage           `json:"usage"`
}

type DbUsageResponse

type DbUsageResponse struct {
	DbUsage DbUsage `json:"database"`
}

type Entities

type Entities struct {
	DBNames []string `json:"databases,omitempty"`
}

type FeedbackClient

type FeedbackClient client

func (*FeedbackClient) Submit

func (f *FeedbackClient) Submit(ctx context.Context, summary, feedback string) error

type Group

type Group struct {
	Name      string   `json:"name"`
	Locations []string `json:"locations"`
	Primary   string   `json:"primary"`
	Archived  bool     `json:"archived"`
	Version   string   `json:"version"`
}

type GroupTokenRequest

type GroupTokenRequest struct {
	Permissions *PermissionsClaim `json:"permissions,omitempty"`
}

type GroupsClient

type GroupsClient client

func (*GroupsClient) AddLocation

func (g *GroupsClient) AddLocation(ctx context.Context, name, location string) error

func (*GroupsClient) Create

func (g *GroupsClient) Create(ctx context.Context, name, location, version string) error

func (*GroupsClient) Delete

func (g *GroupsClient) Delete(ctx context.Context, group string) error

func (*GroupsClient) Get

func (g *GroupsClient) Get(ctx context.Context, name string) (Group, error)

func (*GroupsClient) List

func (g *GroupsClient) List(ctx context.Context) ([]Group, error)

func (*GroupsClient) RemoveLocation

func (g *GroupsClient) RemoveLocation(ctx context.Context, name, location string) error

func (*GroupsClient) Rotate

func (g *GroupsClient) Rotate(ctx context.Context, group string) error

func (*GroupsClient) Token

func (g *GroupsClient) Token(ctx context.Context, group string, expiration string, readOnly bool, permissions *PermissionsClaim) (string, error)

func (*GroupsClient) Transfer

func (g *GroupsClient) Transfer(ctx context.Context, group string, to string) error

func (*GroupsClient) URL

func (g *GroupsClient) URL(suffix string) string

func (*GroupsClient) Unarchive

func (g *GroupsClient) Unarchive(ctx context.Context, name string) error

func (*GroupsClient) Update

func (g *GroupsClient) Update(ctx context.Context, group string, version, extensions string) error

func (*GroupsClient) WaitLocation

func (g *GroupsClient) WaitLocation(ctx context.Context, name, location string) error

type Instance

type Instance struct {
	Uuid     string
	Name     string
	Type     string
	Region   string
	Hostname string
}

type InstanceUsage

type InstanceUsage struct {
	UUID  string `json:"uuid,omitempty"`
	Usage Usage  `json:"usage"`
}

type InstancesClient

type InstancesClient client

func (*InstancesClient) Create

func (c *InstancesClient) Create(ctx context.Context, dbName, location string) (*Instance, error)

func (*InstancesClient) Delete

func (c *InstancesClient) Delete(ctx context.Context, db, instance string) error

func (*InstancesClient) List

func (c *InstancesClient) List(ctx context.Context, db string) ([]Instance, error)

func (*InstancesClient) URL

func (d *InstancesClient) URL(database, suffix string) string

func (*InstancesClient) Wait

func (c *InstancesClient) Wait(ctx context.Context, db, instance string) error

type Invite

type Invite struct {
	Email    string `json:"email,omitempty"`
	Role     string `json:"role,omitempty"`
	Accepted bool   `json:"accepted,omitempty"`
}

type Invoice

type Invoice struct {
	Number          string `json:"invoice_number"`
	Amount          string `json:"amount_due"`
	DueDate         string `json:"due_date"`
	PaidAt          string `json:"paid_at"`
	PaymentFailedAt string `json:"payment_failed_at"`
	InvoicePdf      string `json:"invoice_pdf"`
}

type InvoicesClient

type InvoicesClient client

func (*InvoicesClient) List

func (c *InvoicesClient) List(ctx context.Context) ([]Invoice, error)

func (*InvoicesClient) URL

func (c *InvoicesClient) URL(suffix string) string

type Location

type Location struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

type LocationResponse

type LocationResponse struct {
	Code        string `json:"code"`
	Description string `json:"description"`
	Closest     []Location
}

type LocationsClient

type LocationsClient client

func (*LocationsClient) Closest

func (c *LocationsClient) Closest(ctx context.Context) (string, error)

func (*LocationsClient) Get

func (c *LocationsClient) Get(ctx context.Context, location string) (LocationResponse, error)

func (*LocationsClient) List

func (c *LocationsClient) List(ctx context.Context) (map[string]string, error)

type LocationsResponse

type LocationsResponse struct {
	Locations map[string]string
}

type Member

type Member struct {
	Name string `json:"username,omitempty"`
	Role string `json:"role,omitempty"`
}

type OrgTotal

type OrgTotal struct {
	RowsRead         uint64 `json:"rows_read,omitempty"`
	RowsWritten      uint64 `json:"rows_written,omitempty"`
	StorageBytesUsed uint64 `json:"storage_bytes,omitempty"`
	BytesSynced      uint64 `json:"bytes_synced,omitempty"`
	Databases        uint64 `json:"databases,omitempty"`
	Locations        uint64 `json:"locations,omitempty"`
	Groups           uint64 `json:"groups,omitempty"`
}

type OrgUsage

type OrgUsage struct {
	UUID      string    `json:"uuid,omitempty"`
	Usage     OrgTotal  `json:"usage"`
	Databases []DbUsage `json:"databases"`
}

type OrgUsageResponse

type OrgUsageResponse struct {
	OrgUsage OrgUsage `json:"organization"`
}

type Organization

type Organization struct {
	Name     string `json:"name,omitempty"`
	Slug     string `json:"slug,omitempty"`
	Type     string `json:"type,omitempty"`
	StripeID string `json:"stripe_id,omitempty"`
	Overages bool   `json:"overages,omitempty"`
}

type OrganizationsClient

type OrganizationsClient client

func (*OrganizationsClient) AddMember

func (c *OrganizationsClient) AddMember(ctx context.Context, username, role string) error

func (*OrganizationsClient) Create

func (c *OrganizationsClient) Create(ctx context.Context, name string, stripeId string, dryRun bool) (Organization, error)

func (*OrganizationsClient) Delete

func (c *OrganizationsClient) Delete(ctx context.Context, slug string) error

func (*OrganizationsClient) DeleteInvite

func (c *OrganizationsClient) DeleteInvite(ctx context.Context, email string) error

func (*OrganizationsClient) InviteMember

func (c *OrganizationsClient) InviteMember(ctx context.Context, email, role string) error

func (*OrganizationsClient) List

func (*OrganizationsClient) ListInvites

func (c *OrganizationsClient) ListInvites(ctx context.Context) ([]Invite, error)

func (*OrganizationsClient) ListMembers

func (c *OrganizationsClient) ListMembers(ctx context.Context) ([]Member, error)

func (*OrganizationsClient) MembersURL

func (c *OrganizationsClient) MembersURL(suffix string) (string, error)

func (*OrganizationsClient) RemoveMember

func (c *OrganizationsClient) RemoveMember(ctx context.Context, username string) error

func (*OrganizationsClient) SetOverages

func (c *OrganizationsClient) SetOverages(ctx context.Context, slug string, toggle bool) error

func (*OrganizationsClient) Usage

type PermissionsClaim

type PermissionsClaim struct {
	ReadAttach Entities `json:"read_attach,omitempty"`
}

type Plan

type Plan struct {
	Name   string `json:"name"`
	Price  string `json:"price"`
	Quotas struct {
		RowsRead    uint64 `json:"rowsRead"`
		RowsWritten uint64 `json:"rowsWritten"`
		Databases   uint64 `json:"databases"`
		BytesSynced uint64 `json:"bytesSynced"`
		Locations   uint64 `json:"locations"`
		Storage     uint64 `json:"storage"`
		Groups      uint64 `json:"groups"`
	}
}

type PlansClient

type PlansClient client

func (*PlansClient) List

func (c *PlansClient) List(ctx context.Context) ([]Plan, error)

type Portal

type Portal struct {
	URL string `json:"url"`
}

type Stats

type Stats struct {
	TopQueries []struct {
		Query       string `json:"query"`
		RowsRead    int    `json:"rows_read"`
		RowsWritten int    `json:"rows_written"`
	} `json:"top_queries,omitempty"`
}

type Subscription

type Subscription struct {
	Plan     string `json:"plan"`
	Timeline string `json:"timeline"`
	Overages bool   `json:"overages"`
}

type SubscriptionClient

type SubscriptionClient client

func (*SubscriptionClient) Get

func (*SubscriptionClient) Update

func (c *SubscriptionClient) Update(ctx context.Context, plan, timeline string, overages *bool) error

type TaxID

type TaxID struct {
	Value   string `json:"value"`
	Country string `json:"country"`
}

type TokensClient

type TokensClient client

func (*TokensClient) Invalidate

func (c *TokensClient) Invalidate(ctx context.Context) (int64, error)

func (*TokensClient) Validate

func (c *TokensClient) Validate(ctx context.Context, token string) (int64, error)

type Usage

type Usage struct {
	RowsRead         uint64 `json:"rows_read,omitempty"`
	RowsWritten      uint64 `json:"rows_written,omitempty"`
	StorageBytesUsed uint64 `json:"storage_bytes,omitempty"`
	BytesSynced      uint64 `json:"bytes_synced,omitempty"`
}

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Plan     string `json:"plan"`
}

type UserInfoResponse

type UserInfoResponse struct {
	User UserInfo `json:"user"`
}

type UsersClient

type UsersClient client

func (*UsersClient) GetUser

func (c *UsersClient) GetUser(ctx context.Context) (UserInfo, error)

Jump to

Keyboard shortcuts

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