Beego QueryRows映射失败

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?

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