mysql

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SELECT = iota
	DELETE
	UPDATE
	INSERT
)

The query types.

View Source
const (
	ISSORT    = "isSort"
	ISJOIN    = "isJoin"
	ISDEFAULT = "isDefault"
	INNER     = "INNER"
	LEFT      = "LEFT"
	RIGHT     = "RIGHT"
)

The query flags.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database records dataSourceName 、db

func New

func New(dataSourceName string) *Database

New returns a newly initialized Database that implements Database dataSourceName ("user:password@tcp(ip:port)/database")

func (*Database) Begin

func (database *Database) Begin() (*Transaction, error)

Begin starts a transaction. The default isolation level is dependent on the driver.

func (*Database) Close

func (database *Database) Close() error

Close closes the database, releasing any open resources.

func (*Database) Fetch

func (database *Database) Fetch(sql string, args ...interface{}) *sql.Row

Fetch executes a query that is expected to return at most one row. Fetch is wrapped for db.QueryRow

func (*Database) GetDB

func (database *Database) GetDB() *sql.DB

GetDB returns db

func (*Database) Open

func (database *Database) Open() (*Database, error)

Open returns mysql driver database

func (*Database) Ping

func (database *Database) Ping() error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

func (*Database) Prepare

func (database *Database) Prepare(sql string) (*sql.Stmt, error)

Prepare creates a prepared statement for later queries or executions.

func (*Database) Query

func (database *Database) Query(sql string, args ...interface{}) (*sql.Rows, error)

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func (*Database) SetDB

func (database *Database) SetDB(db *sql.DB)

SetDB sets db

type FromSqlParts

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

FromSqlParts records table and alias

type JoinSqlParts

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

JoinSqlParts records joinType, joinTable, joinAlias, joinCondition

type OrderBySqlParts

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

OrderBySqlParts records sort and order

type QueryBuilder

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

QueryBuilder defined a SQL query builder.

func NewQueryBuilder

func NewQueryBuilder(database *Database) *QueryBuilder

NewQueryBuilder returns a newly initialized QueryBuilder that implements QueryBuilder

func (*QueryBuilder) Delete

func (queryBuilder *QueryBuilder) Delete(table string) *QueryBuilder

Delete turns the query being built into a bulk delete query that ranges over

func (*QueryBuilder) From

func (queryBuilder *QueryBuilder) From(table string, alias string) *QueryBuilder

From returns QueryBuilder that creates and adds a query root corresponding to the table identified by the given alias, forming a cartesian product with any existing query roots.

func (*QueryBuilder) GetFirstResult

func (queryBuilder *QueryBuilder) GetFirstResult() int

GetFirstResult gets the position of the first result the query object was set to retrieve.

func (*QueryBuilder) GetMaxResults

func (queryBuilder *QueryBuilder) GetMaxResults() int

GetMaxResults gets the maximum number of results the query object was set to retrieve

func (*QueryBuilder) GetParameter

func (queryBuilder *QueryBuilder) GetParameter() []interface{}

GetParameter gets all defined query parameters for the query being constructed indexed by parameter index or name.

func (*QueryBuilder) GetParams

func (queryBuilder *QueryBuilder) GetParams() []interface{}

GetParams returns queryBuilder params

func (*QueryBuilder) GetSQL

func (queryBuilder *QueryBuilder) GetSQL() string

GetSQL gets the complete SQL string formed by the current specifications of this QueryBuilder.

func (*QueryBuilder) GroupBy

func (queryBuilder *QueryBuilder) GroupBy(groupBy string) *QueryBuilder

GroupBy returns QueryBuilder that specifies a grouping over the results of the query.

func (*QueryBuilder) Having

func (queryBuilder *QueryBuilder) Having(having string) *QueryBuilder

Having returns QueryBuilder that specifies a restriction over the groups of the query.

func (*QueryBuilder) InnerJoin

func (queryBuilder *QueryBuilder) InnerJoin(join string, alias string, condition string) *QueryBuilder

InnerJoin returns QueryBuilder that creates and adds a join to the query.

func (*QueryBuilder) Insert

func (queryBuilder *QueryBuilder) Insert(table string) *QueryBuilder

Insert turns the query being built into an insert query that inserts into

func (*QueryBuilder) Join

func (queryBuilder *QueryBuilder) Join(join string, alias string, condition string) *QueryBuilder

Join returns QueryBuilder that creates and adds a join to the query.

func (*QueryBuilder) LeftJoin

func (queryBuilder *QueryBuilder) LeftJoin(join string, alias string, condition string) *QueryBuilder

LeftJoin returns QueryBuilder that creates and adds a left join to the query.

func (*QueryBuilder) OrderBy

func (queryBuilder *QueryBuilder) OrderBy(sort string, order string) *QueryBuilder

OrderBy returns QueryBuilder that specifies an ordering for the query results.

func (*QueryBuilder) PrepareAndExecute

func (queryBuilder *QueryBuilder) PrepareAndExecute() (int64, error)

PrepareAndExecute creates a prepared statement for later queries or executions.

func (*QueryBuilder) Query

func (queryBuilder *QueryBuilder) Query() (*sql.Rows, error)

Query executes a query that returns rows

func (*QueryBuilder) QueryAndGetMap

func (queryBuilder *QueryBuilder) QueryAndGetMap() (map[int]map[string]string, error)

QueryAndGetMap executes a query that returns rows map

func (*QueryBuilder) RightJoin

func (queryBuilder *QueryBuilder) RightJoin(join string, alias string, condition string) *QueryBuilder

RightJoin returns QueryBuilder that creates and adds a right join to the query.

func (*QueryBuilder) Select

func (queryBuilder *QueryBuilder) Select(value string) *QueryBuilder

Select returns QueryBuilder that Specifies an item that is to be returned in the query result.

func (*QueryBuilder) Set

func (queryBuilder *QueryBuilder) Set(key string, val interface{}) *QueryBuilder

Set returns QueryBuilder that sets a new value for a column in a bulk update query.

func (*QueryBuilder) SetFirstResult

func (queryBuilder *QueryBuilder) SetFirstResult(firstResult int) *QueryBuilder

SetFirstResult returns QueryBuilder that sets the position of the first result to retrieve.

func (*QueryBuilder) SetMaxResults

func (queryBuilder *QueryBuilder) SetMaxResults(maxResults int) *QueryBuilder

SetMaxResults sets the maximum number of results to retrieve.

func (*QueryBuilder) SetParam

func (queryBuilder *QueryBuilder) SetParam(param interface{}) *QueryBuilder

SetParam sets a query parameter for the query being constructed.

func (*QueryBuilder) Update

func (queryBuilder *QueryBuilder) Update(table string, alias string) *QueryBuilder

Update returns QueryBuilder that turns the query being built into a bulk update query that ranges over a certain table

func (*QueryBuilder) Value

func (queryBuilder *QueryBuilder) Value(key string, val interface{}) *QueryBuilder

Value returns QueryBuilder that sets a new value for a column in a bulk insert query.

func (*QueryBuilder) Where

func (queryBuilder *QueryBuilder) Where(condition string) *QueryBuilder

Where returns QueryBuilder that specifies one or more restrictions to the query result.

type SetSqlParts

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

SetSqlParts records key, val

type Transaction

type Transaction struct {
	Tx *sql.Tx
}

Transaction records Tx

func NewTx

func NewTx() *Transaction

NewTx returns a newly initialized Transaction that implements Transaction

func (*Transaction) Commit

func (transaction *Transaction) Commit() error

Commit commits the transaction.

func (*Transaction) PrepareAndExecute

func (transaction *Transaction) PrepareAndExecute(queryBuilder *QueryBuilder) (sql.Result, error)

PrepareAndExecute creates a prepared statement for later queries or executions.

func (*Transaction) Rollback

func (transaction *Transaction) Rollback() error

Rollback aborts the transaction.

type ValuesSqlParts

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

ValuesSqlParts records key, val

Jump to

Keyboard shortcuts

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