- if cursor != nil {
- params = append(params, cursor.Collection, cursor.Read, cursor.Key, cursor.UserID)
- query += " WHERE (collection, read, key, user_id) > ($1, $2, $3, $4)"
- }
- params = append(params, limit+1)
- query += " ORDER BY collection ASC, read ASC, key ASC, user_id ASC LIMIT $" + strconv.Itoa(len(params))
- case in.Collection == "" && in.Key == "" && userID != nil:
- // Filtering by user ID only returns all results, no pagination or limit.
- limit = 0
- params = []interface{}{*userID}
- query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE user_id = $1"
- case in.Collection != "" && in.Key == "" && userID == nil:
- // Collection only. Querying and paginating on primary key (collection, read, key, user_id).
- params = []interface{}{in.Collection}
- query = "SELECT collection, key, user_id, version, read, write, create_time, update_time FROM storage WHERE collection = $1"
- if cursor != nil {
- params = append(params, cursor.Read, cursor.Key, cursor.UserID)
- query += " AND (collection, read, key, user_id) > ($1, $2, $3, $4)"
- }
- params = append(params, limit+1)
- query += " ORDER BY read ASC, key ASC, user_id ASC LIMIT $" + strconv.Itoa(len(params))