Class: Og::Sqlite2Store
Overview
A Store that persists objects into an Sqlite2 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
#aggregate, #delete_all, #enable_logging, #find, #find_one, #join, #load, #managed_tables, #reload, #select, #select_one, #unjoin, #unmanaged_tables, #update, #update_by_sql, #update_properties
Methods included from SqlUtils
#blob, #build_join_name, #create_join_table_sql, #date, #escape, #join_class_ordering, #join_object_ordering, #join_table, #join_table_index, #join_table_info, #join_table_key, #join_table_keys, #ordered_join_table_keys, #parse_blob, #parse_boolean, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote, #table, #tableize, #timestamp
Methods inherited from Store
#count, create, #delete, #find, for_name, #force_save!, #insert, #load, #reload, #save, #transaction, #update, #update_properties
Constructor Details
Initialize the Sqlite store. This store provides a default name.
62
63
64
65
|
# File 'lib/og/store/sqlite2.rb', line 62
def initialize(options)
super
@conn = SQLite::Database.new(self.class.db_filename(options))
end
|
Class Method Details
.db_filename(options) ⇒ Object
45
46
47
48
|
# File 'lib/og/store/sqlite2.rb', line 45
def self.db_filename(options)
options[:name] ||= 'data'
"#{options[:name]}.db"
end
|
.destroy(options) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/og/store/sqlite2.rb', line 50
def self.destroy(options)
begin
FileUtils.rm(db_filename(options))
super
rescue Object
Logger.info "Cannot drop '#{options[:name]}'!"
end
end
|
Instance Method Details
#close ⇒ Object
67
68
69
70
|
# File 'lib/og/store/sqlite2.rb', line 67
def close
@conn.close
super
end
|
#commit ⇒ Object
101
102
103
104
|
# File 'lib/og/store/sqlite2.rb', line 101
def commit
@transaction_nesting -= 1
@conn.commit if @transaction_nesting < 1
end
|
#enchant(klass, manager) ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/og/store/sqlite2.rb', line 72
def enchant(klass, manager)
if klass.ann.self.primary_key.symbol == :oid
unless klass.properties.include? :oid
klass.property :oid, Fixnum, :sql => 'integer PRIMARY KEY'
end
end
super
end
|
#exec(sql) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/og/store/sqlite2.rb', line 89
def exec(sql)
Logger.debug sql if $DBG
@conn.query(sql).close
rescue => ex
handle_sql_exception(ex, sql)
end
|
#last_insert_rowid ⇒ Object
111
112
113
|
# File 'lib/og/store/sqlite2.rb', line 111
def last_insert_rowid
conn.query("SELECT last_insert_rowid()").first_value.to_i
end
|
#query(sql) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/og/store/sqlite2.rb', line 82
def query(sql)
Logger.debug sql if $DBG
return @conn.query(sql)
rescue Exception => ex
handle_sql_exception(ex, sql)
end
|
#rollback ⇒ Object
106
107
108
109
|
# File 'lib/og/store/sqlite2.rb', line 106
def rollback
@transaction_nesting -= 1
@conn.rollback if @transaction_nesting < 1
end
|
#sql_update(sql) ⇒ Object
115
116
117
118
|
# File 'lib/og/store/sqlite2.rb', line 115
def sql_update(sql)
exec(sql)
@conn.changes
end
|
#start ⇒ Object
96
97
98
99
|
# File 'lib/og/store/sqlite2.rb', line 96
def start
@conn.transaction if @transaction_nesting < 1
@transaction_nesting += 1
end
|