第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將 postgresql jsonb 查詢響應字符串解組到 golang 嵌套結構中

將 postgresql jsonb 查詢響應字符串解組到 golang 嵌套結構中

Go
慕勒3428872 2023-06-26 15:24:53
我正在嘗試從 postgresql jsonb 和非 jsonb 列讀取一些數(shù)據,然后解組我得到嵌套結構的響應字符串。我能夠以字符串形式檢索數(shù)據。但我不知道如何將其解組到結構中。package mainimport (    "database/sql"    "fmt"    "log"    "strconv"    _ "github.com/lib/pq")type Token struct {    Name     string    Value    string    Path     string    HttpOnly bool}type Session struct {    Phishlet   string                       `json:"phishlet,omitempty"`    LandingURL string                       `json:"landing_url,omitempty"`    Username   string                       `json:"username,omitempty"`    Password   string                       `json:"password,omitempty"`    Custom     map[string]string            `json:"custom,omitempty"`    Tokens     map[string]map[string]*Token `json:"tokens,omitempty"`    SessionId  string                       `json:"session_id,omitempty"`    UserAgent  string                       `json:"useragent,omitempty"`    RemoteAddr string                       `json:"remote_addr,omitempty"`    CreateTime int64                        `json:"create_time,omitempty"`    UpdateTime int64                        `json:"update_time,omitempty"`}type Sessions struct {    Id      int64    UserId  []byte    Session Session}func main() {    db, err := sql.Open("postgres", "postgres://user:pass@localhost:port/db")    if err != nil {        log.Fatal(err)    }    rows, err := db.Query("SELECT id, user_id,session FROM sessions ORDER BY id")    defer rows.Close()    columns, err := rows.Columns()    if err != nil {        log.Fatal(err)    }    count := len(columns)    values := make([]interface{}, count)    scanArgs := make([]interface{}, count)    for i := range values {        scanArgs[i] = &values[i]    }
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

我認為這是 pq 驅動程序的預期行為

來自該驅動程序的文檔:

pgx 包含對 Go 類型與 PostgreSQL JSON 和 JSONB 之間編組和解組的內置支持。

我過去曾使用 pgx 進行 jsonb 解組——效果良好。


查看完整回答
反對 回復 2023-06-26
  • 1 回答
  • 0 關注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號