Giter VIP home page Giter VIP logo

Comments (2)

caibirdme avatar caibirdme commented on July 24, 2024

@jacexh 确实,现在还没有支持sql包里的NullXX类型,我会在接下来的一段时间考虑加上这块儿的支持(如果你感兴趣也欢迎Pr)。

我理解的话,你的需求是因为表中有字段可以为NULL,然后你希望有办法能够判断这个信息。我刚才提交了一个新的commit,应该可以支持你目前的需求,你只要把可以为NULL的字段设置为指针类型即可:

type struct User {
    Name *string `ddb:"name"`,
    Score *float64 `ddb:"rank"`,
}

var u User

scanner.Scan(rows, &u)
// 如果数据库中name字段为NULL
if u.Name == nil {
// 这里等价于NullString中的 if u.Valid == false
}

不过只要有指针,用的时候一定要记得判断if xx.YY !=nil 哦

from gendry.

jacexh avatar jacexh commented on July 24, 2024

@jacexh 确实,现在还没有支持sql包里的NullXX类型,我会在接下来的一段时间考虑加上这块儿的支持(如果你感兴趣也欢迎Pr)。

我理解的话,你的需求是因为表中有字段可以为NULL,然后你希望有办法能够判断这个信息。我刚才提交了一个新的commit,应该可以支持你目前的需求,你只要把可以为NULL的字段设置为指针类型即可:

type struct User {
    Name *string `ddb:"name"`,
    Score *float64 `ddb:"rank"`,
}

var u User

scanner.Scan(rows, &u)
// 如果数据库中name字段为NULL
if u.Name == nil {
// 这里等价于NullString中的 if u.Valid == false
}

不过只要有指针,用的时候一定要记得判断if xx.YY !=nil 哦

多谢,我随后试下

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.