mysql - 如何解析复合结构中的表
问题描述
我有几个结构,其中一个包含所有其余结构。我需要使用 GORM 来获取主要结构。
我尝试使用带有“列”的 gorm 标签,但不起作用
package database
import (
"database/sql"
"time"
)
type TaskItem struct {
Ind int32 `gorm:"column:Ind"`
ParentIndArray sql.NullString `gorm:"column:ParentIndArray"`
ParentInd int32 `gorm:"column:ParentInd"`
SourceId string `gorm:"column:SourceId"`
SourceInd int32 `gorm:"column:SourceInd"`
ContentIndActive int32 `gorm:"column:ContentIndActive"`
StatusIndInit int32 `gorm:"column:StatusIndInit"`
StatusIndActive int32 `gorm:"column:StatusIndActive"`
TaskTypeInd int32 `gorm:"column:TaskTypeInd"`
RootTaskTypeInd int32 `gorm:"column:RootTaskTypeInd"`
FieldInd int32 `gorm:"column:FieldInd"`
StateIndActive int32 `gorm:"column:StateIndActive"`
ChildIndArray []byte `gorm:"column:ChildIndArray"`
}
type TaskContent struct {
Ind int32 `gorm:"column:ContentInd"`
TaskInd int32 `gorm:"-"`
SessionInd int32 `gorm:"column:ContentSessInd"`
Caption string `gorm:"column:Caption"`
Content []byte `gorm:"column:Content"`
Priority int32 `gorm:"column:Priority"`
PlanningDateStart time.Time `gorm:"column:PlanningDateStart"`
PlanningDateEnd time.Time `gorm:"column:PlanningDateEnd"`
TimeEstimate time.Time `gorm:"column:TimeEstimate"`
ApplyDate time.Time `gorm:"column:ContentApplyDate"`
}
type TaskStatus struct {
Ind int32 `gorm:"column:StatusInd"`
TaskInd int32 `gorm:"-"`
ChainId string `gorm:"column:ChainId"`
MessageId string `gorm:"column:MessageID"`
SessionInd int32 `gorm:"column:StatusSessInd"`
StatusInd int32 `gorm:"column:Status"`
Text string `gorm:"column:Text"`
Comment string `gorm:"column:Comment"`
ApplyDate time.Time `gorm:"column:StatusApplyDate"`
ReceiveData time.Time `gorm:"column:StatusReceiveDate"`
}
type TaskState struct {
Ind int32 `gorm:"column:StateInd"`
TaskInd int32 `gorm:"-"`
SessionInd int32 `gorm:"column:StateSessInd"`
State int32 `gorm:"column:State"`
ApplyDate time.Time `gorm:"column:StateApplyDate"`
}
type Task struct {
Item TaskItem
Content TaskContent
Status TaskStatus
State TaskState
}
我希望 Task 包含来自数据库的其他数据。我应该怎么办?
笔记。起初,我使用:
// tasks is equal []Task
err = database.db.Raw("CALL pr_task_list_by_account_ind(?)", accountGroupInd).Scan(&tasks)
然后我决定尝试使用:
var ti []TaskItem
var tc []TaskContent
var tse []TaskState
var tss []TaskStatus
err = database.db.Raw("CALL pr_task_list_by_account_ind(?)", accountGroupInd).Scan(&ti).Scan(&tc).Scan(&tse).Scan(&tss).Error
我注意到第一个扫描仪可以工作,如果我删除它,那么第二个扫描仪也开始工作
解决方案
推荐阅读
- javascript - 为什么图像上传器在 laravel 5.6 中不起作用
- html - 优化我的叠加层的行为
- angular - 在 mapbox gl 中添加 png 路径作为图层
- r - R - 使用数据框中的所有非零分数作为用 sample() 替换自己的概率
- python - 迭代数据框中的列表
- c# - 根据特定的开始和结束标记更改 TextBox 前景色
- google-apps-script - Google App Scipt Utilites.unzip 不适用于来自外部脚本的 zip 文件
- node.js - 查询结果达到 500+ 后,带有填充的 Mongoose 查找查询在 Azure MongoDB 上返回错误
- amazon-web-services - AWS IoT - 设备证书问题
- jsf - 添加 Primefaces 扩展的 CKEditor 时出错