common

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2013 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SBegin    = "BEGIN"
	SCommit   = "COMMIT"
	SRollback = "ROLLBACK"
)
View Source
const (
	CapBulkTransfer = iota
)

Variables

View Source
var (
	ErrTxInProgress    = errors.New("another transaction is already in progress")
	ErrNoTxInProgress  = errors.New("no transaction is in progress")
	ErrCapNotSupported = errors.New("capbility not supported")
)
View Source
var (
	DBEXEC_VERBOSE = true
)

Functions

func FilterInclExcl

func FilterInclExcl(list []string, incl map[string]bool, excl map[string]bool) []string

Types

type Column

type Column struct {
	TableName    string
	Name         string
	Type         *Type
	RawType      string
	Length       int
	Null         bool
	PrimaryKey   bool
	AutoIncr     bool
	Default      interface{}
	NeedsQuoting bool

	/* how to select the column */
	Select string
}

type Config

type Config struct {
	Hostname string `yaml:"hostname,omitempty"`
	Socket   string `yaml:"socket,omitempty"`
	Port     int    `yaml:"port,omitempty"`
	Username string `yaml:"username,omitempty"`
	Password string `yaml:"password,omitempty"`
	Database string `yaml:"database,omitempty"`
	Compress bool   `yaml:"compress,omitempty"`
}

type DbExecutor

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

func NewDbExecutor

func NewDbExecutor(db *sql.DB) (*DbExecutor, error)

func (*DbExecutor) Begin added in v0.4.1

func (e *DbExecutor) Begin(name string) error

func (*DbExecutor) BulkAddRecord added in v0.4.1

func (e *DbExecutor) BulkAddRecord(args ...interface{}) error

func (*DbExecutor) BulkFinish added in v0.4.1

func (e *DbExecutor) BulkFinish() error

func (*DbExecutor) BulkInit added in v0.4.1

func (e *DbExecutor) BulkInit(table string, columns ...string) error

func (*DbExecutor) Close

func (e *DbExecutor) Close() error

warning: closes the db connection that was passed to the constructor

func (*DbExecutor) Commit added in v0.4.1

func (e *DbExecutor) Commit() error

func (*DbExecutor) GetDb

func (e *DbExecutor) GetDb() *sql.DB

func (*DbExecutor) GetTx added in v0.4.1

func (e *DbExecutor) GetTx() *sql.Tx

func (*DbExecutor) HasCapability

func (e *DbExecutor) HasCapability(capability int) bool

func (*DbExecutor) Multiple

func (e *DbExecutor) Multiple(name string, statements []string) []error

func (*DbExecutor) Rollback added in v0.4.1

func (e *DbExecutor) Rollback() error

func (*DbExecutor) Single

func (e *DbExecutor) Single(name string, statement string) error

func (*DbExecutor) Submit added in v0.4.1

func (e *DbExecutor) Submit(stmt string) error

func (*DbExecutor) Transaction

func (e *DbExecutor) Transaction(name string, statements []string) error

type Executor

type Executor interface {
	io.Closer

	/* begin a transaction, it's an error to begin a transaction
	 * while another is already in progress */
	Begin(name string) error
	Commit() error

	/* if the statement provokes an error, will automatically rollback,
	 * after which the transaction is no longer in progress */
	Submit(stmt string) error

	/* bulk statements for copying large amounts of data, the underlying
	 * implementation will try to use the most efficient way of achieving this,
	 * for example postgres' COPY FROM semantics. */
	BulkInit(table string, columns ...string) error
	BulkAddRecord(args ...interface{}) error
	BulkFinish() error

	/* submit a transaction in one go */
	Transaction(name string, statements []string) error

	/* submit multiple statements in one go (without a transaction) */
	Multiple(name string, statements []string) []error

	/* submit a single statement */
	Single(name string, statement string) error

	/* for e.g. PostgreSQL COPY support */
	HasCapability(capability int) bool

	/* will return the underlying sql.DB if it exists, otherwise nil */
	GetDb() *sql.DB

	/* will return the underlying sql.Tx if it exists, otherwise nil */
	GetTx() *sql.Tx
}

type FileExecutor

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

func NewFileExecutor

func NewFileExecutor(filename string) (*FileExecutor, error)

func (*FileExecutor) Begin added in v0.4.1

func (e *FileExecutor) Begin(name string) error

func (*FileExecutor) BulkAddRecord added in v0.4.1

func (e *FileExecutor) BulkAddRecord(args ...interface{}) error

func (*FileExecutor) BulkFinish added in v0.4.1

func (e *FileExecutor) BulkFinish() error

func (*FileExecutor) BulkInit added in v0.4.1

func (e *FileExecutor) BulkInit(table string, columns ...string) error

func (*FileExecutor) Close

func (e *FileExecutor) Close() error

func (*FileExecutor) Commit added in v0.4.1

func (e *FileExecutor) Commit() error

func (*FileExecutor) GetDb

func (e *FileExecutor) GetDb() *sql.DB

func (*FileExecutor) GetTx added in v0.4.1

func (e *FileExecutor) GetTx() *sql.Tx

func (*FileExecutor) HasCapability

func (e *FileExecutor) HasCapability(capability int) bool

func (*FileExecutor) Multiple

func (e *FileExecutor) Multiple(name string, statements []string) []error

func (*FileExecutor) Single

func (e *FileExecutor) Single(name string, statement string) error

func (*FileExecutor) Submit added in v0.4.1

func (e *FileExecutor) Submit(stmt string) error

func (*FileExecutor) Transaction

func (e *FileExecutor) Transaction(name string, statements []string) error

type Queryer

type Queryer interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type ReadCloser

type ReadCloser interface {
	io.Closer
	Reader
}

type Reader

type Reader interface {
	Queryer

	TableNames() []string

	/* FilteredTables() is more performant than Tables() if you
	 * only need a few tables */
	Tables() []*Table
	FilteredTables(incl, excl map[string]bool) []*Table

	Read(table *Table) (*sql.Rows, error)
	CreateView(name string, body string) error
	DropView(name string) error

	CreateProjection(name string, body string, engine string, pk []string, uks [][]string) error
	DropProjection(name string) error
}

type Table

type Table struct {
	Name    string
	DbType  string /* mysql, postgres, sqlite, ... */
	Columns []*Column
}

type Type added in v0.4.3

type Type struct {
	/* a base type, possible values:
	 * - text,
	 * - char,
	 * - boolean,
	 * - blob
	 * - float
	 * - double
	 * - numeric (floating point type with scale/precision)
	 * - integer */
	Name string

	/* parameters that are optionally added to base types */
	Max       uint
	Min       uint
	Scale     uint
	Precision uint
}

func BlobType added in v0.4.3

func BlobType() *Type

func BoolType added in v0.4.3

func BoolType() *Type

func DoubleType added in v0.4.3

func DoubleType() *Type

func FloatType added in v0.4.3

func FloatType() *Type

func IntType added in v0.4.3

func IntType() *Type

func NumericType added in v0.4.3

func NumericType(precision, scale uint) *Type

func PaddedTextType added in v0.4.3

func PaddedTextType() *Type

padded text

func SimpleType added in v0.4.3

func SimpleType(name string) *Type

for external usage

func TextType added in v0.4.3

func TextType() *Type

func (*Type) HasMax added in v0.4.3

func (t *Type) HasMax() bool

func (*Type) HasMin added in v0.4.3

func (t *Type) HasMin() bool

type WriteCloser

type WriteCloser interface {
	io.Closer
	Writer
}

type Writer

type Writer interface {

	/* merge the contents of table */
	MergeTable(src *Table, dstName string, r Reader) error
}

Jump to

Keyboard shortcuts

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