Documentation ¶
Overview ¶
Example (Delete) ¶
package main import ( "context" "fmt" "github.com/sqjian/go-kit/rds" ) var db *rds.Rds func main() { ctx := context.Background() fmt.Println(db.Delete(ctx, "test", map[string]any{"age": 5})) }
Output:
Example (Init) ¶
package main import ( "github.com/sqjian/go-kit/log" "github.com/sqjian/go-kit/rds" "time" ) var db *rds.Rds func checkErr(err error) { if err != nil { panic(err) } } func main() { _db, dbErr := rds.NewRds( rds.Mysql, rds.WithIp("192.168.6.6"), rds.WithPort("3306"), rds.WithUserName("root"), rds.WithPassWord("xylx1.t!@#"), rds.WithMaxLifeTime(time.Second), rds.WithMaxIdleConns(3), rds.WithDbName("test"), rds.WithLogger(func() log.Log { inst, _ := log.NewLogger(log.WithLevel("dummy")); return inst }()), ) checkErr(dbErr) db = _db }
Output:
Example (Insert) ¶
package main import ( "context" "fmt" "github.com/sqjian/go-kit/rds" ) var db *rds.Rds func main() { ctx := context.WithValue(context.Background(), "id", 1) fmt.Println(db.Insert(ctx, "test", map[string]any{"age": 1})) }
Output:
Example (MysqlQuery) ¶
package main import ( "context" "fmt" "github.com/sqjian/go-kit/rds" ) var db *rds.Rds func main() { ctx := context.WithValue(context.Background(), "id", 1) rst, err := db.Query(ctx, []string{"test"}, nil) if err != nil { panic(err) } for k, v := range rst { fmt.Printf("k:%v,v:%v", k, v) } fmt.Println(string((rst[0]["create_time"]).([]byte))) }
Output:
Example (Update) ¶
package main import ( "context" "fmt" "github.com/sqjian/go-kit/rds" ) var db *rds.Rds func main() { ctx := context.WithValue(context.Background(), "id", 1) fmt.Println(db.Update(ctx, "test", map[string]any{"age": 5}, map[string]any{"age": 1})) }
Output:
Index ¶
- func WithPlaceholder(placeholder string) instructOptionFunc
- type ConfigOptionFunc
- func WithDbName(dbName string) ConfigOptionFunc
- func WithIp(ip string) ConfigOptionFunc
- func WithLogger(logger log.Log) ConfigOptionFunc
- func WithMaxIdleConns(MaxIdleConns int) ConfigOptionFunc
- func WithMaxLifeTime(MaxLifeTime time.Duration) ConfigOptionFunc
- func WithPassWord(PassWord string) ConfigOptionFunc
- func WithPort(port string) ConfigOptionFunc
- func WithUserName(UserName string) ConfigOptionFunc
- type Err
- type Instruct
- type QueryOption
- type QueryOptionFunc
- type Rds
- func (r *Rds) Delete(ctx context.Context, table string, where map[string]any, ...) (map[string]int64, error)
- func (r *Rds) Insert(ctx context.Context, table string, data map[string]any, ...) (map[string]int64, error)
- func (r *Rds) Query(ctx context.Context, table []string, opts ...QueryOptionFunc) ([]map[string]any, error)
- func (c Rds) Stub() *Rds
- func (r *Rds) Update(ctx context.Context, table string, data map[string]any, where map[string]any, ...) (map[string]int64, error)
- type SqlOption
- type Type
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithPlaceholder ¶
func WithPlaceholder(placeholder string) instructOptionFunc
Types ¶
type ConfigOptionFunc ¶
type ConfigOptionFunc func(*config)
func WithDbName ¶
func WithDbName(dbName string) ConfigOptionFunc
func WithIp ¶
func WithIp(ip string) ConfigOptionFunc
func WithLogger ¶
func WithLogger(logger log.Log) ConfigOptionFunc
func WithMaxIdleConns ¶
func WithMaxIdleConns(MaxIdleConns int) ConfigOptionFunc
func WithMaxLifeTime ¶
func WithMaxLifeTime(MaxLifeTime time.Duration) ConfigOptionFunc
func WithPassWord ¶
func WithPassWord(PassWord string) ConfigOptionFunc
func WithPort ¶
func WithPort(port string) ConfigOptionFunc
func WithUserName ¶
func WithUserName(UserName string) ConfigOptionFunc
type QueryOption ¶
type QueryOption interface {
// contains filtered or unexported methods
}
type QueryOptionFunc ¶
type QueryOptionFunc func(*SqlOption)
func WithColumn ¶
func WithColumn(column []string) QueryOptionFunc
func WithWhere ¶
func WithWhere(where map[string]any) QueryOptionFunc
Click to show internal directories.
Click to hide internal directories.