Skip to content

Instantly share code, notes, and snippets.

@paulcsmith
Last active May 10, 2017 16:25
Show Gist options
  • Save paulcsmith/5b7ce214219021d9b2f6a350cc90d37a to your computer and use it in GitHub Desktop.
Save paulcsmith/5b7ce214219021d9b2f6a350cc90d37a to your computer and use it in GitHub Desktop.
left_outer_joins(:schedule).where(
"schedules.id IS NULL OR schedules.starts_on <= ?",
Date.current,
)
left_out_joins_schedule.where(&.id == nil).or_where(&.starts_on <= Date.current).where(&.name.lower == "something")
.where(&.rating.avg > 5)
class UserRows
def where(&block)
@wheres << yield UserCriteria.new
end
end
class UserCriteria
def id
LuckyRecord::AdvancedCriteria.new(:id) # can use ==, !=, >, <, >=, <=, .. (range)
end
def rating
LuckyRecord::IntegerCriter.new(:rating) # AdvancedCriteria plus avg, count, min, max
end
def name
LuckyRecord::StringCriteria.new(:name) # can use ==, !=, lower, length (returns an advanced criteria!
end
def created_at
LuckyRecord::DateTimeCriteria.new(:created_at) # Maybe same as AdvancedCriteria, but allows, date_parts and stuff like that
end
end
class LuckyRecord::TimeCriteria
#where(&.created.before 3.days.ago)
def before
end
def after
end
def at_or_before
end
def at_or_after
end
end
@paulcsmith
Copy link
Author

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