client

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 32 Imported by: 46

Documentation

Index

Constants

View Source
const (
	CodecNone   = "none"
	CodecHex    = "hex"
	CodecBase58 = "base58"
	CodecBase64 = "base64"
)
View Source
const (
	ObjTypeTable            = "table"
	ObjTypeView             = "view"
	ObjTypeMaterializedView = "materialized_view"
	ObjTypeSequence         = "sequence"
	ObjTypeFunction         = "function"
)

Variables

View Source
var (
	ErrAuthFailed        = errors.New("authentication failed")
	ErrConnectionRefused = errors.New("connection refused")
	ErrDatabaseNotExist  = errors.New("database does not exist")
)
View Source
var (
	// BinaryCodec sets the serialization format of binary data
	BinaryCodec = CodecBase64
)

Functions

func ObjectsFromResult added in v0.9.0

func ObjectsFromResult(res *Result) map[string]*Objects

func SetBinaryCodec added in v0.11.10

func SetBinaryCodec(codec string) error

Types

type Client

type Client struct {
	External         bool             `json:"external"`
	History          []history.Record `json:"history"`
	ConnectionString string           `json:"connection_string"`
	// contains filtered or unexported fields
}

func New

func New() (*Client, error)

func NewFromBookmark added in v0.13.0

func NewFromBookmark(bookmark *bookmarks.Bookmark) (*Client, error)

func NewFromUrl

func NewFromUrl(url string, sshInfo *shared.SSHInfo) (*Client, error)

func (*Client) Activity

func (client *Client) Activity() (*Result, error)

Returns all active queriers on the server

func (*Client) Close

func (client *Client) Close() error

Close database connection

func (*Client) Databases

func (client *Client) Databases() ([]string, error)

func (*Client) EstimatedTableRowsCount added in v0.10.0

func (client *Client) EstimatedTableRowsCount(table string, opts RowsOptions) (*Result, error)

func (*Client) Function added in v0.12.0

func (client *Client) Function(id string) (*Result, error)

func (*Client) GetConnContext added in v0.14.0

func (client *Client) GetConnContext() (*ConnContext, error)

ConnContext returns information about current database connection

func (*Client) Info

func (client *Client) Info() (*Result, error)

func (*Client) IsClosed added in v0.12.0

func (c *Client) IsClosed() bool

func (*Client) IsIdle added in v0.9.9

func (client *Client) IsIdle() bool

func (*Client) LastQueryTime added in v0.12.0

func (c *Client) LastQueryTime() time.Time

func (*Client) MaterializedView added in v0.9.0

func (client *Client) MaterializedView(name string) (*Result, error)

func (*Client) Objects added in v0.9.0

func (client *Client) Objects() (*Result, error)

func (*Client) Query

func (client *Client) Query(query string) (*Result, error)

func (*Client) Schemas

func (client *Client) Schemas() ([]string, error)

func (*Client) ServerVersion added in v0.9.9

func (client *Client) ServerVersion() string

func (*Client) ServerVersionInfo added in v0.12.0

func (client *Client) ServerVersionInfo() string

func (*Client) SetReadOnlyMode added in v0.9.6

func (client *Client) SetReadOnlyMode() error

func (*Client) Table

func (client *Client) Table(table string) (*Result, error)

func (*Client) TableConstraints added in v0.7.0

func (client *Client) TableConstraints(table string) (*Result, error)

func (*Client) TableIndexes

func (client *Client) TableIndexes(table string) (*Result, error)

func (*Client) TableInfo

func (client *Client) TableInfo(table string) (*Result, error)

func (*Client) TableRows

func (client *Client) TableRows(table string, opts RowsOptions) (*Result, error)

func (*Client) TableRowsCount added in v0.8.0

func (client *Client) TableRowsCount(table string, opts RowsOptions) (*Result, error)

func (*Client) TablesStats added in v0.14.0

func (client *Client) TablesStats() (*Result, error)

func (*Client) Test

func (client *Client) Test() error

func (*Client) TestWithTimeout added in v0.13.0

func (client *Client) TestWithTimeout(timeout time.Duration) (result error)

type ConnContext added in v0.14.0

type ConnContext struct {
	Host     string
	User     string
	Database string
	Mode     string
}

func (ConnContext) String added in v0.14.0

func (c ConnContext) String() string

type Dump added in v0.9.9

type Dump struct {
	Table string
}

Dump represents a database dump

func (*Dump) Export added in v0.9.9

func (d *Dump) Export(ctx context.Context, connstr string, writer io.Writer) error

Export streams the database dump to the specified writer

func (*Dump) Validate added in v0.12.0

func (d *Dump) Validate(serverVersion string) error

Validate checks availability and version of pg_dump CLI

type Object added in v0.12.0

type Object struct {
	OID  string `json:"oid"`
	Name string `json:"name"`
}

type Objects added in v0.9.0

type Objects struct {
	Tables            []Object `json:"table"`
	Views             []Object `json:"view"`
	MaterializedViews []Object `json:"materialized_view"`
	Functions         []Object `json:"function"`
	Sequences         []Object `json:"sequence"`
}

type Pagination added in v0.8.0

type Pagination struct {
	Rows    int64 `json:"rows_count"`
	Page    int64 `json:"page"`
	Pages   int64 `json:"pages_count"`
	PerPage int64 `json:"per_page"`
}

type Result

type Result struct {
	Pagination *Pagination  `json:"pagination,omitempty"`
	Columns    []string     `json:"columns"`
	Rows       []Row        `json:"rows"`
	Stats      *ResultStats `json:"stats,omitempty"`
}

func (*Result) CSV

func (res *Result) CSV() []byte

func (*Result) Format

func (res *Result) Format() []map[string]interface{}

func (*Result) JSON added in v0.7.0

func (res *Result) JSON() []byte

func (*Result) PostProcess added in v0.11.10

func (res *Result) PostProcess()

Due to big int number limitations in javascript, numbers should be encoded as strings so they could be properly loaded on the frontend.

type ResultStats added in v0.13.0

type ResultStats struct {
	ColumnsCount    int       `json:"columns_count"`
	RowsCount       int       `json:"rows_count"`
	RowsAffected    int64     `json:"rows_affected"`
	QueryStartTime  time.Time `json:"query_start_time"`
	QueryFinishTime time.Time `json:"query_finish_time"`
	QueryDuration   int64     `json:"query_duration_ms"`
}

type Row

type Row []interface{}

Row represents a single row of data

type RowsOptions

type RowsOptions struct {
	Where      string // Custom filter
	Offset     int    // Number of rows to skip
	Limit      int    // Number of rows to fetch
	SortColumn string // Column to sort by
	SortOrder  string // Sort direction (ASC, DESC)
}

RowsOptions contains a list of parameters for table browsing requests

type Tunnel added in v0.9.0

type Tunnel struct {
	TargetHost string
	TargetPort string
	Port       int
	SSHInfo    *shared.SSHInfo
	Config     *ssh.ClientConfig
	Client     *ssh.Client
	Listener   *net.TCPListener
}

Tunnel represents the connection between local and remote server

func NewTunnel added in v0.9.0

func NewTunnel(sshInfo *shared.SSHInfo, dbUrl string) (*Tunnel, error)

NewTunnel instantiates a new tunnel struct from given ssh info

func (*Tunnel) Close added in v0.9.0

func (tunnel *Tunnel) Close()

Close closes the tunnel connection

func (*Tunnel) Configure added in v0.9.0

func (tunnel *Tunnel) Configure() error

Configure establishes the tunnel between localhost and remote machine

func (*Tunnel) Start added in v0.9.0

func (tunnel *Tunnel) Start()

Start starts the connection handler loop

Jump to

Keyboard shortcuts

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