Procházet zdrojové kódy

db Exec\Get\Select

ls před 4 roky
rodič
revize
f73e1f5c69
3 změnil soubory, kde provedl 30 přidání a 0 odebrání
  1. 27 0
      db/db.go
  2. 1 0
      go.mod
  3. 2 0
      go.sum

+ 27 - 0
db/db.go

@@ -99,6 +99,7 @@ func (d *DB) Connect() (err error) {
 
 // Close close database connect
 func (d *DB) Close() {
+	// use pool
 	//d.conn.Close()
 }
 
@@ -147,6 +148,19 @@ func (d *DB) TransUpdate(query string, args interface{}) (reply Reply) {
 	return
 }
 
+// Select select
+func (d *DB) Select(dest interface{}, query string, args ...interface{}) error {
+	err := d.Connect()
+	if err != nil {
+		return err
+	}
+	defer d.Close()
+
+	err = d.conn.Select(dest, query, args...)
+
+	return err
+}
+
 // Rows get rows
 func (d *DB) Rows(dest interface{}, query string, args interface{}) error {
 	err := d.Connect()
@@ -166,6 +180,19 @@ func (d *DB) Rows(dest interface{}, query string, args interface{}) error {
 	return err
 }
 
+// Get get
+func (d *DB) Get(dest interface{}, query string, args ...interface{}) error {
+	err := d.Connect()
+	if err != nil {
+		return err
+	}
+	defer d.Close()
+
+	err = d.conn.Get(dest, query, args...)
+
+	return err
+}
+
 // Row get row
 func (d *DB) Row(dest interface{}, query string, args interface{}) error {
 	err := d.Connect()

+ 1 - 0
go.mod

@@ -3,6 +3,7 @@ module git.chuangxin1.com/cx/myth
 go 1.13
 
 require (
+	github.com/go-redis/redis v6.15.7+incompatible
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/golang/protobuf v1.3.1
 	github.com/jmoiron/sqlx v1.2.0

+ 2 - 0
go.sum

@@ -5,6 +5,8 @@ github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6
 github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=
 github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
 github.com/go-redis/redis v6.15.6+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
+github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U=
+github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
 github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=