1

我正在使用 SQL 锅炉和 GOlang

"github.com/volatiletech/sqlboiler/v4/queries"
    "github.com/volatiletech/sqlboiler/v4/queries/qm"

我想在不同的列中设置限制、偏移和排序

我的代码是

    queryMods := []qm.QueryMod{
        qm.OrderBy("hive_id"),
        qm.Limit(10),
        qm.Offset(0),
        qm.Load(dbmodels.HiveUserDemographicRels.Answer),
        qm.Load(dbmodels.HiveUserDemographicRels.Question),
        qm.Load(dbmodels.HiveUserDemographicRels.Hive),
    }
    where := fmt.Sprintf(`hive on hive_user_demographic.hive_id=hive.hive_id and hive.deleted_at is null `)
    queryMods = append(queryMods, qm.InnerJoin(where))
    demographic, err := dbmodels.HiveUserDemographics(queryMods...).All(ctx, m.db)

使用此代码,限制和偏移量基于表 HiveUserDemographic

但我想像mysql一样在“Hive”表(dbmodels.HiveUserDemographicRels.Hive)中设置限制和偏移量

SELECT hive_user_demographic.*
            FROM  (
            SELECT *
            FROM   hive
            where  deleted_at is null
                order by hive_id asc
                LIMIT  10
                OFFSET 0
            ) hive_data
            JOIN   hive_user_demographic  on hive_data.hive_id=hive_user_demographic.hive_id

我试过这个

queryMods := []qm.QueryMod{
        qm.Load(dbmodels.HiveUserDemographicRels.Answer),
        qm.Load(dbmodels.HiveUserDemographicRels.Question),
        qm.Load(dbmodels.HiveUserDemographicRels.Hive, qm.Limit(1), qm.Offset(0)),
    }

但不工作

它出现恐慌错误

[{Answer []} {问题 []} {Hive [{1} {1}]} {hive_user_demographic.hive_id=hive.hive_id 和 hive.deleted_at 上的 hive 为 null []} {hive.hive_id asc} { hive_user_demographic}]

&{0x2096ca0 { []} [Answer Question Hive] map[Hive:[{1} {1}]] false map[] [] [] false [ hive_user_demographic] [{0 hive on hive_user_demographic.hive_id=hive.hive_id 和 hive .deleted_at 为 null []}] [] [] [{hive.hive_id asc []}] [] 0 0 }

hive_user_demographic 有 hive_id(例如 1,2..),每行有 10 行。Hive 表每行有一个 hive_id(例如 1,2..)。所以我想在配置单元表中设置限制和偏移量。

我该如何设置

4

0 回答 0