jet: github.com/eaigner/jet Index | Files

package jet

import "github.com/eaigner/jet"

Index

Package Files

colconv.go db.go expand.go lru.go mapper.go query.go suite.go tx.go types.go util.go

Constants

const (
    TableName  string = "migrations"
    ColumnName string = "version"
)

type ColumnConverter Uses

type ColumnConverter interface {
    ColumnToFieldName(col string) string
}

ColumnConverter converts between struct field names and database row names

var SnakeCaseConverter ColumnConverter = &snakeConv{}

SnakeCaseConverter converts column names from snake_case to CamelCase field names.

type ComplexValue Uses

type ComplexValue interface {
    Encode() interface{}

    // Decode receives a plain value to decode, never a pointer.
    Decode(v interface{}) error
}

ComplexValue implements methods for en/decoding custom values to a format the driver understands.

type Db Uses

type Db struct {
    *sql.DB

    // LogFunc is the log function to use for query logging.
    // Defaults to nil.
    LogFunc LogFunc

    // The column converter to use.
    // Defaults to SnakeCaseConverter.
    ColumnConverter ColumnConverter
    // contains filtered or unexported fields
}

func Open Uses

func Open(driverName, dataSourceName string) (*Db, error)

Open opens a new database connection.

func (*Db) Begin Uses

func (db *Db) Begin() (*Tx, error)

Begin starts a new transaction

func (*Db) Query Uses

func (db *Db) Query(query string, args ...interface{}) Runnable

Query creates a prepared query that can be run with Rows or Run.

func (*Db) SetMaxCachedStatements Uses

func (db *Db) SetMaxCachedStatements(n int)

SetMaxCachedStatements sets the max number of statements to cache in the LRU. The default is 500.

type LogFunc Uses

type LogFunc func(queryId, query string, args ...interface{})

LogFunc can be set on the Db instance to allow query logging.

type Migration Uses

type Migration struct {
    Up   string
    Down string
    // contains filtered or unexported fields
}

Migration represents a migration step with up and down SQL strings.

type Runnable Uses

type Runnable interface {
    // Run runs the query without returning results
    Run() error
    // Rows runs the query writing the rows to the specified map or struct array.
    Rows(v interface{}) error
}

type Stmts Uses

type Stmts struct {
    CreateTableSQL   string
    SelectVersionSQL string
    InsertVersionSQL string
    UpdateVersionSQL string
}

type Suite Uses

type Suite struct {
    Migrations []*Migration
    Stmts      *Stmts
    // contains filtered or unexported fields
}

func (*Suite) Add Uses

func (s *Suite) Add(m *Migration)

Add adds a migration step to the suite.

func (*Suite) AddSQL Uses

func (s *Suite) AddSQL(up, down string)

AddSQL is a shorthand for Add taking strings for the up and down SQL.

func (*Suite) Migrate Uses

func (s *Suite) Migrate(db *Db) (int, int, error)

Migrate applies all migrations.

func (*Suite) Reset Uses

func (s *Suite) Reset(db *Db) (int, int, error)

Reset rolls back all migrations

func (*Suite) Rollback Uses

func (s *Suite) Rollback(db *Db) (int, int, error)

Rollback rolls back 1 step.

func (*Suite) Run Uses

func (s *Suite) Run(db *Db, up bool, maxSteps int) (int, int, error)

Run runs the entire migration suite. If up is false, it will run in reverse. It returns the current migration id, the number of steps applied in this run and an error (if one occurred).

func (*Suite) Step Uses

func (s *Suite) Step(db *Db) (int, int, error)

Step applies 1 migration (upward).

type Tx Uses

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

Tx represents a transaction instance. It can be created using Begin on the *Db object.

func (*Tx) Commit Uses

func (tx *Tx) Commit() error

Commit commits the transaction

func (*Tx) Query Uses

func (tx *Tx) Query(query string, args ...interface{}) Runnable

Query creates a prepared query that can be run with Rows or Run.

func (*Tx) Rollback Uses

func (tx *Tx) Rollback() error

Rollback rolls back the transaction

Package jet imports 13 packages (graph) and is imported by 10 packages. Updated 2016-07-15. Refresh now. Tools for package owners.