Skip to content

Instantly share code, notes, and snippets.

@ShopifyEng
Created March 18, 2021 12:47
Show Gist options
  • Save ShopifyEng/85431ef6f759786429cf4f32464bdca1 to your computer and use it in GitHub Desktop.
Save ShopifyEng/85431ef6f759786429cf4f32464bdca1 to your computer and use it in GitHub Desktop.
Repository Pattern
# Consumer 2 Logic
require 'pricing_engine'
module StorefrontRenderer
class PricingRepository < PricingEngine::PricingRepositoryInterface
def variants_by_ids(ids)
variants = DataStoreConnection.execute("SELECT title, price FROM variants WHERE id in (?)", ids).limit(50)
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) }
end
def variants_by_titles(titles)
variants = DataStoreConnection.execute("SELECT title, price FROM variants WHERE name in (?)", titles).limit(50)
variants.map { |variant| PricingEngine::Schema::Variant.new(title: variant.title, price: variant.price) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment