@@ -14,8 +14,15 @@ func TuplesFilterQueryForSelectBuilder(sl squirrel.SelectBuilder, filter *base.T
1414 eq ["entity_type" ] = filter .GetEntity ().GetType ()
1515 }
1616
17- if len (filter .GetEntity ().GetIds ()) > 0 {
18- eq ["entity_id" ] = filter .GetEntity ().GetIds ()
17+ entityIds := filter .GetEntity ().GetIds ()
18+ if len (entityIds ) > 0 {
19+ if len (entityIds ) == 1 {
20+ // If there is only one ID, use the = operator
21+ eq ["entity_id" ] = entityIds [0 ]
22+ } else {
23+ // If there are multiple IDs, use the IN operator
24+ eq ["entity_id" ] = entityIds
25+ }
1926 }
2027
2128 if filter .GetRelation () != "" {
@@ -26,16 +33,23 @@ func TuplesFilterQueryForSelectBuilder(sl squirrel.SelectBuilder, filter *base.T
2633 eq ["subject_type" ] = filter .GetSubject ().GetType ()
2734 }
2835
29- if len (filter .GetSubject ().GetIds ()) > 0 {
30- eq ["subject_id" ] = filter .GetSubject ().GetIds ()
36+ subjectIds := filter .GetSubject ().GetIds ()
37+ if len (subjectIds ) > 0 {
38+ if len (subjectIds ) == 1 {
39+ // If there is only one ID, use the = operator
40+ eq ["subject_id" ] = subjectIds [0 ]
41+ } else {
42+ // If there are multiple IDs, use the IN operator
43+ eq ["subject_id" ] = subjectIds
44+ }
3145 }
3246
3347 if filter .GetSubject ().GetRelation () != "" {
3448 eq ["subject_relation" ] = filter .GetSubject ().GetRelation ()
3549 }
3650
37- // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
38- // This ensures we don't accidentally update every row in the table.
51+ // If eq is empty, return the original squirrel.SelectBuilder without attaching a WHERE clause.
52+ // This ensures we don't accidentally select every row in the table.
3953 if len (eq ) == 0 {
4054 return sl
4155 }
@@ -51,16 +65,30 @@ func AttributesFilterQueryForSelectBuilder(sl squirrel.SelectBuilder, filter *ba
5165 eq ["entity_type" ] = filter .GetEntity ().GetType ()
5266 }
5367
54- if len (filter .GetEntity ().GetIds ()) > 0 {
55- eq ["entity_id" ] = filter .GetEntity ().GetIds ()
68+ entityIds := filter .GetEntity ().GetIds ()
69+ if len (entityIds ) > 0 {
70+ if len (entityIds ) == 1 {
71+ // If there is only one ID, use the = operator
72+ eq ["entity_id" ] = entityIds [0 ]
73+ } else {
74+ // If there are multiple IDs, use the IN operator
75+ eq ["entity_id" ] = entityIds
76+ }
5677 }
5778
58- if len (filter .GetAttributes ()) > 0 {
59- eq ["attribute" ] = filter .GetAttributes ()
79+ attributes := filter .GetAttributes ()
80+ if len (attributes ) > 0 {
81+ if len (attributes ) == 1 {
82+ // If there is only one attribute, use the = operator
83+ eq ["attribute" ] = attributes [0 ]
84+ } else {
85+ // If there are multiple attributes, use the IN operator
86+ eq ["attribute" ] = attributes
87+ }
6088 }
6189
62- // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
63- // This ensures we don't accidentally update every row in the table.
90+ // If eq is empty, return the original squirrel.SelectBuilder without attaching a WHERE clause.
91+ // This ensures we don't accidentally select every row in the table.
6492 if len (eq ) == 0 {
6593 return sl
6694 }
@@ -76,8 +104,15 @@ func TuplesFilterQueryForUpdateBuilder(sl squirrel.UpdateBuilder, filter *base.T
76104 eq ["entity_type" ] = filter .GetEntity ().GetType ()
77105 }
78106
79- if len (filter .GetEntity ().GetIds ()) > 0 {
80- eq ["entity_id" ] = filter .GetEntity ().GetIds ()
107+ entityIds := filter .GetEntity ().GetIds ()
108+ if len (entityIds ) > 0 {
109+ if len (entityIds ) == 1 {
110+ // If there is only one ID, use the = operator
111+ eq ["entity_id" ] = entityIds [0 ]
112+ } else {
113+ // If there are multiple IDs, use the IN operator
114+ eq ["entity_id" ] = entityIds
115+ }
81116 }
82117
83118 if filter .GetRelation () != "" {
@@ -88,8 +123,15 @@ func TuplesFilterQueryForUpdateBuilder(sl squirrel.UpdateBuilder, filter *base.T
88123 eq ["subject_type" ] = filter .GetSubject ().GetType ()
89124 }
90125
91- if len (filter .GetSubject ().GetIds ()) > 0 {
92- eq ["subject_id" ] = filter .GetSubject ().GetIds ()
126+ subjectIds := filter .GetSubject ().GetIds ()
127+ if len (subjectIds ) > 0 {
128+ if len (subjectIds ) == 1 {
129+ // If there is only one ID, use the = operator
130+ eq ["subject_id" ] = subjectIds [0 ]
131+ } else {
132+ // If there are multiple IDs, use the IN operator
133+ eq ["subject_id" ] = subjectIds
134+ }
93135 }
94136
95137 if filter .GetSubject ().GetRelation () != "" {
@@ -113,12 +155,26 @@ func AttributesFilterQueryForUpdateBuilder(sl squirrel.UpdateBuilder, filter *ba
113155 eq ["entity_type" ] = filter .GetEntity ().GetType ()
114156 }
115157
116- if len (filter .GetEntity ().GetIds ()) > 0 {
117- eq ["entity_id" ] = filter .GetEntity ().GetIds ()
118- }
119-
120- if len (filter .GetAttributes ()) > 0 {
121- eq ["attribute" ] = filter .GetAttributes ()
158+ entityIds := filter .GetEntity ().GetIds ()
159+ if len (entityIds ) > 0 {
160+ if len (entityIds ) == 1 {
161+ // If there is only one ID, use the = operator
162+ eq ["entity_id" ] = entityIds [0 ]
163+ } else {
164+ // If there are multiple IDs, use the IN operator
165+ eq ["entity_id" ] = entityIds
166+ }
167+ }
168+
169+ attributes := filter .GetAttributes ()
170+ if len (attributes ) > 0 {
171+ if len (attributes ) == 1 {
172+ // If there is only one attribute, use the = operator
173+ eq ["attribute" ] = attributes [0 ]
174+ } else {
175+ // If there are multiple attributes, use the IN operator
176+ eq ["attribute" ] = attributes
177+ }
122178 }
123179
124180 // If eq is empty, return the original squirrel.UpdateBuilder without attaching a WHERE clause.
0 commit comments