class SPARQL::Algebra::Operator::Insert
The SPARQL
UPDATE `insertData` operator.
The INSERT operation is a form of the DELETE/INSERT operation having no DELETE section
@example
(insert ((triple ?s ?p "q")))
Constants
- NAME
Public Instance Methods
execute(queryable, solutions: nil, **options)
click to toggle source
Executes this upate on the given `writable` graph or repository.
@param [RDF::Queryable] queryable
the graph or repository to write
@param [RDF::Query::Solutions] solutions
Solution to map to patterns for this operation
@param [Hash{Symbol => Object}] options
any additional keyword options
@option options [Boolean] debug
Query execution debugging
@return [RDF::Queryable]
Returns queryable.
@raise [IOError]
If `from` does not exist, unless the `silent` operator is present
@see www.w3.org/TR/sparql11-update/
# File lib/sparql/algebra/operator/insert.rb, line 34 def execute(queryable, solutions: nil, **options) # Only binds the first solution solution = solutions.is_a?(RDF::Query::Solutions) ? solutions.first : solutions debug(options) {"Insert"} patterns = operand.inject([]) do |memo, op| if op.respond_to?(:statements) memo += op.statements.to_a else memo << op end memo end patterns.each do |pattern| pattern = pattern.dup.bind(solution) debug(options) {"Insert pattern #{pattern.to_sse}"} # Only insert bound or constant patterns queryable.insert(RDF::Statement.from(pattern)) if pattern.bound? || pattern.constant? end queryable end