core

package
v0.0.0-...-21d2cc0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDatabaseSwitchingNotSupported = errors.New("database switching not supported")
View Source
var ErrInvalidRange = func(from int, to int) error { return fmt.Errorf("invalid selection range: %d ... %d", from, to) }

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	Connect(url string) (Driver, error)
	GetHelpers(opts *TableOptions) map[string]string
}

Adapter is an object which allows to connect to database using a url. It also has the GetHelpers method, which returns a list of operations for a given type.

type Call

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

func (*Call) Cancel

func (c *Call) Cancel()

func (*Call) Done

func (c *Call) Done() chan struct{}

Done returns a non-buffered channel that is closed when call finishes.

func (*Call) Err

func (c *Call) Err() error

func (*Call) GetID

func (c *Call) GetID() CallID

func (*Call) GetQuery

func (c *Call) GetQuery() string

func (*Call) GetResult

func (c *Call) GetResult() (*Result, error)

func (*Call) GetState

func (c *Call) GetState() CallState

func (*Call) GetTimeTaken

func (c *Call) GetTimeTaken() time.Duration

func (*Call) GetTimestamp

func (c *Call) GetTimestamp() time.Time

func (*Call) MarshalJSON

func (s *Call) MarshalJSON() ([]byte, error)

func (*Call) UnmarshalJSON

func (c *Call) UnmarshalJSON(data []byte) error

type CallID

type CallID string

type CallState

type CallState int
const (
	CallStateUnknown CallState = iota
	CallStateExecuting
	CallStateExecutingFailed
	CallStateRetrieving
	CallStateRetrievingFailed
	CallStateArchived
	CallStateArchiveFailed
	CallStateCanceled
)

func CallStateFromString

func CallStateFromString(s string) CallState

func (CallState) String

func (s CallState) String() string

type Column

type Column struct {
	// Column name
	Name string
	// Database data type
	Type string
}

type Connection

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

func NewConnection

func NewConnection(params *ConnectionParams, adapter Adapter) (*Connection, error)

func (*Connection) Close

func (c *Connection) Close()

func (*Connection) Execute

func (c *Connection) Execute(query string, onEvent func(CallState, *Call)) *Call

func (*Connection) GetColumns

func (c *Connection) GetColumns(opts *TableOptions) ([]*Column, error)

func (*Connection) GetHelpers

func (c *Connection) GetHelpers(opts *TableOptions) map[string]string

func (*Connection) GetID

func (c *Connection) GetID() ConnectionID

func (*Connection) GetName

func (c *Connection) GetName() string

func (*Connection) GetParams

func (c *Connection) GetParams() *ConnectionParams

GetParams returns the original source for this connection

func (*Connection) GetStructure

func (c *Connection) GetStructure() ([]*Structure, error)

func (*Connection) GetType

func (c *Connection) GetType() string

func (*Connection) GetURL

func (c *Connection) GetURL() string

func (*Connection) ListDatabases

func (c *Connection) ListDatabases() (current string, available []string, err error)

func (*Connection) MarshalJSON

func (s *Connection) MarshalJSON() ([]byte, error)

func (*Connection) SelectDatabase

func (c *Connection) SelectDatabase(name string) error

SelectDatabase tries to switch to a given database with the used client. on error, the switch doesn't happen and the previous connection remains active.

type ConnectionID

type ConnectionID string

type ConnectionParams

type ConnectionParams struct {
	ID   ConnectionID
	Name string
	Type string
	URL  string
}

func (*ConnectionParams) Expand

func (p *ConnectionParams) Expand() *ConnectionParams

Expand returns a copy of the original parameters with expanded fields

func (*ConnectionParams) MarshalJSON

func (cp *ConnectionParams) MarshalJSON() ([]byte, error)

type DatabaseSwitcher

type DatabaseSwitcher interface {
	SelectDatabase(string) error
	ListDatabases() (current string, available []string, err error)
}

DatabaseSwitcher is an optional interface for drivers that have database switching capabilities.

type Driver

type Driver interface {
	Query(ctx context.Context, query string) (ResultStream, error)
	Structure() ([]*Structure, error)
	Columns(opts *TableOptions) ([]*Column, error)
	Close()
}

Driver is an interface for a specific database driver.

type Formatter

type Formatter interface {
	Format(header Header, rows []Row, opts *FormatterOptions) ([]byte, error)
}

Formatter converts header and rows to bytes

type FormatterOptions

type FormatterOptions struct {
	SchemaType SchemaType
	ChunkStart int
}

FormatterOptions provide various options for formatters

type Header []string

type Meta

type Meta struct {
	// type of schema (schemaful or schemaless)
	SchemaType SchemaType
}

Meta holds metadata

type Result

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

Result is the cached form of the ResultStream iterator

func (*Result) Format

func (cr *Result) Format(formatter Formatter, from, to int) ([]byte, error)

func (*Result) Header

func (cr *Result) Header() Header

func (*Result) IsEmpty

func (cr *Result) IsEmpty() bool

func (*Result) Len

func (cr *Result) Len() int

func (*Result) Meta

func (cr *Result) Meta() *Meta

func (*Result) Rows

func (cr *Result) Rows(from, to int) ([]Row, error)

func (*Result) SetIter

func (cr *Result) SetIter(iter ResultStream, onFillStart func()) error

SetIter sets the ResultStream iterator to result. This can be done only once!

func (*Result) Wipe

func (cr *Result) Wipe()

type ResultStream

type ResultStream interface {
	Meta() *Meta
	Header() Header
	Next() (Row, error)
	HasNext() bool
	Close()
}

ResultStream is a result from executed query and has a form of an iterator

type Row

type Row []any

Row and Header are attributes of IterResult iterator

type SchemaType

type SchemaType int
const (
	SchemaFul SchemaType = iota
	SchemaLess
)

type Structure

type Structure struct {
	// Name to be displayed
	Name   string
	Schema string
	// Type of layout
	Type StructureType
	// Children layout nodes
	Children []*Structure
}

Structure represents the structure of a single database

type StructureType

type StructureType int
const (
	StructureTypeNone StructureType = iota
	StructureTypeTable
	StructureTypeView
)

func StructureTypeFromString

func StructureTypeFromString(s string) StructureType

func (StructureType) String

func (s StructureType) String() string

type TableOptions

type TableOptions struct {
	Table           string
	Schema          string
	Materialization StructureType
}

TableOptions contain options for gathering information about specific table.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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