You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SELECT u.id, u.name, c.type, p.nickname FROM user u JOIN contract c ON u.id = c.user_id AND c.status IN (?, ?, ?) RIGHT OUTER JOIN person p ON u.id = p.user_id AND p.surname LIKE ? WHERE u.modified_at > u.created_at + ?
92
92
// [1 2 5 %Du 86400]
93
93
}
94
+
95
+
funcExampleSelectBuilder_limit_offset() {
96
+
97
+
sb:=NewSelectBuilder()
98
+
sb.Select("*")
99
+
sb.From("user")
100
+
101
+
// first test case: limit and offset < 0
102
+
// will not add LIMIT and OFFSET to either query for MySQL or PostgresSQL
103
+
sb.Limit(-1)
104
+
sb.Offset(-1)
105
+
106
+
pgSQL, _:=sb.BuildWithFlavor(PostgreSQL)
107
+
fmt.Println(pgSQL)
108
+
109
+
mySQL, _:=sb.BuildWithFlavor(MySQL)
110
+
fmt.Println(mySQL)
111
+
112
+
// second test case: limit <= 0 and offset >= 0
113
+
// doesn't add offset for MySQL as limit <= 0
114
+
// just adds offset to PostgresSQL with no limit as it is not specified
115
+
sb.Limit(-1)
116
+
sb.Offset(0)
117
+
118
+
pgSQL, _=sb.BuildWithFlavor(PostgreSQL)
119
+
fmt.Println(pgSQL)
120
+
121
+
mySQL, _=sb.BuildWithFlavor(MySQL)
122
+
fmt.Println(mySQL)
123
+
124
+
// third test case: limit >= 0 and offset >= 0
125
+
// adds offset and limit for MySQL and PostgresSQL, the query will not return a row (hint: can be used to check if table exists)
126
+
sb.Limit(0)
127
+
sb.Offset(0)
128
+
129
+
pgSQL, _=sb.BuildWithFlavor(PostgreSQL)
130
+
fmt.Println(pgSQL)
131
+
132
+
mySQL, _=sb.BuildWithFlavor(MySQL)
133
+
fmt.Println(mySQL)
134
+
135
+
// forth test case: limit >= 0 and offset <= 0
136
+
// adds limit for MySQL and PostgresSQL and omits offset
0 commit comments