mysql

package
v0.0.0-...-0eaed87 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatabaseMigration

func DatabaseMigration(cfg *Config)

DatabaseMigration ...

func Init

func Init() (*sqlx.DB, error)

init create new session maria db

Types

type Adapter

type Adapter interface {
	QueryRow(query string, args ...interface{}) sql.Result
	// QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row
	// QueryRows(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error)
	Fetch(dst interface{}, query string, args ...interface{}) error
	FetchRow(dst interface{}, query string, args ...interface{}) error
	// BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	// Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	Ping(ctx context.Context) error
	Query(query string, args ...interface{}) (*sql.Rows, error)
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	QueryRowx(query string, args ...interface{}) *sqlx.Row
	UpdateQuery(table string, data map[string]interface{}) string
}

type Config

type Config struct {
	Host         string
	Port         int
	User         string
	Password     string
	Name         string
	Timeout      time.Duration
	Charset      string
	MaxOpenConns int
	MaxIdleConns int
	MaxLifetime  time.Duration
	Type         string
}

type MySqlDB

type MySqlDB struct {
	DB      *sqlx.DB
	Queryer sqlx.Queryer
	Logger  *logrus.Logger
}

func NewMySQL

func NewMySQL(db *sqlx.DB) *MySqlDB

NewMaria initialize single mysql db

func (*MySqlDB) Fetch

func (d *MySqlDB) Fetch(dst interface{}, query string, args ...interface{}) error

Fetch select multiple rows of database will cast data to struct passing by parameter

func (*MySqlDB) FetchRow

func (d *MySqlDB) FetchRow(dst interface{}, query string, args ...interface{}) error

FetchRow fetching one row database will cast data to struct passing by parameter

func (*MySqlDB) Ping

func (d *MySqlDB) Ping(ctx context.Context) error

Ping check database connectivity

func (*MySqlDB) Query

func (p *MySqlDB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query sqlx property

func (*MySqlDB) QueryRow

func (p *MySqlDB) QueryRow(query string, args ...interface{}) sql.Result

Create sqlx property

func (*MySqlDB) QueryRowx

func (p *MySqlDB) QueryRowx(query string, args ...interface{}) *sqlx.Row

QueryRowx sqlx property

func (*MySqlDB) Queryx

func (p *MySqlDB) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

Queryx sqlx property

type NewQueryBuilder

type NewQueryBuilder struct {
	FullQuery string
}

func (*NewQueryBuilder) Create

func (qb *NewQueryBuilder) Create(table string, field string) *NewQueryBuilder

table: users field: "name,created_at,updated_at" Create represents "insert into users (name,created_at,updated_at) values (?,?,?)"

func (*NewQueryBuilder) Delete

func (qb *NewQueryBuilder) Delete(table string, field string, value interface{}) *NewQueryBuilder

func (*NewQueryBuilder) From

func (qb *NewQueryBuilder) From(table string) *NewQueryBuilder

func (*NewQueryBuilder) JoinTable

func (qb *NewQueryBuilder) JoinTable(table string, arg string) *NewQueryBuilder

arg: users.id,address_users.id onExpression: users.id = address_users.id JoinTable represents "Join table on users.id = address_users.id"

func (*NewQueryBuilder) Limit

func (qb *NewQueryBuilder) Limit(numb int) *NewQueryBuilder

func (*NewQueryBuilder) Offset

func (qb *NewQueryBuilder) Offset(numb int) *NewQueryBuilder

func (*NewQueryBuilder) OperatorEqual

func (qb *NewQueryBuilder) OperatorEqual(field string, value interface{}) *NewQueryBuilder

field: email OperatorEqual represents "where email = value"

func (*NewQueryBuilder) OperatorIN

func (qb *NewQueryBuilder) OperatorIN(field string, value string) *NewQueryBuilder

value: ari,budiman field: name OperatorORLike represents "where name in["ari","budiman"]"

func (*NewQueryBuilder) OperatorLike

func (qb *NewQueryBuilder) OperatorLike(field string, value string) *NewQueryBuilder

field: email OperatorLike represents "where email LIKE %value%"

func (*NewQueryBuilder) OperatorORLike

func (qb *NewQueryBuilder) OperatorORLike(field string, value string) *NewQueryBuilder

field: name,email OperatorORLike represents "where name LIKE "%value%" OR email LIKE "%value%""

func (*NewQueryBuilder) OrderBy

func (qb *NewQueryBuilder) OrderBy(array []string) *NewQueryBuilder

func (*NewQueryBuilder) Select

func (qb *NewQueryBuilder) Select(field string) *NewQueryBuilder

func (*NewQueryBuilder) Update

func (qb *NewQueryBuilder) Update(table string, data map[string]interface{}) *NewQueryBuilder

UpdateQuery validate update query string

Jump to

Keyboard shortcuts

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