mysql

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

deprecated: use middleware/dbquery package instead

Index

Constants

View Source
const (

	// misoconfig-prop: enable MySQL client | false
	PropMySQLEnabled = "mysql.enabled"

	// misoconfig-prop: username | root
	PropMySQLUser = "mysql.user"

	// misoconfig-prop: password
	PropMySQLPassword = "mysql.password"

	// misoconfig-prop: database
	PropMySQLSchema = "mysql.database"

	// misoconfig-prop: host | localhost
	PropMySQLHost = "mysql.host"

	// misoconfig-prop: port | 3306
	PropMySQLPort = "mysql.port"

	// misoconfig-prop: connection parameters (slices of strings) | `[]string{"charset=utf8mb4", "parseTime=True", "loc=Local", "readTimeout=30s", "writeTimeout=30s", "timeout=3s"}`
	PropMySQLConnParam = "mysql.connection.parameters"

	// misoconfig-prop: connection lifetime in minutes (hikari recommends 1800000, so we do the same thing) | 30
	PropMySQLConnLifetime = "mysql.connection.lifetime"

	// misoconfig-prop: max number of open connections | 10
	PropMySQLMaxOpenConns = "mysql.connection.open.max"

	// misoconfig-prop: max number of idle connections | 10
	PropMySQLMaxIdleConns = "mysql.connection.idle.max"
)

misoconfig-section: MySQL Configuration

Variables

View Source
var (
	NewQuery = dbquery.NewQuery
)

Functions

func AddMySQLBootstrapCallback

func AddMySQLBootstrapCallback(cbk MySQLBootstrapCallback)

func GetMySQL

func GetMySQL() *gorm.DB

Get MySQL Connection.

func InitMySQL

func InitMySQL(rail miso.Rail, p MySQLConnParam) error

Init Handle to the database

If mysql client has been initialized, current func call will be ignored.

func InitMySQLFromProp

func InitMySQLFromProp(rail miso.Rail) error

Init connection to mysql

If mysql client has been initialized, current func call will be ignored.

This func looks for following props:

"mysql.user"
"mysql.password"
"mysql.database"
"mysql.host"
"mysql.port"
"mysql.connection.parameters"

func IsMySQLInitialized

func IsMySQLInitialized() bool

Check whether mysql client is initialized

func NewMySQLConn

func NewMySQLConn(rail miso.Rail, p MySQLConnParam) (*gorm.DB, error)

Create new MySQL connection

func QueryPage

func QueryPage[Res any](rail miso.Rail, tx *gorm.DB, p QueryPageParam[Res]) (miso.PageRes[Res], error)

Execute paged query.

COUNT query is called first, if none is found (i.e., COUNT(...) == 0), this method will not call the actual SELECT query to avoid unnecessary performance lost.

Types

type ChainedPageQuery added in v0.1.10

type ChainedPageQuery = dbquery.ChainedPageQuery

type MySQLBootstrapCallback

type MySQLBootstrapCallback func(rail miso.Rail, db *gorm.DB) error

type MySQLConnParam

type MySQLConnParam struct {
	User            string
	Password        string
	Schema          string
	Host            string
	Port            int
	ConnParam       string
	MaxConnLifetime time.Duration
	MaxOpenConns    int
	MaxIdleConns    int
}

type Nilable added in v0.1.13

type Nilable = dbquery.Nilable

type NilableValue added in v0.1.13

type NilableValue = dbquery.NilableValue

type PageQuery added in v0.1.10

type PageQuery[V any] struct {
	// contains filtered or unexported fields
}

Create param for page query.

TODO: make this an alias of type dbquery.PageQuery in go1.24 (when generic type alias becomes available).

func NewPagedQuery added in v0.1.10

func NewPagedQuery[V any](db *gorm.DB) *PageQuery[V]

func (*PageQuery[V]) Scan added in v0.1.10

func (pq *PageQuery[V]) Scan(rail miso.Rail, reqPage miso.Paging) (miso.PageRes[V], error)

func (*PageQuery[V]) Transform added in v0.1.10

func (pq *PageQuery[V]) Transform(t util.Transform[V]) *PageQuery[V]

func (*PageQuery[V]) TransformAsync added in v0.1.16

func (pq *PageQuery[V]) TransformAsync(t util.TransformAsync[V]) *PageQuery[V]

func (*PageQuery[V]) WithBaseQuery added in v0.1.10

func (pq *PageQuery[V]) WithBaseQuery(qry ChainedPageQuery) *PageQuery[V]

func (*PageQuery[V]) WithSelectQuery added in v0.1.10

func (pq *PageQuery[V]) WithSelectQuery(qry ChainedPageQuery) *PageQuery[V]

type PageQueryBuilder

type PageQueryBuilder func(tx *gorm.DB) *gorm.DB

type Query added in v0.1.6

type Query = dbquery.Query

type QueryPageParam

type QueryPageParam[V any] struct {
	// contains filtered or unexported fields
}

Create param for page query.

func NewPageQuery

func NewPageQuery[Res any]() *QueryPageParam[Res]

func (*QueryPageParam[V]) Exec

func (q *QueryPageParam[V]) Exec(rail miso.Rail, tx *gorm.DB) (miso.PageRes[V], error)

Execute paging query

func (*QueryPageParam[V]) ForEach

func (q *QueryPageParam[V]) ForEach(t util.Transform[V]) *QueryPageParam[V]

func (*QueryPageParam[V]) WithBaseQuery

func (q *QueryPageParam[V]) WithBaseQuery(qry PageQueryBuilder) *QueryPageParam[V]

func (*QueryPageParam[V]) WithPage

func (q *QueryPageParam[V]) WithPage(p miso.Paging) *QueryPageParam[V]

func (*QueryPageParam[V]) WithSelectQuery

func (q *QueryPageParam[V]) WithSelectQuery(qry PageQueryBuilder) *QueryPageParam[V]

Jump to

Keyboard shortcuts

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