Documentation ¶
Index ¶
- Variables
- type Client
- func Connect(ctx context.Context, driver string, opt *options.ConnectOptions) (client *Client, err error)
- func ConnectDB(ctx context.Context, driver string, conn driver.Connector) (*Client, error)
- func MustConnect(ctx context.Context, driver string, opt *options.ConnectOptions) *Client
- func MustConnectDB(ctx context.Context, driver string, conn driver.Connector) *Client
- func MustOpen(ctx context.Context, driver string, opt *options.ConnectOptions) *Client
- func Open(ctx context.Context, driver string, opt *options.ConnectOptions) (client *Client, err error)
- func (c *Client) CreateDatabase(ctx context.Context, name string) error
- func (c *Client) Database(name string) *Database
- func (c *Client) DropDatabase(ctx context.Context, name string) error
- func (c *Client) ListDatabases(ctx context.Context) ([]string, error)
- func (c *Client) SetCodec(cdc codec.Codecer) *Client
- func (c *Client) SetLogger(logger logs.Logger) *Client
- func (c *Client) SetPrimaryKey(pk string) *Client
- func (c *Client) SetStructMapper(mapper reflext.StructMapper) *Client
- type Column
- type ColumnView
- type Database
- func (db *Database) BeginTransaction(ctx context.Context, opts ...*sql.TxOptions) (*Transaction, error)
- func (db *Database) BuildIndexes(ctx context.Context, paths ...string) error
- func (db *Database) QueryStmt(ctx context.Context, query interface{}) (*Result, error)
- func (db *Database) RunInTransaction(ctx context.Context, cb txCallback, opts ...*options.TransactionOptions) error
- func (db *Database) Table(name string) *Table
- type DriverInfo
- type Index
- type IndexView
- func (idv *IndexView) Create(ctx context.Context, idxs []indexes.Index) error
- func (idv *IndexView) CreateIfNotExists(ctx context.Context, idxs []indexes.Index) error
- func (idv *IndexView) CreateOne(ctx context.Context, idx indexes.Index) error
- func (idv *IndexView) CreateOneIfNotExists(ctx context.Context, idx indexes.Index) error
- func (idv *IndexView) DropAll(ctx context.Context) error
- func (idv IndexView) DropOne(ctx context.Context, name string) error
- func (idv *IndexView) List(ctx context.Context) ([]Index, error)
- type Paginator
- type Result
- func (r *Result) All(results interface{}) error
- func (r *Result) Close() error
- func (r *Result) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Result) Columns() []string
- func (r *Result) Decode(dst interface{}) error
- func (r *Result) Error() error
- func (r *Result) Next() bool
- func (r *Result) NextResultSet() bool
- func (r *Result) Scan(dests ...interface{}) error
- func (r *Result) ScanSlice(results interface{}) error
- type Resulter
- type SessionContext
- type SingleResult
- type Table
- func (tb *Table) Columns() *ColumnView
- func (tb *Table) Delete(ctx context.Context, act actions.DeleteStatement, ...) (int64, error)
- func (tb *Table) DeleteOne(ctx context.Context, act actions.DeleteOneStatement, ...) (int64, error)
- func (tb *Table) DestroyOne(ctx context.Context, delete interface{}, opts ...*options.DestroyOneOptions) error
- func (tb Table) Drop(ctx context.Context) (err error)
- func (tb Table) DropIfExists(ctx context.Context) (err error)
- func (tb *Table) Exists(ctx context.Context) bool
- func (tb *Table) Find(ctx context.Context, act actions.SelectStatement, opts ...*options.FindOptions) (*Result, error)
- func (tb *Table) FindOne(ctx context.Context, act actions.SelectOneStatement, ...) SingleResult
- func (tb *Table) HasIndexByName(ctx context.Context, name string) (bool, error)
- func (tb *Table) Indexes() *IndexView
- func (tb *Table) Insert(ctx context.Context, src interface{}, opts ...*options.InsertOptions) (sql.Result, error)
- func (tb *Table) InsertOne(ctx context.Context, src interface{}, opts ...*options.InsertOneOptions) (sql.Result, error)
- func (tb *Table) ListColumns(ctx context.Context) ([]Column, error)
- func (tb *Table) ListIndexes(ctx context.Context) ([]Index, error)
- func (tb *Table) Migrate(ctx context.Context, entity interface{}) error
- func (tb *Table) ModifyOne(ctx context.Context, update interface{}, opts ...*options.ModifyOneOptions) error
- func (tb Table) MustMigrate(ctx context.Context, entity interface{})
- func (tb *Table) MustUnsafeMigrate(ctx context.Context, entity interface{})
- func (tb *Table) Paginate(ctx context.Context, act actions.PaginateStatement, ...) (*Paginator, error)
- func (tb *Table) Rename(ctx context.Context, name string) error
- func (tb *Table) Replace(ctx context.Context, fields []string, query *sql.SelectStmt) error
- func (tb *Table) ReplaceOne(ctx context.Context, src interface{}, opts ...*options.InsertOneOptions) (sql.Result, error)
- func (tb *Table) Truncate(ctx context.Context) (err error)
- func (tb *Table) UnsafeMigrate(ctx context.Context, entity interface{}) error
- func (tb *Table) Update(ctx context.Context, act actions.UpdateStatement, ...) (int64, error)
- func (tb *Table) UpdateOne(ctx context.Context, act actions.UpdateOneStatement, ...) (int64, error)
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoValueUpdate = errors.New("sqlike: no value to update") // ErrInvalidInput : ErrInvalidInput = errors.New("sqlike: invalid input <nil>") // ErrUnaddressableEntity : ErrUnaddressableEntity = errors.New("sqlike: unaddressable entity") // ErrNilEntity : ErrNilEntity = errors.New("sqlike: entity is <nil>") // ErrNoColumn : ErrNoColumn = errors.New("sqlike: no columns to create index") )
errors : common error of sqlike
var EOF = io.EOF
EOF : is an alias for end of file
var ErrEmptyFields = errors.New("empty fields")
ErrEmptyFields :
var ErrExpectedStruct = errors.New("expected struct as a source")
ErrExpectedStruct :
var ErrInvalidCursor = errors.New("sqlike: invalid cursor")
ErrInvalidCursor :
var ErrNoRecordAffected = errors.New("no record affected")
ErrNoRecordAffected :
var ErrNoRows = sql.ErrNoRows
ErrNoRows : is an alias for no record found
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { *DriverInfo *sql.DB // contains filtered or unexported fields }
Client : sqlike client is a client embedded with *sql.DB, so you may use any apis of *sql.DB
func Connect ¶
func Connect(ctx context.Context, driver string, opt *options.ConnectOptions) (client *Client, err error)
Connect : connect and ping the sql server, throw error when unable to ping
func MustConnect ¶
MustConnect will panic if cannot connect to sql server
func MustConnectDB ¶ added in v1.1.0
MustConnectDB :
func Open ¶
func Open(ctx context.Context, driver string, opt *options.ConnectOptions) (client *Client, err error)
Open : open connection to sql server with connection string
func (*Client) CreateDatabase ¶
CreateDatabase : create database with name
func (*Client) Database ¶
Database : this api will execute `USE database`, which will point your current connection to selected database
func (*Client) DropDatabase ¶
DropDatabase : drop the selected database
func (*Client) ListDatabases ¶
ListDatabases : list all the database on current connection
func (*Client) SetCodec ¶ added in v1.0.2
SetCodec : Codec is a component which handling the : 1. encoding between input data and driver.Valuer 2. decoding between output data and sql.Scanner
func (*Client) SetLogger ¶
SetLogger : this is to set the logger for debugging, it will panic if the logger input is nil
func (*Client) SetPrimaryKey ¶
SetPrimaryKey : this will set a default primary key for subsequent operation such as Insert, InsertOne, ModifyOne
func (*Client) SetStructMapper ¶ added in v1.1.1
func (c *Client) SetStructMapper(mapper reflext.StructMapper) *Client
SetStructMapper : StructMapper is a mapper to reflect a struct on runtime and provide struct info
type Column ¶
type Column struct { // column name Name string // column position in sql database Position int // column data type with precision or size, eg. VARCHAR(20) Type string // column data type without precision and size, eg. VARCHAR DataType string // whether column is nullable or not IsNullable types.Boolean // default value of the column DefaultValue *string // text character set encoding Charset *string // text collation for sorting Collation *string // column comment Comment string // extra information Extra string }
Column : contains sql column information
type ColumnView ¶
type ColumnView struct {
// contains filtered or unexported fields
}
ColumnView :
func (*ColumnView) DropOne ¶
func (cv *ColumnView) DropOne(ctx context.Context, name string) error
DropOne : drop column with name
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database :
func (*Database) BeginTransaction ¶
func (db *Database) BeginTransaction(ctx context.Context, opts ...*sql.TxOptions) (*Transaction, error)
BeginTransaction :
func (*Database) BuildIndexes ¶
BuildIndexes :
func (*Database) RunInTransaction ¶
func (db *Database) RunInTransaction(ctx context.Context, cb txCallback, opts ...*options.TransactionOptions) error
RunInTransaction :
type IndexView ¶
type IndexView struct {
// contains filtered or unexported fields
}
IndexView :
func (*IndexView) CreateIfNotExists ¶
CreateIfNotExists :
func (*IndexView) CreateOneIfNotExists ¶
CreateOneIfNotExists :
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result :
func (*Result) ColumnTypes ¶
func (r *Result) ColumnTypes() ([]*sql.ColumnType, error)
ColumnTypes :
func (*Result) Decode ¶
Decode will decode the current document into val, this will only accepting pointer of struct as an input.
func (*Result) NextResultSet ¶ added in v1.1.0
NextResultSet :
type Resulter ¶ added in v1.1.0
type Resulter interface { Scan(dests ...interface{}) error Columns() []string Next() bool NextResultSet() bool Close() error }
Resulter :
type SessionContext ¶
type SessionContext interface { context.Context Table(name string) *Table QueryStmt(ctx context.Context, query interface{}) (*Result, error) }
SessionContext :
type SingleResult ¶
type SingleResult interface { Scan(dest ...interface{}) error Decode(dest interface{}) error Columns() []string ColumnTypes() ([]*sql.ColumnType, error) Error() error }
SingleResult : single result is an interface implementing apis as similar as driver.Result
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table :
func (*Table) Delete ¶
func (tb *Table) Delete(ctx context.Context, act actions.DeleteStatement, opts ...*options.DeleteOptions) (int64, error)
Delete : delete multiple record on the table using where clause. If you didn't provided any where clause, it will throw error. For multiple record deletion without where clause, you should use `Truncate` instead.
func (*Table) DeleteOne ¶
func (tb *Table) DeleteOne(ctx context.Context, act actions.DeleteOneStatement, opts ...*options.DeleteOneOptions) (int64, error)
DeleteOne : delete single record on the table using where clause.
func (*Table) DestroyOne ¶
func (tb *Table) DestroyOne(ctx context.Context, delete interface{}, opts ...*options.DestroyOneOptions) error
DestroyOne : hard delete a record on the table using primary key. You should alway have primary key defined in your struct in order to use this api.
func (Table) DropIfExists ¶
DropIfExists : will drop the table only if it exists.
func (*Table) Find ¶
func (tb *Table) Find(ctx context.Context, act actions.SelectStatement, opts ...*options.FindOptions) (*Result, error)
Find : find multiple records on the table.
func (*Table) FindOne ¶
func (tb *Table) FindOne(ctx context.Context, act actions.SelectOneStatement, opts ...*options.FindOneOptions) SingleResult
FindOne : find single record on the table, you should alway check the return error to ensure it have result return.
func (*Table) HasIndexByName ¶
HasIndexByName :
func (*Table) Insert ¶
func (tb *Table) Insert(ctx context.Context, src interface{}, opts ...*options.InsertOptions) (sql.Result, error)
Insert : insert multiple records. You should always pass in the address of the slice.
func (*Table) InsertOne ¶
func (tb *Table) InsertOne(ctx context.Context, src interface{}, opts ...*options.InsertOneOptions) (sql.Result, error)
InsertOne : insert single record. You should always pass in the address of input.
func (*Table) ListColumns ¶
ListColumns : list all the column of the table.
func (*Table) ListIndexes ¶
ListIndexes : list all the index of the table.
func (*Table) Migrate ¶
Migrate : migrate will create a new table follows by the definition of struct tag, alter when the table already exists
func (*Table) ModifyOne ¶
func (tb *Table) ModifyOne(ctx context.Context, update interface{}, opts ...*options.ModifyOneOptions) error
ModifyOne :
func (Table) MustMigrate ¶
MustMigrate : this will ensure the migrate is complete, otherwise it will panic
func (*Table) MustUnsafeMigrate ¶
MustUnsafeMigrate : this will panic if it get error on unsafe migrate
func (*Table) Paginate ¶
func (tb *Table) Paginate(ctx context.Context, act actions.PaginateStatement, opts ...*options.PaginateOptions) (*Paginator, error)
Paginate :
func (*Table) ReplaceOne ¶
func (tb *Table) ReplaceOne(ctx context.Context, src interface{}, opts ...*options.InsertOneOptions) (sql.Result, error)
ReplaceOne :
func (*Table) UnsafeMigrate ¶
UnsafeMigrate : unsafe migration will delete non-exist index and columns, beware when you use this
type Transaction ¶
type Transaction struct { // transaction context context.Context // contains filtered or unexported fields }
Transaction :
func (*Transaction) CommitTransaction ¶
func (tx *Transaction) CommitTransaction() error
CommitTransaction :
func (*Transaction) QueryStmt ¶
func (tx *Transaction) QueryStmt(ctx context.Context, query interface{}) (*Result, error)
QueryStmt : support complex and advance query statement
func (*Transaction) RollbackTransaction ¶
func (tx *Transaction) RollbackTransaction() error
RollbackTransaction :