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) SetLogger(logger db.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) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (db *Database) Name() string
- func (db *Database) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (db *Database) QueryRow(ctx context.Context, query string, args ...any) *Row
- func (db *Database) QueryStmt(ctx context.Context, query any) (*Rows, 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 []sql.Index) error
- func (idv *IndexView) CreateIfNotExists(ctx context.Context, idxs []sql.Index) error
- func (idv *IndexView) CreateOne(ctx context.Context, idx sql.Index) error
- func (idv *IndexView) CreateOneIfNotExists(ctx context.Context, idx sql.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
- type Row
- type Rows
- func (r *Rows) All(results any) error
- func (r *Rows) Close() error
- func (r *Rows) ColumnTypes() ([]*sql.ColumnType, error)
- func (r *Rows) Columns() []string
- func (r *Rows) Decode(dst any) error
- func (r *Rows) Error() error
- func (r *Rows) Next() bool
- func (r *Rows) NextResultSet() bool
- func (r *Rows) Scan(dests ...any) error
- func (r *Rows) ScanSlice(results any) error
- 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 any, 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) (*Rows, 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 any, opts ...*options.InsertOptions) (sql.Result, error)
- func (tb *Table) InsertOne(ctx context.Context, src any, 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 any) error
- func (tb *Table) ModifyOne(ctx context.Context, update any, opts ...*options.ModifyOneOptions) (int64, error)
- func (tb Table) MustMigrate(ctx context.Context, entity any)
- func (tb *Table) MustUnsafeMigrate(ctx context.Context, entity any)
- 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 any, opts ...*options.InsertOneOptions) (sql.Result, error)
- func (tb *Table) Truncate(ctx context.Context) (err error)
- func (tb *Table) UnsafeDrop(ctx context.Context) (err error)
- func (tb *Table) UnsafeMigrate(ctx context.Context, entity any) 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") // ErrNestedTransaction : ErrNestedTransaction = errors.New("sqlike: nested transaction") // ErrNoRecordAffected : ErrNoRecordAffected = errors.New("sqlike: no record affected") // ErrExpectedStruct : ErrExpectedStruct = errors.New("sqlike: expected struct as a source") // ErrEmptyFields : ErrEmptyFields = errors.New("sqlike: empty fields") // ErrInvalidCursor : ErrInvalidCursor = errors.New("sqlike: invalid cursor") )
errors : common error of sqlike
var EOF = io.EOF
EOF : is an alias for end of file
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 ΒΆ
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) 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 ΒΆ
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 DriverInfo ΒΆ
type DriverInfo struct {
// contains filtered or unexported fields
}
DriverInfo :
type IndexView ΒΆ
type IndexView struct {
// contains filtered or unexported fields
}
IndexView :
func (*IndexView) CreateIfNotExists ΒΆ
CreateIfNotExists :
func (*IndexView) CreateOneIfNotExists ΒΆ
CreateOneIfNotExists :
type Paginator ΒΆ
type Paginator struct {
// contains filtered or unexported fields
}
Paginator :
type Result ΒΆ
type Result interface { Scan(dests ...any) error Columns() []string Next() bool NextResultSet() bool Close() error }
Result :
type Rows ΒΆ
type Rows struct {
// contains filtered or unexported fields
}
Rows :
func (*Rows) Decode ΒΆ
Decode will decode the current document into val, this will only accepting pointer of struct as an input.
type SingleResult ΒΆ
type SingleResult interface { Scan(dest ...any) error Decode(dest any) 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 any, 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, ) (*Rows, 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 any, 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 any, 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 any, opts ...*options.ModifyOneOptions, ) (int64, 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 any, opts ...*options.InsertOneOptions, ) (sql.Result, error)
ReplaceOne :
func (*Table) UnsafeDrop ΒΆ
UnsafeDrop : drop the table without table is exists and foreign key constraint error
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) Commit ΒΆ
func (tx *Transaction) Commit() error
Commit : Commit commits the transaction.
func (*Transaction) Rollback ΒΆ
func (tx *Transaction) Rollback() error
Rollback : Rollback aborts the transaction.