db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MongoDefaultPort                   = "27017"
	MongoDefaultDatabase               = "bioos"
	MongoDefaultConnectTimeout         = 30 * time.Second
	MongoDefaultServerSelectionTimeout = 30 * time.Second
	MongoDefaultSocketTimeout          = 30 * time.Second
	MongoDefaultHeartbeatInterval      = 5 * time.Second
	MongoDefaultMaxConnIdleTime        = 30 * time.Second
	MongoDefaultMaxPoolSize            = 100
	MongoDefaultMinPoolSize            = 1
)
View Source
const (
	MySQLDefaultPort            = "3306"
	MySQLDefaultDatabase        = "bioos"
	MySQLDefaultMaxIdleConns    = 10
	MySQLDefaultMaxOpenConns    = 100
	MySQLDefaultCreateBatchSize = 1000
	MySQLDefaultConnMaxLifeTime = time.Hour
	MySQLDefaultConnMaxIdleTime = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoOptions

type MongoOptions struct {
	Host                   string        `json:"host" mapstructure:"host"`
	Port                   string        `json:"port" mapstructure:"port"`
	Username               string        `json:"username" mapstructure:"username"`
	Password               string        `json:"password" mapstructure:"password,omitempty"`
	Database               string        `json:"database" mapstructure:"database"`
	ConnectTimeout         time.Duration `json:"connectTimeout" mapstructure:"connectTimeout"`
	ServerSelectionTimeout time.Duration `json:"serverSelectionTimeout" mapstructure:"serverSelectionTimeout"`
	SocketTimeout          time.Duration `json:"socketTimeout" mapstructure:"socketTimeout"`
	HeartbeatInterval      time.Duration `json:"heartbeatInterval" mapstructure:"heartbeatInterval"`
	MaxConnIdleTime        time.Duration `json:"maxConnIdleTime" mapstructure:"maxConnIdleTime"`
	MaxPoolSize            uint64        `json:"maxPoolSize" mapstructure:"maxPoolSize"`
	MinPoolSize            uint64        `json:"minPoolSize" mapstructure:"minPoolSize"`
}

func NewMongoOptions

func NewMongoOptions() *MongoOptions

NewMongoOptions new a mongo option.

func (*MongoOptions) AddFlags

func (o *MongoOptions) AddFlags(fs *pflag.FlagSet)

AddFlags ...

func (*MongoOptions) Enabled

func (o *MongoOptions) Enabled() bool

func (*MongoOptions) GetDBInstance

func (o *MongoOptions) GetDBInstance(ctx context.Context) (*mongo.Client, *mongo.Database, error)

GetDBInstance ...

func (*MongoOptions) Validate

func (o *MongoOptions) Validate() error

Validate validate mongo options is valid.

type MySQLOptions

type MySQLOptions struct {
	Username        string        `json:"username" mapstructure:"username"`
	Password        string        `json:"password" mapstructure:"password,omitempty"`
	Host            string        `json:"host" mapstructure:"host"`
	Port            string        `json:"port" mapstructure:"port"`
	Database        string        `json:"database" mapstructure:"database"`
	MaxIdleConns    int           `json:"maxIdleConns" mapstructure:"maxIdleConns"`
	MaxOpenConns    int           `json:"maxOpenConns" mapstructure:"maxOpenConns"`
	CreateBatchSize int           `json:"createBatchSize" mapstructure:"createBatchSize,omitempty"`
	ConnMaxLifetime time.Duration `json:"connMaxLifetime" mapstructure:"connMaxLifetime"`
	ConnMaxIdleTime time.Duration `json:"connMaxIdleTime" mapstructure:"connMaxIdletime"`
}

func NewMySQLOptions

func NewMySQLOptions() *MySQLOptions

NewMySQLOptions new a mysql option.

func (*MySQLOptions) AddFlags

func (o *MySQLOptions) AddFlags(fs *pflag.FlagSet)

func (*MySQLOptions) Enabled

func (o *MySQLOptions) Enabled() bool

func (*MySQLOptions) GetGORMInstance

func (o *MySQLOptions) GetGORMInstance(ctx context.Context) (*gorm.DB, error)

GetGORMInstance ...

func (*MySQLOptions) Validate

func (o *MySQLOptions) Validate() error

Validate validate log options is valid.

type Options

type Options struct {
	SQLite3 *SQLite3Options `json:"sqlite3,omitempty" mapstructure:"sqlite3,omitempty"`
	MySQL   *MySQLOptions   `json:"mysql,omitempty" mapstructure:"mysql,omitempty"`
	Mongo   *MongoOptions   `json:"mongo,omitempty" mapstructure:"mongo,omitempty"`
}

func NewOptions

func NewOptions() *Options

NewOptions new a db option.

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags ...

func (*Options) Validate

func (o *Options) Validate() error

Validate check db options is valid.

type SQLite3Options

type SQLite3Options struct {
	File string `json:"file" mapstructure:"file"`
}

SQLite3Options stands for sqlite options.

func NewSQLite3Options

func NewSQLite3Options() *SQLite3Options

NewSQLite3Options return a sqlite option.

func (*SQLite3Options) AddFlags

func (o *SQLite3Options) AddFlags(fs *pflag.FlagSet)

func (*SQLite3Options) Enabled

func (o *SQLite3Options) Enabled() bool

func (*SQLite3Options) GetGORMInstance

func (o *SQLite3Options) GetGORMInstance(ctx context.Context) (*gorm.DB, error)

GetGORMInstance ...

func (*SQLite3Options) Validate

func (o *SQLite3Options) Validate() error

Jump to

Keyboard shortcuts

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