douyu9433 2018-07-06 03:14
浏览 128

Beego QueryRows映射失败

what is the mapping rule of beego Raw().QueryRows() this is the struct I used:

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
}

and this is the table in 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    |                |
+--------------------------+---------------+------+-----+---------+----------------+

I used this to read the database:

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])

and the output was:

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

However, there should be some string in this, where are they? I suppose it's the mapping rule make it failed, am I right?

  • 写回答

1条回答 默认 最新

  • drtiwd06558 2018-07-06 03:43
    关注

    https://beego.me/docs/mvc/model/models.md
    Base on the naming convention, your struct field name will be convert to snake_case as use for your DB schema and I notice your "ProcessingStatus" in schema. So I believe you have 2 options:
    1. Rename the "ProcessingStatus" column to snake_case
    2. Use special mapping with your struct tag:

    ProcessingStatus string `orm:"column(processing_status)"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据