Class: Og::MysqlStore
Overview
A Store that persists objects into a MySQL database. To read documentation about the methods, consult the documentation for SqlStore and Store.
Instance Attribute Summary
Attributes inherited from SqlStore
Attributes inherited from Store
#options, #transaction_nesting
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#commit ⇒ Object
Commit a transaction.
- #enchant(klass, manager) ⇒ Object
- #exec(sql) ⇒ Object
-
#initialize(options) ⇒ MysqlStore
constructor
A new instance of MysqlStore.
- #query(sql) ⇒ Object
-
#rollback ⇒ Object
Rollback a transaction.
- #start ⇒ Object
Methods included from MysqlUtils
Methods included from SqlUtils
#date, #escape, #join_table, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote, #table, #timestamp
Methods inherited from SqlStore
#count, #enable_logging, #find, #find_one, #join, #load, #reload, #unjoin, #update, #update_properties
Methods inherited from Store
#count, #delete, #find, for_name, #insert, #load, #reload, #save, #transaction, #update, #update_properties
Constructor Details
#initialize(options) ⇒ MysqlStore
Returns a new instance of MysqlStore.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/og/store/mysql.rb', line 87 def initialize() super @typemap.update(TrueClass => 'tinyint') @conn = Mysql.connect( [:address] || 'localhost', [:user], [:password], [:name] ) rescue => ex if ex.errno == 1049 # database does not exist. Logger.info "Database '#{[:name]}' not found!" self.class.create() retry end raise end |
Class Method Details
.create(options) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/og/store/mysql.rb', line 72 def self.create() # gmosx: system is used to avoid shell expansion. system 'mysqladmin', '-f', "--user=#{[:user]}", "--password=#{[:password]}", 'create', [:name] super end |
.destroy(options) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/og/store/mysql.rb', line 80 def self.destroy() system 'mysqladmin', '-f', "--user=#{[:user]}", "--password=#{[:password]}", 'drop', [:name] super end |
Instance Method Details
#close ⇒ Object
107 108 109 110 |
# File 'lib/og/store/mysql.rb', line 107 def close @conn.close super end |
#commit ⇒ Object
Commit a transaction.
140 141 142 143 |
# File 'lib/og/store/mysql.rb', line 140 def commit # nop, not supported? # FIXME: InnoDB supports transactions. end |
#enchant(klass, manager) ⇒ Object
112 113 114 115 |
# File 'lib/og/store/mysql.rb', line 112 def enchant(klass, manager) klass.property :oid, Fixnum, :sql => 'integer AUTO_INCREMENT PRIMARY KEY' super end |
#exec(sql) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/og/store/mysql.rb', line 125 def exec(sql) # Logger.debug sql if $DBG @conn.query_with_result = false @conn.query(sql) rescue => ex handle_sql_exception(ex, sql) end |
#query(sql) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/og/store/mysql.rb', line 117 def query(sql) # Logger.debug sql if $DBG @conn.query_with_result = true return @conn.query(sql) rescue => ex handle_sql_exception(ex, sql) end |
#rollback ⇒ Object
Rollback a transaction.
147 148 149 150 |
# File 'lib/og/store/mysql.rb', line 147 def rollback # nop, not supported? # FIXME: InnoDB supports transactions. end |
#start ⇒ Object
133 134 135 136 |
# File 'lib/og/store/mysql.rb', line 133 def start # nop # FIXME: InnoDB supports transactions. end |