Class: Og::SqliteStore

Inherits:
SqlStore show all
Defined in:
lib/og/store/sqlite.rb

Overview

A Store that persists objects into an Sqlite3 database. To read documentation about the methods, consult the documentation for SqlStore and Store.

Instance Attribute Summary

Attributes inherited from SqlStore

#conn

Attributes inherited from Store

#options, #transaction_nesting

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SqlStore

#count, #enable_logging, #find, #find_one, #join, #load, #reload, #unjoin, #update, #update_properties

Methods included from SqlUtils

#date, #escape, #join_table, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote, #table, #timestamp

Methods inherited from Store

#count, create, #delete, #find, for_name, #insert, #load, #reload, #save, #transaction, #update, #update_properties

Constructor Details

#initialize(options) ⇒ SqliteStore

Returns a new instance of SqliteStore.



54
55
56
57
# File 'lib/og/store/sqlite.rb', line 54

def initialize(options)
	super
	@conn = SQLite3::Database.new(self.class.db_filename(options))
end

Class Method Details

.db_filename(options) ⇒ Object

Override if needed.



41
42
43
# File 'lib/og/store/sqlite.rb', line 41

def self.db_filename(options)
	"#{options[:name]}.db"
end

.destroy(options) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/og/store/sqlite.rb', line 45

def self.destroy(options)
	begin
		FileUtils.rm(db_filename(options))	
		super
	rescue Object
		Logger.info "Cannot drop '#{options[:name]}'!"
	end
end

Instance Method Details

#closeObject



59
60
61
62
63
# File 'lib/og/store/sqlite.rb', line 59

def close
# FIXME: problems when closing due to unfinalised statements.
#		@conn.close
	super
end

#commitObject



89
90
91
92
# File 'lib/og/store/sqlite.rb', line 89

def commit
	@transaction_nesting -= 1
	@conn.commit if @transaction_nesting < 1
end

#enchant(klass, manager) ⇒ Object



65
66
67
68
# File 'lib/og/store/sqlite.rb', line 65

def enchant(klass, manager)
	klass.property :oid, Fixnum, :sql => 'integer PRIMARY KEY'
	super
end

#exec(sql) ⇒ Object



77
78
79
80
81
82
# File 'lib/og/store/sqlite.rb', line 77

def exec(sql)
	Logger.debug sql if $DBG
	@conn.query(sql).close
rescue => ex
	handle_sql_exception(ex, sql)
end

#query(sql) ⇒ Object



70
71
72
73
74
75
# File 'lib/og/store/sqlite.rb', line 70

def query(sql)
	Logger.debug sql if $DBG
	return @conn.query(sql)
rescue => ex
	handle_sql_exception(ex, sql)
end

#rollbackObject



94
95
96
97
# File 'lib/og/store/sqlite.rb', line 94

def rollback
	@transaction_nesting -= 1
	@conn.rollback if @transaction_nesting < 1
end

#startObject



84
85
86
87
# File 'lib/og/store/sqlite.rb', line 84

def start
	@conn.transaction if @transaction_nesting < 1
	@transaction_nesting += 1
end