Module: MR::ReadModel::Querying::ClassMethods

Defined in:
lib/mr/read_model/querying.rb

Instance Method Summary collapse

Instance Method Details

#build_sql(params = nil) ⇒ Object



37
38
39
# File 'lib/mr/read_model/querying.rb', line 37

def build_sql(params = nil)
  self.relation.build_sql(params)
end

#count(*args) ⇒ Object



33
34
35
# File 'lib/mr/read_model/querying.rb', line 33

def count(*args)
  self.query(*args).count
end

#find(id, params = nil) ⇒ Object



25
26
27
# File 'lib/mr/read_model/querying.rb', line 25

def find(id, params = nil)
  self.new(self.relation.build_for_find(id, params || {}).first!)
end

#find_attr(column = nil) ⇒ Object



41
42
43
44
# File 'lib/mr/read_model/querying.rb', line 41

def find_attr(column = nil)
  self.relation.find_attr = column if !column.nil?
  self.relation.find_attr
end

#from(record_class) ⇒ Object



52
53
54
55
56
# File 'lib/mr/read_model/querying.rb', line 52

def from(record_class)
  relation.from(record_class)
rescue ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#from_subquery(&block) ⇒ Object



58
59
60
61
62
# File 'lib/mr/read_model/querying.rb', line 58

def from_subquery(&block)
  relation.from_subquery(&block)
rescue ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#full_outer_join_subquery(&block) ⇒ Object Also known as: full_join_subquery



90
91
92
93
94
# File 'lib/mr/read_model/querying.rb', line 90

def full_outer_join_subquery(&block)
  add_subquery_expression(:joins, :full, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#group(*args, &block) ⇒ Object



109
110
111
112
113
# File 'lib/mr/read_model/querying.rb', line 109

def group(*args, &block)
  add_query_expression(:group, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#having(*args, &block) ⇒ Object



115
116
117
118
119
# File 'lib/mr/read_model/querying.rb', line 115

def having(*args, &block)
  add_query_expression(:having, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#inner_join_subquery(&block) ⇒ Object



70
71
72
73
74
# File 'lib/mr/read_model/querying.rb', line 70

def inner_join_subquery(&block)
  add_subquery_expression(:joins, :inner, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#joins(*args, &block) ⇒ Object



64
65
66
67
68
# File 'lib/mr/read_model/querying.rb', line 64

def joins(*args, &block)
  add_query_expression(:joins, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#left_outer_join_subquery(&block) ⇒ Object Also known as: left_join_subquery



76
77
78
79
80
# File 'lib/mr/read_model/querying.rb', line 76

def left_outer_join_subquery(&block)
  add_subquery_expression(:joins, :left, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#limit(*args, &block) ⇒ Object



121
122
123
124
125
# File 'lib/mr/read_model/querying.rb', line 121

def limit(*args, &block)
  add_query_expression(:limit, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#merge(*args, &block) ⇒ Object



133
134
135
136
137
# File 'lib/mr/read_model/querying.rb', line 133

def merge(*args, &block)
  add_merge_query_expression(:merge, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#offset(*args, &block) ⇒ Object



127
128
129
130
131
# File 'lib/mr/read_model/querying.rb', line 127

def offset(*args, &block)
  add_query_expression(:offset, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#order(*args, &block) ⇒ Object



103
104
105
106
107
# File 'lib/mr/read_model/querying.rb', line 103

def order(*args, &block)
  add_merge_query_expression(:order, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#query(params = nil) ⇒ Object



29
30
31
# File 'lib/mr/read_model/querying.rb', line 29

def query(params = nil)
  MR::Query.new(self, self.relation.build_for_all(params || {}))
end

#record_classObject



21
22
23
# File 'lib/mr/read_model/querying.rb', line 21

def record_class
  self.relation.from_record_class
end

#relationObject



17
18
19
# File 'lib/mr/read_model/querying.rb', line 17

def relation
  @relation ||= Relation.new
end

#right_outer_join_subquery(&block) ⇒ Object Also known as: right_join_subquery



83
84
85
86
87
# File 'lib/mr/read_model/querying.rb', line 83

def right_outer_join_subquery(&block)
  add_subquery_expression(:joins, :right, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#select(*args, &block) ⇒ Object



46
47
48
49
50
# File 'lib/mr/read_model/querying.rb', line 46

def select(*args, &block)
  add_query_expression(:select, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end

#where(*args, &block) ⇒ Object



97
98
99
100
101
# File 'lib/mr/read_model/querying.rb', line 97

def where(*args, &block)
  add_merge_query_expression(:where, *args, &block)
rescue InvalidQueryExpressionError, ArgumentError => exception
  raise ArgumentError, exception.message, caller
end