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, #count, #delete_all, #enable_logging, #find, #find_one, #join, #load, #managed_tables, #prepare_statement, #reload, #select, #select_one, #type_cast, #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, #quote_array, #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.
66
67
68
69
|
# File 'lib/og/store/sqlite2.rb', line 66
def initialize(options)
super
@conn = SQLite::Database.new(self.class.db_filename(options))
end
|
Class Method Details
.db_filename(options) ⇒ Object
49
50
51
52
|
# File 'lib/og/store/sqlite2.rb', line 49
def self.db_filename(options)
options[:name] ||= 'data'
"#{options[:name]}.db"
end
|
.destroy(options) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/og/store/sqlite2.rb', line 54
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
71
72
73
74
|
# File 'lib/og/store/sqlite2.rb', line 71
def close
@conn.close
super
end
|
#commit ⇒ Object
105
106
107
108
|
# File 'lib/og/store/sqlite2.rb', line 105
def commit
@transaction_nesting -= 1
@conn.commit if @transaction_nesting < 1
end
|
#enchant(klass, manager) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/og/store/sqlite2.rb', line 76
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
93
94
95
96
97
98
|
# File 'lib/og/store/sqlite2.rb', line 93
def exec(sql)
Logger.debug sql if $DBG
@conn.query(sql).close
rescue => ex
handle_sql_exception(ex, sql)
end
|
#last_insert_rowid ⇒ Object
115
116
117
|
# File 'lib/og/store/sqlite2.rb', line 115
def last_insert_rowid
conn.query("SELECT last_insert_rowid()").first_value.to_i
end
|
#query(sql) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/og/store/sqlite2.rb', line 86
def query(sql)
Logger.debug sql if $DBG
return @conn.query(sql)
rescue Exception => ex
handle_sql_exception(ex, sql)
end
|
#rollback ⇒ Object
110
111
112
113
|
# File 'lib/og/store/sqlite2.rb', line 110
def rollback
@transaction_nesting -= 1
@conn.rollback if @transaction_nesting < 1
end
|
#sql_update(sql) ⇒ Object
119
120
121
122
|
# File 'lib/og/store/sqlite2.rb', line 119
def sql_update(sql)
exec(sql)
@conn.changes
end
|
#start ⇒ Object
100
101
102
103
|
# File 'lib/og/store/sqlite2.rb', line 100
def start
@conn.transaction if @transaction_nesting < 1
@transaction_nesting += 1
end
|