Documentation ¶
Overview ¶
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.
Index ¶
- Constants
- Variables
- func BuildNamedColumnsValuesBatch(req interface{}) map[string]interface{}
- func BuildNamedInsertSql(table string, cols []string, batch int) string
- func CloseDB() error
- func CloseTheDB(conf DBConfig) error
- func ConditionWithEqualAnd(condFields ...string) string
- func ExecContext(ctx context.Context, query string, arg interface{}, tx *sqlx.Tx, db *sqlx.DB) (rows int64, err error)
- func GetCountContext(ctx context.Context, query string, arg interface{}, db *sqlx.DB) (count uint32, err error)
- func GetDB() *sqlx.DB
- func GetTheDB(conf DBConfig) (*sqlx.DB, error)
- func InCondition(cond string, values ...string) string
- func JoinNamedColumnsValues(cols ...string) string
- func JoinNamedColumnsValuesBatch(cols []string, batch int) string
- func JoinNamedColumnsValuesWithOperator(cmp SqlCompare, oper SqlOperator, cols ...string) string
- func NamedExecContext(ctx context.Context, query string, arg interface{}, tx *sqlx.Tx, db *sqlx.DB) (sql.Result, error)
- func NamedInCondition(oper SqlOperator, cols []string, arg interface{}) (string, error)
- func NonzeroCondition(cmp SqlCompare, oper SqlOperator, arg interface{}) string
- func NonzeroFields(arg interface{}) []string
- func OrderCondition(orders map[string]bool) string
- func PrepareNamedContext(ctx context.Context, query string, tx *sqlx.Tx, db *sqlx.DB) (*sqlx.NamedStmt, error)
- func SelectNamedContext(ctx context.Context, query string, arg interface{}, dest interface{}, ...) (err error)
- func TransferToNamedColumnsValuesBatch(req []map[string]interface{}) map[string]interface{}
- func TxPipelined(ctx context.Context, db *sqlx.DB, fn func(*sqlx.Tx) error) (err error)
- type CompletedConfig
- type Config
- type ConfigOption
- type ConfigOptionFunc
- type DB
- type DBConfig
- type DBOption
- func WithConnMaxLifetime(connMaxLifetime time.Duration) DBOption
- func WithDialTimeout(dialTimeout time.Duration) DBOption
- func WithInterpolateParams(enabled bool) DBOption
- func WithMaxConnections(maxConns int) DBOption
- func WithMaxIdleConnections(maxIdleConns int) DBOption
- func WithReadTimeout(readTimeout time.Duration) DBOption
- func WithWriteTimeout(writeTimeout time.Duration) DBOption
- type DBOptionFunc
- type EmptyConfigOption
- type EmptyDBOption
- type Mysql
- func (*Mysql) Descriptor() ([]byte, []int)deprecated
- func (x *Mysql) GetAddress() string
- func (x *Mysql) GetDbName() string
- func (x *Mysql) GetDialTimeout() *duration.Duration
- func (x *Mysql) GetEnabled() bool
- func (x *Mysql) GetFailAfterDuration() *duration.Duration
- func (x *Mysql) GetInterpolateParams() bool
- func (x *Mysql) GetMaxConnections() int32
- func (x *Mysql) GetMaxIdleConnections() int32
- func (x *Mysql) GetMaxLifeTime() *duration.Duration
- func (x *Mysql) GetMaxWaitDuration() *duration.Duration
- func (x *Mysql) GetPassword() string
- func (x *Mysql) GetReadTimeout() *duration.Duration
- func (x *Mysql) GetUsername() string
- func (x *Mysql) GetWriteTimeout() *duration.Duration
- func (*Mysql) ProtoMessage()
- func (x *Mysql) ProtoReflect() protoreflect.Message
- func (x *Mysql) Reset()
- func (x *Mysql) String() string
- type SQLDB
- type SqlCompare
- type SqlOperator
- type TxDao
Constants ¶
const ( DefaultMaxConns = 100 DefaultMaxIdleConns = 10 )
Default values for Mysql.
Variables ¶
var File_pkg_database_mysql_mysql_proto protoreflect.FileDescriptor
Functions ¶
func BuildNamedColumnsValuesBatch ¶ added in v0.0.121
func BuildNamedColumnsValuesBatch(req interface{}) map[string]interface{}
req is slice of struct or pointer struct
func BuildNamedInsertSql ¶ added in v0.0.121
func CloseTheDB ¶ added in v0.0.14
func ConditionWithEqualAnd ¶ added in v0.0.55
func ExecContext ¶ added in v0.0.34
func GetCountContext ¶ added in v0.0.54
func InCondition ¶ added in v0.0.55
func JoinNamedColumnsValues ¶ added in v0.0.33
JoinNamedColumnsValues foo=:foo,bar=:bar, for update set
func JoinNamedColumnsValuesBatch ¶ added in v0.0.121
used for batch insert (
:group_id_1, :page_id_1, :fea_id_1, :entity_id_1, :feature0_1, :feature1_1, :extend_info_1 ),
(
:group_id_2, :page_id_2, :fea_id_2, :entity_id_2, :feature0_2, :feature1_2, :extend_info_2 )
func JoinNamedColumnsValuesWithOperator ¶ added in v0.0.33
func JoinNamedColumnsValuesWithOperator(cmp SqlCompare, oper SqlOperator, cols ...string) string
JoinNamedColumnsValuesWithOperator "foo=:foo AND bar=:bar" , for where condition
func NamedExecContext ¶ added in v0.0.54
func NamedInCondition ¶ added in v0.0.53
func NamedInCondition(oper SqlOperator, cols []string, arg interface{}) (string, error)
func NonzeroCondition ¶ added in v0.0.55
func NonzeroCondition(cmp SqlCompare, oper SqlOperator, arg interface{}) string
"foo=:foo AND bar=:bar"
func NonzeroFields ¶ added in v0.0.55
func NonzeroFields(arg interface{}) []string
func OrderCondition ¶ added in v0.0.55
"ORDER BY create_time DESC, id DESC"
func PrepareNamedContext ¶ added in v0.0.54
func SelectNamedContext ¶ added in v0.0.55
func SelectNamedContext( ctx context.Context, query string, arg interface{}, dest interface{}, db *sqlx.DB, ) (err error)
pointer struct model for dest
func TransferToNamedColumnsValuesBatch ¶ added in v0.0.121
used for batch insert
Types ¶
type CompletedConfig ¶ added in v0.0.32
type CompletedConfig struct {
// contains filtered or unexported fields
}
type Config ¶ added in v0.0.32
type Config struct { Proto Mysql // contains filtered or unexported fields }
func NewConfig ¶ added in v0.0.32
func NewConfig(options ...ConfigOption) *Config
func (*Config) ApplyOptions ¶ added in v0.0.32
func (o *Config) ApplyOptions(options ...ConfigOption) *Config
func (*Config) Complete ¶ added in v0.0.32
func (c *Config) Complete() CompletedConfig
Complete set default ServerRunOptions.
type ConfigOption ¶ added in v0.0.32
type ConfigOption interface {
// contains filtered or unexported methods
}
A ConfigOption sets options.
func WithViper ¶ added in v0.0.32
func WithViper(v *viper.Viper) ConfigOption
type ConfigOptionFunc ¶ added in v0.0.32
type ConfigOptionFunc func(*Config)
ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.
type DB ¶
type DB struct { //DSN string Conf DBConfig // contains filtered or unexported fields }
func (*DB) ApplyOptions ¶
type DBOption ¶
type DBOption interface {
// contains filtered or unexported methods
}
A DBOption sets options.
func WithConnMaxLifetime ¶ added in v0.0.32
func WithDialTimeout ¶ added in v0.0.32
func WithInterpolateParams ¶ added in v0.0.59
func WithMaxConnections ¶ added in v0.0.32
func WithMaxIdleConnections ¶ added in v0.0.32
func WithReadTimeout ¶ added in v0.0.32
func WithWriteTimeout ¶ added in v0.0.32
type DBOptionFunc ¶
type DBOptionFunc func(*DB)
DBOptionFunc wraps a function that modifies DB into an implementation of the DBOption interface.
type EmptyConfigOption ¶ added in v0.0.32
type EmptyConfigOption struct{}
EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type EmptyDBOption ¶
type EmptyDBOption struct{}
EmptyDBUrlOption does not alter the DBuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type Mysql ¶ added in v0.0.32
type Mysql struct { Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"` Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` DbName string `protobuf:"bytes,5,opt,name=db_name,json=dbName,proto3" json:"db_name,omitempty"` MaxConnections int32 `protobuf:"varint,6,opt,name=max_connections,json=maxConnections,proto3" json:"max_connections,omitempty"` MaxIdleConnections int32 `protobuf:"varint,7,opt,name=max_idle_connections,json=maxIdleConnections,proto3" json:"max_idle_connections,omitempty"` DialTimeout *duration.Duration `protobuf:"bytes,8,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"` ReadTimeout *duration.Duration `protobuf:"bytes,9,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` // https://github.com/go-sql-driver/mysql#writetimeout WriteTimeout *duration.Duration `protobuf:"bytes,10,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"` MaxLifeTime *duration.Duration `protobuf:"bytes,11,opt,name=max_life_time,json=maxLifeTime,proto3" json:"max_life_time,omitempty"` MaxWaitDuration *duration.Duration `protobuf:"bytes,12,opt,name=max_wait_duration,json=maxWaitDuration,proto3" json:"max_wait_duration,omitempty"` FailAfterDuration *duration.Duration `protobuf:"bytes,13,opt,name=fail_after_duration,json=failAfterDuration,proto3" json:"fail_after_duration,omitempty"` InterpolateParams bool `protobuf:"varint,14,opt,name=interpolate_params,json=interpolateParams,proto3" json:"interpolate_params,omitempty"` // contains filtered or unexported fields }
func (*Mysql) Descriptor
deprecated
added in
v0.0.32
func (*Mysql) GetAddress ¶ added in v0.0.32
func (*Mysql) GetDialTimeout ¶ added in v0.0.32
func (*Mysql) GetEnabled ¶ added in v0.0.32
func (*Mysql) GetFailAfterDuration ¶ added in v0.0.32
func (*Mysql) GetInterpolateParams ¶ added in v0.0.59
func (*Mysql) GetMaxConnections ¶ added in v0.0.32
func (*Mysql) GetMaxIdleConnections ¶ added in v0.0.32
func (*Mysql) GetMaxLifeTime ¶ added in v0.0.32
func (*Mysql) GetMaxWaitDuration ¶ added in v0.0.32
func (*Mysql) GetPassword ¶ added in v0.0.32
func (*Mysql) GetReadTimeout ¶ added in v0.0.32
func (*Mysql) GetUsername ¶ added in v0.0.32
func (*Mysql) GetWriteTimeout ¶ added in v0.0.32
func (*Mysql) ProtoMessage ¶ added in v0.0.32
func (*Mysql) ProtoMessage()
func (*Mysql) ProtoReflect ¶ added in v0.0.32
func (x *Mysql) ProtoReflect() protoreflect.Message
type SqlCompare ¶ added in v0.0.33
type SqlCompare string
const ( SqlCompareEqual SqlCompare = "=" SqlCompareNotEqual SqlCompare = "!=" SqlCompareGreater SqlCompare = ">" SqlCompareLessThan SqlCompare = "<" SqlCompareGreatEqual SqlCompare = ">=" SqlCompareLessEqual SqlCompare = "<=" SqlCompareLike SqlCompare = "LIKE" SqlCompareIn SqlCompare = "IN" )
type SqlOperator ¶ added in v0.0.33
type SqlOperator string
const ( SqlOperatorAnd SqlOperator = "AND" SqlOperatorOr SqlOperator = "OR" SqlOperatorNot SqlOperator = "NOT" )