Giter VIP home page Giter VIP logo

Comments (6)

caibirdme avatar caibirdme commented on July 24, 2024

我没看明白你描述的需求,你可以给一段你期望的功能的伪代码
目前我们可以帮你映射到struct不需要你自己映射啊

row,err := db.Query(`select user_name,age from user where id>100`)

type User struct {
  Name string `ddb:"user_name"`
  Age int `ddb:"age"`
}

var students []User
scanner.Scan(rows, &students)

这样就行了

from gendry.

zhanghongming avatar zhanghongming commented on July 24, 2024

对,目前就是这样的,我希望没有struct,而是自动返回数据库的字端,目前都是我把数据库的字端变成struct来解析的,感觉这样很麻烦

from gendry.

zhanghongming avatar zhanghongming commented on July 24, 2024
//字段
cols, _ := rows.Columns()

比如这个就可以

from gendry.

caibirdme avatar caibirdme commented on July 24, 2024

这个rows是标准库的rows,db也是标准库的database/sql.DB对象,你可以执行rows.Columns(),没有问题啊

from gendry.

caibirdme avatar caibirdme commented on July 24, 2024

对,目前就是这样的,我希望没有struct,而是自动返回数据库的字端,目前都是我把数据库的字端变成struct来解析的,感觉这样很麻烦

@zhanghongming 我给的demo代码你还觉得用起来麻烦吗?那你现在的代码是什么样的呢,可以分享下么

from gendry.

caibirdme avatar caibirdme commented on July 24, 2024

@zhanghongming 你是指的ScanMap吗,比如:

rows, _ := db.Query("select name, age as m_age from person")
result, err := scanner.ScanMap(rows)
for _, record := range result {
	fmt.Println(record["name"], record["m_age"])
}

这个功能目前也是支持的

from gendry.

Related Issues (20)

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.