Class: Graffiti::SqlMapper
- Inherits:
-
Object
- Object
- Graffiti::SqlMapper
- Includes:
- Debug
- Defined in:
- lib/graffiti/sql_mapper.rb
Overview
Transform RDF query pattern graph into a relational join expression.
Instance Attribute Summary collapse
-
#clauses ⇒ Object
readonly
map clause position to table, field, and table alias.
-
#from ⇒ Object
readonly
list of tables for FROM clause of SQL query.
-
#nodes ⇒ Object
readonly
map node to list of positions in clauses.
-
#where ⇒ Object
readonly
conditions for WHERE clause of SQL query.
Instance Method Summary collapse
-
#bind(node) ⇒ Object
return node’s binding, raise exception if the node isn’t bound.
-
#initialize(config, pattern, negative = [], optional = [], global_filter = '') ⇒ SqlMapper
constructor
A new instance of SqlMapper.
Constructor Details
#initialize(config, pattern, negative = [], optional = [], global_filter = '') ⇒ SqlMapper
Returns a new instance of SqlMapper.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/graffiti/sql_mapper.rb', line 97 def initialize(config, pattern, negative = [], optional = [], global_filter = '') @config = config @global_filter = global_filter check_graph(pattern) negative.empty? or check_graph(pattern + negative) optional.empty? or check_graph(pattern + optional) map_predicates(pattern, negative, optional) transform generate_tables_and_conditions @jc = @aliases = @ac = @global_filter = nil end |
Instance Attribute Details
#clauses ⇒ Object (readonly)
map clause position to table, field, and table alias
position => {
:subject => {
:node => node,
:field => field
},
:object => {
:node => node,
:field => field
},
:map => RdfPropertyMap,
:bind_mode => < :must_bind | :may_bind | :must_not_bind >,
:alias => alias
}
128 129 130 |
# File 'lib/graffiti/sql_mapper.rb', line 128 def clauses @clauses end |
#from ⇒ Object (readonly)
list of tables for FROM clause of SQL query
144 145 146 |
# File 'lib/graffiti/sql_mapper.rb', line 144 def from @from end |
#nodes ⇒ Object (readonly)
map node to list of positions in clauses
node => {
:positions => [
{ :clause => position, :role => < :subject | :object > }
],
:bind_mode => < :must_bind | :may_bind | :must_not_bind >,
:colors => { color1 => bind_mode1, ... },
:ground => < true | false >
}
141 142 143 |
# File 'lib/graffiti/sql_mapper.rb', line 141 def nodes @nodes end |
#where ⇒ Object (readonly)
conditions for WHERE clause of SQL query
147 148 149 |
# File 'lib/graffiti/sql_mapper.rb', line 147 def where @where end |
Instance Method Details
#bind(node) ⇒ Object
return node’s binding, raise exception if the node isn’t bound
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/graffiti/sql_mapper.rb', line 151 def bind(node) (@nodes[node] and @bindings[node] and (binding = @bindings[node].first) ) or raise ProgrammingError, "Node '#{node}' is not bound by the query pattern" @nodes[node][:positions].each do |p| if :object == p[:role] and @clauses[ p[:clause] ][:map].subproperty_of property = @clauses[ p[:clause] ][:map].property return %{select_subproperty(#{binding}, #{bind(property)})} end end binding end |