Module: DataMapper::SQLFinders
- Defined in:
- lib/data_mapper/sql_finders.rb,
lib/data_mapper/sql_finders/query.rb,
lib/data_mapper/sql_finders/version.rb,
lib/data_mapper/sql_finders/sql_parser.rb,
lib/data_mapper/sql_finders/sql_builder.rb,
lib/data_mapper/sql_finders/table_representation.rb
Defined Under Namespace
Classes: Query, SQLBuilder, SQLParser, TableRepresentation
Constant Summary
collapse
- VERSION =
"0.0.3"
Instance Method Summary
collapse
Instance Method Details
#by_sql(*additional_models, &block) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/data_mapper/sql_finders.rb', line 8
def by_sql(*additional_models, &block)
options = if additional_models.last.kind_of?(Hash)
additional_models.pop
else
{}
end
sql, *bind_values = sql(self, *additional_models, &block)
parts = SQLParser.new(sql).parse
options[:limit] ||= parts[:limit] if parts[:limit]
options[:offset] ||= parts[:offset] if parts[:offset]
Collection.new(Query.new(repository, self, options).tap { |q| q.send(:sql=, parts, bind_values) })
end
|
#default_order(repository_name = default_repository_name) ⇒ Object
24
25
26
|
# File 'lib/data_mapper/sql_finders.rb', line 24
def default_order(repository_name = default_repository_name)
Array(super).map { |d| Query::DefaultDirection.new(d) }.freeze
end
|
#sql(*models) {|TableRepresentation.from_models(*models)| ... } ⇒ Object
3
4
5
6
|
# File 'lib/data_mapper/sql_finders.rb', line 3
def sql(*models)
raise ArgumentError, "Block required" unless block_given?
yield *TableRepresentation.from_models(*models)
end
|