Code Monkey home page Code Monkey logo

golang-db's People

Contributors

hopehook avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-db's Issues

can not query data from mysql

hello , i can not select data from mysql , my code is:

my main package:

package main

import(
    "github.com/gin-gonic/gin"
    "net/http"
    "fecshop.com/module/user" 
    //"fecshop.com/common/cdb"  
    _ "github.com/go-sql-driver/mysql" 
    mysqlPool "github.com/hopehook/golang-db/mysql"
)


func mysqlDBPool() *mysqlPool.SQLConnPool{
    host := `127.0.0.1:3306`
    database := `go_test`
    user := `root`
    password := `xxx`
    charset := `utf8`
    // 用于设置最大打开的连接数
    maxOpenConns := 200
    // 用于设置闲置的连接数
    maxIdleConns := 100
    mysqlDB := mysqlPool.InitMySQLPool(host, database, user, password, charset, maxOpenConns, maxIdleConns)

    return mysqlDB
}

func main() { 
    mysqlDB := mysqlDBPool();
    r := gin.Default()
    
    
    v2 := r.Group("/v2")
    {
        // 查询部分
        v2.GET("/users", func(c *gin.Context) {
            data := user.List2(mysqlDB);
            c.JSON(http.StatusOK, data)
        })
    }
    
    r.Run("120.24.37.249:3000") // listen and serve on 0.0.0.0:8080
    
}

my user package code :

package user

import (    
    "fmt"
    "github.com/gin-gonic/gin"  
    mysqlPool "github.com/hopehook/golang-db/mysql"
)

func List2(mysqlDB *mysqlPool.SQLConnPool) gin.H{
    body := make(gin.H) 
    rows, err := mysqlDB.Query("SELECT * From user")
    if err != nil {
        fmt.Printf("%s\r\n","mysql query error")
    }
    fmt.Printf("%v\r\n",rows)
    var dbdata []gin.H
    if rows != nil {
        for _, row := range rows {
            h := make(gin.H) 
            for k,v := range row {
                h[k] = v
                
            }
            dbdata = append(dbdata, h)
        }
    }
    body["data"] = dbdata
    return body
}

fmt.Printf("%v\r\n",rows) :

[map[] map[] map[] map[] map[] map[] map[] map[] map[]]

return empty

go_test.user:

CREATE TABLE IF NOT EXISTS `user` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT '',
  `age` int(11) DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;

--
-- 转存表中的数据 `user`
--

INSERT INTO `user` (`id`, `name`, `age`) VALUES
(1, '111', 111),
(2, 'terry', 44),
(3, 'terry', 55),
(4, 'terry', 44),
(5, 'terry', 44),
(6, 'terry', 44),
(7, 'terry', 44),
(8, 'te11rry', 929),
(10, 'terry', 66);

can you help me ? thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.