rice

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: MIT Imports: 13 Imported by: 0

README

rice

Usage

Database

import "github.com/woxingliu/rice"
go mod tidy

postgresql

pg, err := rice.NewPostgresDB(
	"postgres://postgres:123456@localhost:5432/user?sslmode=disable",
	rice.ConnAttempts_Postgres(10),
	rice.MaxPoolSize_Postgres(4),
)
if err != nil {
	return err
}
defer pg.Close()

mariadb

mariaDB := rice.NewMariaDB(
	"root:root@tcp(localhost:3306)/user?parseTime=True&loc=Local&charset=utf8mb4&collation=utf8mb4_unicode_ci",
	rice.MaxIdleConns_MYSQL(4),
	rice.MaxOpenConns_MYSQL(4),
)
defer mariaDB.Close()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteString

func ByteString(b []byte) string

[]byte to string

func CloseDB added in v0.0.8

func CloseDB()

func StrconvFormatInt

func StrconvFormatInt(i int64) string

1645270804 to "1645270804"

func StrconvParseFloat added in v0.0.8

func StrconvParseFloat(i int) float64

int/100 to float64 保留 2 位小数点

func StrconvParseInt

func StrconvParseInt(s string) int64

"1645270804" to 1645270804

func StringByte

func StringByte(s string) (b []byte)

string to []byte

func TimeFormat

func TimeFormat(tm time.Time) string

time.Time to "2006-01-02 15:04:05"

func TimeNowFormat

func TimeNowFormat() string

time.Time to "2006-01-02 15:04:05"

func TimeParse

func TimeParse(s string) time.Time

"2006-01-02 15:04:05" to time.Time

func TimeUnix

func TimeUnix(sec int64) time.Time

1645270804 to time.Time

Types

type MariaDB added in v0.0.8

type MariaDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func GetMariaDB added in v0.0.8

func GetMariaDB() *MariaDB

func NewMariaDB added in v0.0.8

func NewMariaDB(url string, opts ...MariaDBOption) *MariaDB

func (*MariaDB) Close added in v0.0.8

func (db *MariaDB) Close()

type MariaDBOption added in v0.0.8

type MariaDBOption func(*MariaDB)

func ConnAttempts_MYSQL added in v0.0.8

func ConnAttempts_MYSQL(attempts int) MariaDBOption

ConnAttempts_MYSQL 尝试连接数据库次数

func ConnMaxIdleTime_MYSQL added in v0.0.8

func ConnMaxIdleTime_MYSQL(d time.Duration) MariaDBOption

ConnMaxIdleTime_MYSQL 一个连接空闲的最大时长

func ConnMaxLifetime_MYSQL added in v0.0.8

func ConnMaxLifetime_MYSQL(d time.Duration) MariaDBOption

ConnMaxLifetime_MYSQL 一个连接使用的最大时长

func ConnTimeout_MYSQL added in v0.0.8

func ConnTimeout_MYSQL(timeout time.Duration) MariaDBOption

ConnTimeout_MYSQL 连接数据库超时时间

func MaxIdleConns_MYSQL added in v0.0.8

func MaxIdleConns_MYSQL(size int) MariaDBOption

MaxIdleConns_MYSQL 最大闲置的连接数

func MaxOpenConns_MYSQL added in v0.0.8

func MaxOpenConns_MYSQL(size int) MariaDBOption

MaxOpenConns_MYSQL 最大打开的连接数

type Postgres added in v0.0.8

type Postgres struct {
	Builder squirrel.StatementBuilderType
	Pool    *pgxpool.Pool
	// contains filtered or unexported fields
}

Postgres -.

func GetPostgresDB added in v0.0.8

func GetPostgresDB() *Postgres

func NewPostgresDB added in v0.0.8

func NewPostgresDB(url string, opts ...PostgresOption) (*Postgres, error)

NewPostgresDB -.

func (*Postgres) Close added in v0.0.8

func (p *Postgres) Close()

Close -.

type PostgresOption added in v0.0.8

type PostgresOption func(*Postgres)

Option -.

func ConnAttempts_Postgres added in v0.0.8

func ConnAttempts_Postgres(attempts int) PostgresOption

ConnAttempts -.

func ConnTimeout_Postgres added in v0.0.8

func ConnTimeout_Postgres(timeout time.Duration) PostgresOption

ConnTimeout -.

func MaxPoolSize_Postgres added in v0.0.8

func MaxPoolSize_Postgres(size int) PostgresOption

MaxPoolSize -.

type Redis added in v0.0.8

type Redis struct {
	*redis.Client
	// contains filtered or unexported fields
}

func NewRedisClient added in v0.0.8

func NewRedisClient(addr, pwd string, db, poolSize int) *Redis

func (*Redis) Close added in v0.0.8

func (r *Redis) Close()

Directories

Path Synopsis
database
Package httpserver implements HTTP server.
Package httpserver implements HTTP server.

Jump to

Keyboard shortcuts

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