Class: SqlStmt::Query
- Inherits:
-
Object
- Object
- SqlStmt::Query
- Defined in:
- lib/sqlstmt/query.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#wheres ⇒ Object
readonly
Returns the value of attribute wheres.
Instance Method Summary collapse
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #join(table, expr) ⇒ Object
- #join_using(table, *fields) ⇒ Object
- #left_join(table, expr) ⇒ Object
- #left_join_using(table, *fields) ⇒ Object
- #no_where ⇒ Object
- #optional_join(table, expr) ⇒ Object
- #optional_where ⇒ Object
- #table(table) ⇒ Object
- #to_s ⇒ Object
- #where(*sql) ⇒ Object
Constructor Details
#initialize ⇒ Query
10 11 12 13 14 15 16 |
# File 'lib/sqlstmt/query.rb', line 10 def initialize @fields = [] @tables = [] @joins = [] @wheres = [] @where_behavior = :require end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/sqlstmt/query.rb', line 8 def fields @fields end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
8 9 10 |
# File 'lib/sqlstmt/query.rb', line 8 def joins @joins end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
8 9 10 |
# File 'lib/sqlstmt/query.rb', line 8 def tables @tables end |
#wheres ⇒ Object (readonly)
Returns the value of attribute wheres.
8 9 10 |
# File 'lib/sqlstmt/query.rb', line 8 def wheres @wheres end |
Instance Method Details
#join(table, expr) ⇒ Object
23 24 25 26 |
# File 'lib/sqlstmt/query.rb', line 23 def join(table, expr) @joins << ['JOIN', table, "ON #{expr}"] self end |
#join_using(table, *fields) ⇒ Object
34 35 36 37 |
# File 'lib/sqlstmt/query.rb', line 34 def join_using(table, *fields) @joins << ['JOIN', table, "USING (#{fields.join(',')})"] self end |
#left_join(table, expr) ⇒ Object
39 40 41 42 |
# File 'lib/sqlstmt/query.rb', line 39 def left_join(table, expr) @joins << ['LEFT JOIN', table, "ON #{expr}"] self end |
#left_join_using(table, *fields) ⇒ Object
44 45 46 47 |
# File 'lib/sqlstmt/query.rb', line 44 def left_join_using(table, *fields) @joins << ['LEFT JOIN', table, "USING (#{fields.join(',')})"] self end |
#no_where ⇒ Object
54 55 56 57 |
# File 'lib/sqlstmt/query.rb', line 54 def no_where @where_behavior = :exclude self end |
#optional_join(table, expr) ⇒ Object
28 29 30 31 32 |
# File 'lib/sqlstmt/query.rb', line 28 def optional_join(table, expr) unless find_join(table) join(table, expr) end end |
#optional_where ⇒ Object
59 60 61 62 |
# File 'lib/sqlstmt/query.rb', line 59 def optional_where @where_behavior = :optional self end |
#table(table) ⇒ Object
18 19 20 21 |
# File 'lib/sqlstmt/query.rb', line 18 def table(table) @tables << table self end |
#to_s ⇒ Object
64 65 66 67 |
# File 'lib/sqlstmt/query.rb', line 64 def to_s verify_minimum_requirements build_stmt end |
#where(*sql) ⇒ Object
49 50 51 52 |
# File 'lib/sqlstmt/query.rb', line 49 def where(*sql) @wheres.concat(sql) self end |