client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

* Copyright 2023 https://github.com/superfly * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Modifications by https://github.com/stephen.

Index

Constants

View Source
const DefaultURL = "https://litefs.fly.io"

DefaultURL is the default URL set by NewClient().

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckRestoreDatabaseOutput

type CheckRestoreDatabaseOutput struct {
	Timestamp time.Time `json:"timestamp"`
	TXID      ltx.TXID  `json:"txID"`
}

type Client

type Client struct {
	// Base URL of the remote LiteFS Cloud service.
	URL string

	// Authentication token. Required for most API calls.
	Token string
}

Client represents a client for connecting to LiteFS Cloud.

func NewClient

func NewClient() *Client

NewClient returns a new instance of Client with the default URL.

func (*Client) CheckRestoreDatabase

func (c *Client) CheckRestoreDatabase(ctx context.Context, database string, ro RestoreOption) (*CheckRestoreDatabaseOutput, error)

CheckRestoreDatabase verifies that the requested restore can be completed and returns the txid/timestamp that will be restored. A cluster-scoped authentication token with write permissions is required.

func (*Client) CreateCluster

func (c *Client) CreateCluster(ctx context.Context, name, region string) (*Cluster, error)

CreateCluster creates a new cluster in a given region. An org-scoped authentication token with write permissions is required.

func (*Client) DeleteCluster

func (c *Client) DeleteCluster(ctx context.Context, name string) error

DeleteCluster permanently deletes an existing cluster. An org-scoped authentication token with write permissions is required.

func (*Client) DeleteDB

func (c *Client) DeleteDB(ctx context.Context, database string) error

DeleteDB permanently deletes a db from a cluster. An org-scoped authentication token with write permissions is required.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method string, u url.URL, input, output any) error

func (*Client) ExportDatabase

func (c *Client) ExportDatabase(ctx context.Context, database, format string) (io.ReadCloser, error)

ExportDatabase returns a reader that contains the current database state. A cluster-scoped authentication token with read permissions is required.

func (*Client) HWM

func (c *Client) HWM(ctx context.Context) (map[string]ltx.TXID, error)

HWM returns a map of database names with their current high-water mark. A cluster-scoped authentication token with read permissions is required.

func (*Client) ImportDatabase

func (c *Client) ImportDatabase(ctx context.Context, database string, r io.Reader) (ltx.TXID, error)

ImportDatabase creates a new database with the SQLite database contained in r. A cluster-scoped authentication token with write permissions is required.

func (*Client) Info

func (c *Client) Info(ctx context.Context, database string, all bool) (*DBInfoOutput, error)

Regions returns a list of available LiteFS Cloud regions.

func (*Client) ListClusters

func (c *Client) ListClusters(ctx context.Context, input *ListClustersInput) (*ListClustersOutput, error)

ListClusters returns a list of clusters for the current organization. An org-scoped authentication token with read permissions is required.

func (*Client) Pos

func (c *Client) Pos(ctx context.Context) (map[string]ltx.Pos, error)

Pos returns a map of database names with their current replication position. A cluster-scoped authentication token with read permissions is required.

func (*Client) Regions

func (c *Client) Regions(ctx context.Context) ([]string, error)

Regions returns a list of available LiteFS Cloud regions.

func (*Client) RestoreDatabase

func (c *Client) RestoreDatabase(ctx context.Context, database string, ro RestoreOption) (ltx.TXID, error)

RestoreDatabase reverts the database to the state by timestamp or txid. A cluster-scoped authentication token with write permissions is required.

type Cluster

type Cluster struct {
	OrgID     int       `json:"orgID"`
	Name      string    `json:"name"`
	Region    string    `json:"region"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

Cluster represents a grouping of databases in LiteFS Cloud.

type DBInfoOutput

type DBInfoOutput struct {
	Name            string                 `json:"name"`
	RestorablePaths []DBInfoRestorablePath `json:"restorablePaths"`
}

type DBInfoRestorablePath

type DBInfoRestorablePath struct {
	MaxTXID           string     `json:"maxTxId"`
	Timestamp         *time.Time `json:"maxTimestamp,omitempty"`
	PostApplyChecksum string     `json:"postApplyChecksum"`
}

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"error"`
}

Error represents an error code & message returned from LiteFS Cloud.

func (*Error) Error

func (e *Error) Error() string

Error returns a string-formatted message. Implements the error interface.

type ListClustersInput

type ListClustersInput struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

type ListClustersOutput

type ListClustersOutput struct {
	Offset   int        `json:"offset"`
	Limit    int        `json:"limit"`
	Total    int        `json:"total"`
	Clusters []*Cluster `json:"clusters"`
}

type RestoreOption

type RestoreOption func(*restoreOptions)

func RestoreByTXID

func RestoreByTXID(txid string) RestoreOption

RestoreByTXID tries to restore to the txid, if available.

func RestoreByTimestamp

func RestoreByTimestamp(timestamp time.Time) RestoreOption

RestoreByTimestamp tries to restore to the timestamp, or closest point earlier than the timestamp.

Jump to

Keyboard shortcuts

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