本文整理汇总了Golang中database/sql.NullInt64类的典型用法代码### 示例。如果您正苦于以下问题:Golang NullInt64类的具体用法?Golang NullInt64怎么用?Golang NullInt64使用的例子?那么恭喜您, 这里精选的类代码### 示例或许可以为您提供帮助。

在下文中一共展示了NullInt64类的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: TestIntOrNull

func TestIntOrNull(t *testing.T) {
    var nullInt sql.NullInt64
    var value driver.Value
    var err error

    // When the integer is zero
    nullInt = IntOrNull(0)

    // nullInt.Valid should be false
    assert.False(t, nullInt.Valid)

    // nullInt.Value() should return nil
    value, err = nullInt.Value()
    assert.Nil(t, err)
    assert.Nil(t, value)

    // When the integer is greater than zero
    nullInt = IntOrNull(1)

    // nullInt.Valid should be true
    assert.True(t, nullInt.Valid)

    // nullInt.Value() should return the integer
    value, err = nullInt.Value()
    assert.Nil(t, err)
    assert.Equal(t, int64(1), value)
}

开发者ID:kunalshah,项目名称:go-oauth2-server,代码行数:27,代码来源:util_test.go

示例2: TestPositiveIntOrNull

func TestPositiveIntOrNull(t *testing.T) {
    var (
        nullInt sql.NullInt64
        value   driver.Value
        err     error
    )

    // When the number is negative
    nullInt = PositiveIntOrNull(-1)

    // nullInt.Valid should be false
    assert.False(t, nullInt.Valid)

    // nullInt.Value() should return nil
    value, err = nullInt.Value()
    assert.Nil(t, err)
    assert.Nil(t, value)

    // When the number is greater than zero
    nullInt = PositiveIntOrNull(1)

    // nullInt.Valid should be true
    assert.True(t, nullInt.Valid)

    // nullInt.Value() should return the integer
    value, err = nullInt.Value()
    assert.Nil(t, err)
    assert.Equal(t, int64(1), value)
}

开发者ID:chenhougen,项目名称:go-oauth2-server,代码行数:29,代码来源:util_test.go

示例3: listAllConnections

func (database Database) listAllConnections() (res DbUsersWithConnections) {
    res = make(DbUsersWithConnections)

    rows, err := database.db.Query(`
        -- Left join because we want users without connections as well
        SELECT u1.id, u1.username, u2.id, u2.username FROM 
            user AS u1 LEFT JOIN connection ON u1.id = connection.fromUser
            LEFT JOIN user AS u2 ON u2.id = connection.toUser
            ORDER BY u1.id
            `)
    checkErr(err)
    defer rows.Close()
    for rows.Next() {
        var fromUser User
        var toUsername sql.NullString
        var toId sql.NullInt64
        err := rows.Scan(&fromUser.Id, &fromUser.Username, &toId, &toUsername)
        checkErr(err)

        if toId.Valid {
            // this user has at least one connection, unpack the nullable values
            toIdValue, _ := toId.Value()
            toUsernameValue, _ := toUsername.Value()
            res[fromUser] = append(res[fromUser], User{toIdValue.(int64), toUsernameValue.(string)})
        } else {
            // this user doesn't have any connections
            res[fromUser] = []User{}
        }
    }
    return res
}

开发者ID:rutchkiwi,项目名称:go-rest-api,代码行数:31,代码来源:db.go

示例4: AllAgents

func AllAgents(db *sql.DB, simid []byte, proto string) (ags []AgentInfo, err error) {
    s := `SELECT AgentId,Kind,Spec,Prototype,ParentId,EnterTime,ExitTime,Lifetime FROM
                Agents
            WHERE Agents.SimId = ?`

    var rows *sql.Rows
    if proto != "" {
        s += ` AND Agents.Prototype = ?`
        rows, err = db.Query(s, simid, proto)
    } else {
        rows, err = db.Query(s, simid)
    }
    if err != nil {
        return nil, err
    }

    for rows.Next() {
        ai := AgentInfo{}
        var exit sql.NullInt64
        if err := rows.Scan(&ai.Id, &ai.Kind, &ai.Impl, &ai.Proto, &ai.Parent, &ai.Enter, &exit, &ai.Lifetime); err != nil {
            return nil, err
        }
        if !exit.Valid {
            exit.Int64 = -1
        }
        ai.Exit = int(exit.Int64)
        ags = append(ags, ai)
    }
    if err := rows.Err(); err != nil {
        return nil, err
    }
    return ags, nil
}

开发者ID:katyhuff,项目名称:cyan,代码行数:33,代码来源:query.go

示例5: createLoginLog

func createLoginLog(succeeded bool, remoteAddr, login string, user *User) error {
    succ := 0
    if succeeded {
        succ = 1
    }

    var userId sql.NullInt64
    if user != nil {
        userId.Int64 = int64(user.ID)
        userId.Valid = true

        mu.Lock()
        if succeeded {
            resetUserFailCount(user.ID)
            resetIpFailCount(remoteAddr)
        } else {
            incrUserFailCount(user.ID)
            incrIpFailCount(remoteAddr)
        }
        mu.Unlock()
    }

    _, err := db.Exec(
        "INSERT INTO login_log (`created_at`, `user_id`, `login`, `ip`, `succeeded`) "+
            "VALUES (?,?,?,?,?)",
        time.Now(), userId, login, remoteAddr, succ,
    )

    return err
}

开发者ID:walf443,项目名称:isucon4,代码行数:30,代码来源:db.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng