【问题标题】:Beego QueryRows map failedBeego QueryRows 映射失败
【发布时间】:2018-12-14 14:22:42
【问题描述】:

beegoRaw().QueryRows()的映射规则是什么 这是我使用的结构:

type ProcessingNetworkDataProviderConfig struct {
    Id                     int
    NetworkId              int
    DataProviderId         int
    DistributorId          int
    EnableTargeting        int
    EnableReporting        int
    UsePrivateData         int
    UseExternalUserId      int
    UseUserMapping         int
    UseUserAttributes      int
    UserExchangeUrl        string
    EnableCache            int
    EnableBloomFilter      int
    EnableDisplayAds       int
    EnableResellerMode     int
    EnableVisitorReporting int
    Nsql                   string
    MaxSegmentNumber       int
    ExpirationDays         int
    DeltaIngest            int
    Pkg                    int
    Trackednum             int
    Comment                string
    ProcessingStatus       string
}

这是 MySQL 中的表 (desc processing_network_data_provider_config):

+--------------------------+---------------+------+-----+---------+----------------+
| Field                    | Type          | Null | Key | Default | Extra          |
+--------------------------+---------------+------+-----+---------+----------------+
| id                       | bigint(20)    | NO   | PRI | NULL    | auto_increment |
| network_id               | bigint(20)    | NO   | MUL | NULL    |                |
| data_provider_id         | bigint(20)    | NO   | MUL | NULL    |                |
| distributor_id           | bigint(20)    | YES  | MUL | NULL    |                |
| enable_targeting         | tinyint(1)    | NO   |     | 0       |                |
| enable_reporting         | tinyint(1)    | NO   |     | 0       |                |
| use_private_data         | tinyint(1)    | NO   |     | 0       |                |
| use_external_user_id     | tinyint(1)    | NO   |     | 0       |                |
| use_user_mapping         | tinyint(1)    | NO   |     | 0       |                |
| use_user_attributes      | tinyint(1)    | NO   |     | 1       |                |
| user_exchange_url        | varchar(255)  | YES  |     | NULL    |                |
| enable_cache             | tinyint(1)    | NO   |     | 1       |                |
| enable_bloom_filter      | tinyint(1)    | NO   |     | 0       |                |
| enable_display_ads       | tinyint(1)    | NO   |     | 1       |                |
| enable_reseller_mode     | tinyint(1)    | NO   |     | 0       |                |
| enable_visitor_reporting | tinyint(1)    | NO   |     | 1       |                |
| Nsql                     | varchar(2000) | YES  |     | NULL    |                |
| seg_num                  | int(11)       | YES  |     | NULL    |                |
| exp_date                 | int(11)       | YES  |     | NULL    |                |
| delta_ingest             | tinyint(1)    | YES  |     | NULL    |                |
| package                  | tinyint(1)    | YES  |     | NULL    |                |
| tracked_num              | int(11)       | YES  |     | NULL    |                |
| Comment                  | varchar(2000) | YES  |     | NULL    |                |
| ProcessingStatus         | varchar(30)   | YES  |     | NULL    |                |
+--------------------------+---------------+------+-----+---------+----------------+

我用这个来读取数据库:

var tt []*ProcessingNetworkDataProviderConfig
sql := `SELECT * FROM processing_network_data_provider_config`
if _, err := o.Raw(sql).QueryRows(&tt); err != nil {
    fmt.Println("fff wo")
    beego.Error("Error when querying network configuration: ", err.Error())
}
fmt.Println(tt[0])

输出是:

&{49 1271 1 -1 1 0 0 0 0 1 1 1 1 1 1 1  0 0 0 0 0  }

但是,这里面应该有一些字符串,它们在哪里? 我想是映射规则让它失败了,对吗?

【问题讨论】:

    标签: mysql go github orm beego


    【解决方案1】:

    https://beego.me/docs/mvc/model/models.md
    根据命名约定,您的结构字段名称将转换为 snake_case 以用于您的数据库架构,并且我注意到架构中的“ProcessingStatus”。所以我相信你有两个选择:
    1. 将“ProcessingStatus”列重命名为snake_case
    2. 对你的结构标签使用特殊映射:

    ProcessingStatus string `orm:"column(processing_status)"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 1970-01-01
      • 2013-01-02
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多