database

package
v1.18.6 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectMongoDB added in v1.6.10

func ConnectMongoDB(ctx context.Context, dsn string, opts ...*options.ClientOptions) *mongo.Database

ConnectMongoDB connect to mongodb with dsn

func ConnectRedis added in v1.6.10

func ConnectRedis(dsn string, opts ...RedisPoolOption) *redis.Pool

ConnectRedis connect to redis with dsn

func ConnectSQLDatabase added in v1.6.10

func ConnectSQLDatabase(dsn string, opts ...SQLDatabaseOption) *sql.DB

ConnectSQLDatabase connect to sql database with dsn

func ParseSQLDSN added in v1.16.1

func ParseSQLDSN(source string) (driverName string, dsn string)

ParseSQLDSN parse sql dsn

Types

type MongoInstance added in v1.18.0

type MongoInstance struct {
	DBRead, DBWrite *mongo.Database
}

func InitMongoDB

func InitMongoDB(ctx context.Context, opts ...*options.ClientOptions) *MongoInstance

InitMongoDB return mongo db read & write instance from environment: MONGODB_HOST_WRITE, MONGODB_HOST_READ if want to create single connection, use MONGODB_HOST_WRITE and set empty for MONGODB_HOST_READ

func (*MongoInstance) Close added in v1.18.0

func (m *MongoInstance) Close() (err error)

func (*MongoInstance) Disconnect added in v1.18.0

func (m *MongoInstance) Disconnect(ctx context.Context) (err error)

func (*MongoInstance) Health added in v1.18.0

func (m *MongoInstance) Health() map[string]error

func (*MongoInstance) ReadDB added in v1.18.0

func (m *MongoInstance) ReadDB() *mongo.Database

func (*MongoInstance) WriteDB added in v1.18.0

func (m *MongoInstance) WriteDB() *mongo.Database

type RedisInstance added in v1.18.0

type RedisInstance struct {
	DBRead, DBWrite *redis.Pool
	ICache          interfaces.Cache
}

func InitRedis

func InitRedis(opts ...RedisPoolOption) *RedisInstance

InitRedis connection from environment: REDIS_READ_DSN, REDIS_WRITE_DSN if want to create single connection, use REDIS_WRITE_DSN and set empty for REDIS_READ_DSN

func (*RedisInstance) Cache added in v1.18.0

func (m *RedisInstance) Cache() interfaces.Cache

func (*RedisInstance) Disconnect added in v1.18.0

func (m *RedisInstance) Disconnect(ctx context.Context) (err error)

func (*RedisInstance) Health added in v1.18.0

func (m *RedisInstance) Health() map[string]error

func (*RedisInstance) ReadPool added in v1.18.0

func (m *RedisInstance) ReadPool() *redis.Pool

func (*RedisInstance) WritePool added in v1.18.0

func (m *RedisInstance) WritePool() *redis.Pool

type RedisPoolOption added in v1.17.0

type RedisPoolOption func(pool *redis.Pool)

func RedisPoolOptionSetIdleTimeout added in v1.17.0

func RedisPoolOptionSetIdleTimeout(dur time.Duration) RedisPoolOption

func RedisPoolOptionSetMaxActive added in v1.17.0

func RedisPoolOptionSetMaxActive(count int) RedisPoolOption

func RedisPoolOptionSetMaxConnLifetime added in v1.17.0

func RedisPoolOptionSetMaxConnLifetime(dur time.Duration) RedisPoolOption

func RedisPoolOptionSetMaxIdle added in v1.17.0

func RedisPoolOptionSetMaxIdle(count int) RedisPoolOption

type SQLDatabaseOption added in v1.17.2

type SQLDatabaseOption func(db *sql.DB)

type SQLInstance added in v1.18.0

type SQLInstance struct {
	DBRead, DBWrite *sql.DB
}

func InitSQLDatabase

func InitSQLDatabase(opts ...SQLDatabaseOption) *SQLInstance

InitSQLDatabase return sql db read & write instance from environment: SQL_DB_READ_DSN, SQL_DB_WRITE_DSN if want to create single connection, use SQL_DB_WRITE_DSN and set empty for SQL_DB_READ_DSN

func (*SQLInstance) Close added in v1.18.0

func (s *SQLInstance) Close() (err error)

func (*SQLInstance) Disconnect added in v1.18.0

func (s *SQLInstance) Disconnect(ctx context.Context) (err error)

func (*SQLInstance) Health added in v1.18.0

func (s *SQLInstance) Health() map[string]error

func (*SQLInstance) ReadDB added in v1.18.0

func (s *SQLInstance) ReadDB() *sql.DB

func (*SQLInstance) WriteDB added in v1.18.0

func (s *SQLInstance) WriteDB() *sql.DB

Jump to

Keyboard shortcuts

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