Documentation
¶
Overview ¶
deprecated: use middleware/dbquery package instead
Index ¶
- Constants
- Variables
- func AddMySQLBootstrapCallback(cbk MySQLBootstrapCallback)
- func GetMySQL() *gorm.DB
- func InitMySQL(rail miso.Rail, p MySQLConnParam) error
- func InitMySQLFromProp(rail miso.Rail) error
- func IsMySQLInitialized() bool
- func NewMySQLConn(rail miso.Rail, p MySQLConnParam) (*gorm.DB, error)
- func QueryPage[Res any](rail miso.Rail, tx *gorm.DB, p QueryPageParam[Res]) (miso.PageRes[Res], error)
- type ChainedPageQuery
- type MySQLBootstrapCallback
- type MySQLConnParam
- type Nilable
- type NilableValue
- type PageQuery
- func (pq *PageQuery[V]) Scan(rail miso.Rail, reqPage miso.Paging) (miso.PageRes[V], error)
- func (pq *PageQuery[V]) Transform(t util.Transform[V]) *PageQuery[V]
- func (pq *PageQuery[V]) TransformAsync(t util.TransformAsync[V]) *PageQuery[V]
- func (pq *PageQuery[V]) WithBaseQuery(qry ChainedPageQuery) *PageQuery[V]
- func (pq *PageQuery[V]) WithSelectQuery(qry ChainedPageQuery) *PageQuery[V]
- type PageQueryBuilder
- type Query
- type QueryPageParam
- func (q *QueryPageParam[V]) Exec(rail miso.Rail, tx *gorm.DB) (miso.PageRes[V], error)
- func (q *QueryPageParam[V]) ForEach(t util.Transform[V]) *QueryPageParam[V]
- func (q *QueryPageParam[V]) WithBaseQuery(qry PageQueryBuilder) *QueryPageParam[V]
- func (q *QueryPageParam[V]) WithPage(p miso.Paging) *QueryPageParam[V]
- func (q *QueryPageParam[V]) WithSelectQuery(qry PageQueryBuilder) *QueryPageParam[V]
Constants ¶
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 ¶
var (
NewQuery = dbquery.NewQuery
)
Functions ¶
func AddMySQLBootstrapCallback ¶
func AddMySQLBootstrapCallback(cbk MySQLBootstrapCallback)
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 ¶
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 NewMySQLConn ¶
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 MySQLConnParam ¶
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 (*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 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]) 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]