-
-
Save akhtarja/ed71ae4caa99793e0e7ce512d1482a39 to your computer and use it in GitHub Desktop.
Blog post 4 - Returning a JSON Field From Rails GraphQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.id = 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = %( | |
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.id = 12 | |
) | |
query_results = ActiveRecord::Base.send(:sanitize_sql_array, query) | |
query_results = ActiveRecord::Base.connection.select_all(query_results).rows | |
query_results #=> [ [12, "My item", 4.99] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = %( | |
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.id = #{item_id} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = %( | |
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.id = ? | |
) | |
query_results = ActiveRecord::Base.send(:sanitize_sql_array, [query, item_id]) | |
query_results = ActiveRecord::Base.connection.select_all(query_results).rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.price > 3 | |
and items.name ~ 'item' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = %( | |
select | |
items.id as ItemId, | |
items.name as ItemName, | |
items.price as ItemPrice | |
from items | |
where items.price > :item_price | |
and items.name ~ :item_name | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::Base.send(:sanitize_sql_array, [query, { item_price: 3, item_name: 'item' }]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment