Documentation
¶
Index ¶
- Variables
- func SetManual(man map[string]string) map[string]string
- type Database
- type Embedded
- type EmbeddedOptions
- type Encoder
- type Encoding
- type Messages
- type Mongo
- type MongoIndex
- type MongoODM
- type MongoProviderConfig
- type MongoTransaction
- type ORM
- type OrmModel
- type Provider
- type Redis
- type RedisProviderConfig
- type SQL
- type SQLConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigManual = map[string]string{
"config:autoReconnect": `auto reconnect database in first init`,
"config:startInterval": `first timeout duration after failed`,
"config:maxError": `how many reconnect before trigger error`,
"config:sql:name": `database config name, optional`,
"config:sql:enable": `enable sql database`,
"config:sql:host": `sql server address, must be valid rules hostname_rfc1123
ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
"config:sql:port": `sql server port number`,
"config:sql:username": `sql server username`,
"config:sql:password": `sql server password`,
"config:sql:database": `sql database name`,
"config:sql:options": `this option will be added after connection string`,
"config:sql:connection": `if this value not empty, another mysql parameter will be ignored.
use this, if you have a custom protocol connection.
like username:password@unix(/tmp/mysql.sock)/dbname.`,
"config:sql:dbPath": `sqlite database file location path`,
"config:redis:name": `database config name, optional`,
"config:redis:host": `redis server address, must be valid rules hostname_rfc1123
ex: localhost, 127.0.0.1, service.domain, 10.10.10.10, etc.`,
"config:redis:port": `redis server port number`,
"config:redis:password": `redis server password`,
"config:redis:pool": `number of redis pool`,
"config:mongo:name": `database config name, optional`,
}
View Source
var RecordNotFound = errors.New("record not found in database")
RecordNotFound - global error record not found type
Functions ¶
Types ¶
type Embedded ¶
type Embedded interface { DB() *nutsdb.DB Set(bucket string, key string, value interface{}, encoding Encoding) (err error) Get(bucket string, key string, value interface{}, encoding Encoding) (err error) Delete(bucket string, key string) (err error) GetAllKeys(bucket string) (keys []string, err error) }
type EmbeddedOptions ¶
type EmbeddedOptions struct {
Directory string
}
type Messages ¶
type Mongo ¶
type Mongo interface { Client() *mongo.Client Start() (err error) UseEncryption(encLib encryption.Encryption) Mongo ODM() MongoODM WithMonitor(enable bool) Mongo GetConfig() MongoProviderConfig }
type MongoIndex ¶
type MongoIndex struct { Collection string Field string Unique bool Compound bool PrimaryKey bool Desc bool ExpiredAfterSecond int32 }
MongoIndex - indexing mongodb
type MongoODM ¶
type MongoODM interface { Error() error Collection(model interface{}, name string) MongoODM NativeCollection() *mongo.Collection Index() MongoODM Create(ctx context.Context, data interface{}) *MongoTransaction Upsert(ctx context.Context, data interface{}, matchKey []string) *MongoTransaction Filter(filter map[string]interface{}) MongoODM Find(ctx context.Context, dest interface{}) *MongoTransaction FindRaw(ctx context.Context) (results []bson.Raw, cc *MongoTransaction) Drop(ctx context.Context) MongoODM Update(ctx context.Context, data map[string]interface{}) *MongoTransaction Delete(ctx context.Context) *MongoTransaction SetSort(sortBy string, desc bool) MongoODM SetLimit(limit int64) MongoODM SetSkip(skip int64) MongoODM Count(ctx context.Context) (res int64, err error) }
type MongoProviderConfig ¶
type MongoProviderConfig struct { Name string `yaml:"name" default:"" desc:"config:mongo:name"` Enable bool `yaml:"enable" default:"false" desc:"config:mongo:enable"` Uri string `yaml:"uri" default:"" desc:"config:mongo:uri"` Host string `yaml:"host" default:"127.0.0.1" desc:"config:mongo:host"` Port int `yaml:"port" default:"27017" desc:"config:mongo:port"` UserName string `yaml:"username" default:"root" desc:"config:mongo:username"` Password string `yaml:"password" default:"root" desc:"config:mongo:password"` Database string `yaml:"database" default:"sample_database" desc:"config:mongo:database"` Options string `yaml:"options" default:"" desc:"config:mongo:options"` TimeoutConnection int `yaml:"timeoutConnection" default:"5000" desc:"config:mongo:timeoutConnection"` AutoReconnect bool `yaml:"autoReconnect" default:"false" desc:"config:autoReconnect"` StartInterval int `yaml:"startInterval" default:"2" desc:"config:startInterval"` MaxError int `yaml:"maxError" default:"5" desc:"config:maxError"` }
MongoProviderConfig - Mongodb configuration
If Uri not empty, Host, Port, UserName, Password and Options will be ignored
type MongoTransaction ¶
type OrmModel ¶
type OrmModel interface { Debug() OrmModel WithContext(ctx context.Context) OrmModel Drop() error Truncate() error Limit(limit int) OrmModel Offset(offset int) OrmModel Order(query ...clause.OrderByColumn) OrmModel Equal(query ...interface{}) OrmModel NotEqual(query ...interface{}) OrmModel Or(query ...interface{}) OrmModel Create(data interface{}) (err error) Upsert(data interface{}) (err error) Update(data map[string]interface{}) (err error) Find(dst interface{}) error First(dst interface{}) error FindRaw() (res []interface{}, err error) Delete() (rowEffected int64, err error) Where(query interface{}, args ...interface{}) OrmModel }
type Redis ¶
type Redis interface { Init() error GetClient() (pool radix.Client) GetConfig() RedisProviderConfig }
type RedisProviderConfig ¶
type RedisProviderConfig struct { Name string `yaml:"name" default:"" desc:"config:redis:name"` Enable bool `yaml:"enable" default:"false" desc:"config:redis:enable"` Host string `yaml:"host" default:"127.0.0.1" desc:"config:redis:host"` Port int `yaml:"port" default:"6379" desc:"config:redis:port"` Password string `yaml:"password" default:"" desc:"config:redis:password"` Pool int `yaml:"pool" default:"10" desc:"config:redis:pool"` AutoReconnect bool `yaml:"autoReconnect" default:"false" desc:"config:autoReconnect"` StartInterval int `yaml:"startInterval" default:"2" desc:"config:startInterval"` MaxError int `yaml:"maxError" default:"5" desc:"config:maxError"` }
type SQL ¶
type SQL interface { Config() SQLConfig UseEncryption(encLib encryption.Encryption) SQL Gorm() *gorm.DB ORM() ORM Start() error Close() error GetEncryption() (encLib encryption.Encryption) }
type SQLConfig ¶
type SQLConfig struct { Name string `yaml:"name" default:"" desc:"config:sql:name"` Driver string `yaml:"driver" default:"mysql" desc:"config:sql:enable"` Enable bool `yaml:"enable" default:"false" desc:"config:sql:enable"` Host string `yaml:"host" default:"127.0.0.1" desc:"config:sql:host"` Port int `yaml:"port" default:"3306" desc:"config:sql:port"` Username string `yaml:"username" default:"root" desc:"config:sql:username"` Password string `yaml:"password" default:"root" desc:"config:sql:password"` Database string `yaml:"database" default:"sample_database" desc:"config:sql:database"` Options string `yaml:"options" default:"" desc:"config:sql:options"` Connection string `yaml:"connection" default:"" desc:"config:sql:connection"` AutoReconnect bool `yaml:"autoReconnect" default:"false" desc:"config:autoReconnect"` StartInterval int `yaml:"startInterval" default:"2" desc:"config:startInterval"` MaxError int `yaml:"maxError" default:"5" desc:"config:maxError"` DBPath string `yaml:"dbPath" default:"./sqlite.db" desc:"config:sql:dbPath"` SsLMode string `yaml:"sslMode" default:"disable" desc:"config:sql:sslMode"` TimeoutConnection int `yaml:"timeoutConnection" default:"5000" desc:"config:sql:timeoutConnection"` TimeoutTransaction int `yaml:"timeoutTransaction" default:"5000" desc:"config:sql:timeoutTransaction"` }
Click to show internal directories.
Click to hide internal directories.