Skip to content

Instantly share code, notes, and snippets.

@dnd
Created December 5, 2017 17:21
Show Gist options
  • Save dnd/503958d156ff763eeaa3b4036231e2c3 to your computer and use it in GitHub Desktop.
Save dnd/503958d156ff763eeaa3b4036231e2c3 to your computer and use it in GitHub Desktop.
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (3,'bob smith','2017-11-26');
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (4,'bob jones','2017-11-26');
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (5,'bob ames','2017-11-26');
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (6,'adam','2017-11-27');
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (7,'larry','2017-11-27');
INSERT INTO `new_table` (`id`,`name`,`created_at`) VALUES (8,'hank','2017-11-29');
SELECT *
FROM new_table
where created_at >= '2017-11-26'
and not (created_at <= '2017-11-26' and name <= 'bob ames')
order by created_at, name;
@rmosolgo
Copy link

rmosolgo commented Dec 5, 2017

GraphQL-Pro doesn't know that values in the table are unique together. (I can't think of how it could, unless there was a compound unique key in the database.) So, it will add .order(primary_key => :asc) to the relation.

Assuming you resume pagination after "bob ames", the resulting query will look like this:

SELECT * 
FROM new_table 
where created_at > '2017-11-26' 
  or (created_at = '2017-11-26' and name  > 'bob ames') 
  or (created_at = '2017-11-26' and name = 'bob ames' and id > 5)
order by created_at, name, id;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment