class Graffiti::Store
API for the RDF storage access similar to DBI or Sequel
Attributes
config[R]
storage configuration in an RdfConfig
object
Public Class Methods
new(db, config)
click to toggle source
initialize class attributes
db is a Sequel database handle
config is a hash of configuraiton options for RdfConfig
# File lib/graffiti/store.rb, line 33 def initialize(db, config) @db = db @config = RdfConfig.new(config) # cache parsed Squish SELECT queries @select_cache = SynCache::Cache.new(nil, 1000) end
Public Instance Methods
assert(query, params={})
click to toggle source
merge Squish query into RDF database
returns list of new ids assigned to blank nodes listed in INSERT section
# File lib/graffiti/store.rb, line 93 def assert(query, params={}) @db.transaction do SquishAssert.new(@config, query).run(@db, params) end end
fetch(query, params={})
click to toggle source
# File lib/graffiti/store.rb, line 58 def fetch(query, params={}) @db.fetch(select(query), params) end
get_property(subject, property)
click to toggle source
get value of subject's property
# File lib/graffiti/store.rb, line 53 def get_property(subject, property) fetch(%{SELECT ?object WHERE (#{property} :subject ?object)}, :subject => subject).get(:object) end
ns_shrink(uriref)
click to toggle source
replace schema uri with a prefix from the configured namespaces
# File lib/graffiti/store.rb, line 47 def ns_shrink(uriref) SquishQuery.ns_shrink(uriref, @config.ns) end
select(query)
click to toggle source
accepts String or pre-parsed SquishQuery
object, caches SQL by String
# File lib/graffiti/store.rb, line 81 def select(query) query.kind_of?(String) and query = @select_cache.fetch_or_add(query) { SquishSelect.new(@config, query) } query.kind_of?(SquishSelect) or raise ProgrammingError, "String or SquishSelect expected" query.to_sql end
select_all(query, limit=nil, offset=nil, params={}, &p)
click to toggle source
get all query answers (similar to DBI#select_all)
# File lib/graffiti/store.rb, line 70 def select_all(query, limit=nil, offset=nil, params={}, &p) ds = fetch(query, params).limit(limit, offset) if block_given? ds.all(&p) else ds.all end end
select_one(query, params={})
click to toggle source
get one query answer (similar to DBI#select_one)
# File lib/graffiti/store.rb, line 64 def select_one(query, params={}) fetch(query, params).first end