dbx

package
v0.0.0-...-6c293db Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrReadOnly = errors.New("error 1299. Can't write changes in Read-Only mode")

Functions

func Convert

func Convert(v interface{}, t ColType) (interface{}, error)

func IsIdent

func IsIdent(s string) bool

func ParseDateTime

func ParseDateTime(v interface{}) (time.Time, error)

func ParseDateTimeStr

func ParseDateTimeStr(str string) (time.Time, error)

func ParseInt

func ParseInt(v interface{}) (int, error)

func ParseTime

func ParseTime(v []uint8) (time.Duration, error)

Types

type ColType

type ColType int
const (
	String ColType = iota
	Int
	Decimal
	Bool
	Time
	Date
	DateTime
	Blob
	Unknown
)

func (ColType) MarshalJSON

func (c ColType) MarshalJSON() ([]byte, error)

func (ColType) String

func (i ColType) String() string

type Column

type Column struct {
	Name     string       `json:"name"`
	Type     ColType      `json:"type"`
	ScanType reflect.Type `json:"-"`
}

type DB

type DB struct {
	sync.Mutex
	*sql.DB
	Driver    string
	Database  string
	Namespace string
	Prefix    string
	ReadOnly  bool
	IgnoreTx  bool
	NestedTx  bool
	// contains filtered or unexported fields
}

func Open

func Open(driver, dsn string) (*DB, error)

func OpenDatabase

func OpenDatabase(database, driver, dsn string) (*DB, error)

OpenDatabase opens a new database handle.

func (*DB) Begin

func (db *DB) Begin() error

func (*DB) Clone

func (db *DB) Clone() *DB

Copies the database but without transaction information

func (*DB) Columns

func (db *DB) Columns(table string) ([]SchemaColumn, error)

func (*DB) Commit

func (db *DB) Commit() error

func (*DB) Databases

func (db *DB) Databases() (*Table, error)

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

func (*DB) ExecEx

func (db *DB) ExecEx(q sqx.Query, args ...interface{}) (sql.Result, error)

func (*DB) ExecRaw

func (db *DB) ExecRaw(query string, args ...interface{}) (sql.Result, error)

func (*DB) HasDatabase

func (db *DB) HasDatabase(name string) (bool, error)

func (*DB) HasTable

func (db *DB) HasTable(name string) (bool, error)

func (*DB) HasTransaction

func (db *DB) HasTransaction() bool

func (*DB) InitMultiDB

func (db *DB) InitMultiDB() error

func (*DB) Open

func (db *DB) Open(database string) *DB

Open returns a new db handler for the database.

func (*DB) Prepare

func (db *DB) Prepare(query string) (*Stmt, error)

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*Table, error)

func (*DB) QueryEx

func (db *DB) QueryEx(query *sqx.SelectQuery) (*Table, error)

func (*DB) QueryRaw

func (db *DB) QueryRaw(query string, args ...interface{}) (*sql.Rows, error)

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) (*Row, error)

func (*DB) QueryRowEx

func (db *DB) QueryRowEx(query *sqx.SelectQuery) (*Row, error)

func (*DB) QueryRowRaw

func (db *DB) QueryRowRaw(query string, args ...interface{}) *sql.Row

func (*DB) QueryRows

func (db *DB) QueryRows(query string, args ...interface{}) (*sql.Rows, error)

func (*DB) QueryRowsEx

func (db *DB) QueryRowsEx(q *sqx.SelectQuery) (*sql.Rows, error)

func (*DB) QueryValue

func (db *DB) QueryValue(query string, args ...interface{}) (interface{}, error)

func (*DB) QueryValueEx

func (db *DB) QueryValueEx(query *sqx.SelectQuery) (interface{}, error)

func (*DB) QueryValueRaw

func (db *DB) QueryValueRaw(query string, args ...interface{}) (interface{}, error)

func (*DB) Reader

func (db *DB) Reader(query string, args ...interface{}) (*Reader, error)

func (*DB) ReaderEx

func (db *DB) ReaderEx(query *sqx.SelectQuery) (*Reader, error)

func (*DB) ReaderRaw

func (db *DB) ReaderRaw(query string, args ...interface{}) (*Reader, error)

func (*DB) Rollback

func (db *DB) Rollback() error

func (*DB) ScanValueRaw

func (db *DB) ScanValueRaw(v interface{}, query string, args ...interface{}) error

func (*DB) ShowQuery

func (db *DB) ShowQuery(query string) (*Table, error)

func (*DB) ShowQueryEx

func (db *DB) ShowQueryEx(query *sqx.ShowQuery) (*Table, error)

func (*DB) ShowReader

func (db *DB) ShowReader(query string) (*Reader, error)

func (*DB) ShowReaderEx

func (db *DB) ShowReaderEx(query *sqx.ShowQuery) (*Reader, error)

func (*DB) Tables

func (db *DB) Tables() ([]string, error)

func (*DB) ToSql

func (db *DB) ToSql(q sqx.Query) (string, []interface{}, error)

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime scans null time values

func (*NullTime) Scan

func (t *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface. The value type must be time.Time otherwise Scan fails.

type Reader

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Columns

func (r *Reader) Columns() ([]*Column, error)

func (*Reader) Err

func (r *Reader) Err() error

func (*Reader) Next

func (r *Reader) Next() bool

func (*Reader) Read

func (r *Reader) Read() ([]interface{}, error)

type Row

type Row struct {
	Values []interface{} `json:"values"`
	// contains filtered or unexported fields
}

func (*Row) ColumnIndex

func (r *Row) ColumnIndex(column string) int

func (*Row) Columns

func (r *Row) Columns() []*Column

func (*Row) MarshalJSON

func (r *Row) MarshalJSON() ([]byte, error)

manually serialize

func (*Row) Table

func (r *Row) Table() *Table

func (*Row) Value

func (r *Row) Value(column string) (interface{}, bool)

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

type SchemaColumn

type SchemaColumn struct {
	Name     string
	Type     string
	Nullable bool
}

type Stmt

type Stmt struct {
	*DB
	*sql.Stmt
	// contains filtered or unexported fields
}

func (*Stmt) Close

func (stmt *Stmt) Close() error

func (*Stmt) Exec

func (stmt *Stmt) Exec(args ...interface{}) (sql.Result, error)

func (*Stmt) Query

func (stmt *Stmt) Query(args ...interface{}) (*sql.Rows, error)

func (*Stmt) QueryRow

func (stmt *Stmt) QueryRow(args ...interface{}) *sql.Row

type Table

type Table struct {
	Columns []*Column `json:"columns"`
	Rows    []*Row    `json:"rows"`
}

func ToTable

func ToTable(rows *sql.Rows) (*Table, error)

func ToTableLimit

func ToTableLimit(rows *sql.Rows, maxRows int) (*Table, bool, error)

Returns a table with up to maxRows number of rows and returns also if there are more rows to read.

func (*Table) ColumnIndex

func (t *Table) ColumnIndex(name string) int

func (*Table) NewRow

func (t *Table) NewRow() *Row

Jump to

Keyboard shortcuts

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