class Baza::Driver::Sqlite3Rhodes
This class handels SQLite3-specific behaviour.
Attributes
mutex_statement_reader[R]
Public Class Methods
from_object(args)
click to toggle source
Helper to enable automatic registering of database using Baza::Db.from_object
# File lib/baza/driver/sqlite3_rhodes.rb, line 8 def self.from_object(args) if args[:object].class.name == "SQLite3::Database" return { type: :success, args: { type: :sqlite3, conn: args[:object] } } end end
new(db)
click to toggle source
Constructor. This should not be called manually.
Calls superclass method
Baza::BaseSqlDriver::new
# File lib/baza/driver/sqlite3_rhodes.rb, line 21 def initialize(db) super @path = @db.opts[:path] if @db.opts[:path] @mutex_statement_reader = Mutex.new if @db.opts[:conn] @conn = @db.opts[:conn] else raise "No path was given." unless @path @conn = ::SQLite3::Database.new(@path, @path) end end
Public Instance Methods
close()
click to toggle source
Closes the connection to the database.
# File lib/baza/driver/sqlite3_rhodes.rb, line 52 def close @mutex_statement_reader.synchronize do @conn.close end end
escape(string)
click to toggle source
Escapes a string to be safe to used in a query.
# File lib/baza/driver/sqlite3_rhodes.rb, line 45 def escape(string) # This code is taken directly from the documentation so we dont have to rely on the SQLite3::Database class. This way it can also be used with JRuby and IronRuby... # http://sqlite-ruby.rubyforge.org/classes/SQLite/Database.html string.to_s.gsub(/'/, "''") end
query(sql)
click to toggle source
Executes a query against the driver.
# File lib/baza/driver/sqlite3_rhodes.rb, line 36 def query(sql) Baza::Driver::Sqlite3::Result.new(self, @conn.execute(sql, sql)) end
query_ubuf(sql)
click to toggle source
# File lib/baza/driver/sqlite3_rhodes.rb, line 40 def query_ubuf(sql) Baza::Driver::Sqlite3::UnbufferedResult.new(self, @conn.prepare(sql)) end
transaction() { |db| ... }
click to toggle source
Starts a transaction, yields the database and commits.
# File lib/baza/driver/sqlite3_rhodes.rb, line 59 def transaction @conn.transaction { yield @db } end