1

I want to execute this eager loading query by SQLBoiler in order to get specific row.

SELECT * FROM `room_users` WHERE (`room_users`.`room_id` IN (?,?,?,?) AND (room_users.user_id=?, 2));

But, I don't know how to write query in SQLBoiler.

My code is here:

    return entity.Rooms(
        qm.Load(entity.RoomRels.RoomUsers, qm.Where("room_users.user_id=?, 2")),
    ).All(ctx, ur.DB)

this code execute this query

SELECT * FROM `room_users` WHERE (`room_users`.`room_id` IN (?,?,?,?)) AND (room_users.user_id=?, 2);

Can anyone teach me how to load specific row by SQLBoiler.

kkkkgyg
  • 69
  • 8
  • 1
    ORMs... Destroying developer hours since invention.... So the best answer is: Since you can write SQL, you can use that: https://golang.hotexamples.com/examples/github.com.vattle.sqlboiler.queries/-/Raw/golang-raw-function-examples.html => See line queries.Raw – Norbert Aug 10 '22 at 23:40

2 Answers2

-1

this query did work for me

 return entity.Rooms(
    qm.Load(qm.Rels(entity.RoomRels.RoomUsers), qm.Where("room_users.user_id=?", 2)),
).All(ctx, ur.DB)
lpcl
  • 34
  • 1
  • 2
-1

You can do something like this,

return entity.Rooms(
    qm.Load(qm.Rels(entity.RoomRels.RoomUsers), entity.RoomUsersWhere.UserID.EQ(2)),
).All(ctx, ur.DB)
TanA
  • 41
  • 5