module App::Database
Attributes
db[R]
Public Instance Methods
connected?()
click to toggle source
# File lib/app-database.rb, line 48 def connected? !! ( defined?( Db ) && Db.test_connection ) end
init()
click to toggle source
Ищем секцию настроек Cfg.db
# File lib/app-database.rb, line 18 def init raise ArgumentError.new("Cfg not found!") if ! defined?( ::Cfg ) || ! Cfg.db || Cfg.db.empty? if (! defined? @db ) || ( @db.nil? ) || ( ! @db ) || ( ! @db.test_connection ) Log.debug{ "БД #{ Cfg.db.database }." } Sequel.extension :pg_array, :pg_inet, :pg_json, :pg_json_ops, :pg_array, :pg_array_ops, :pg_row, :pg_hstore, :pg_json_ops Sequel::Model.raise_on_save_failure = false Sequel::Model.plugin :validation_helpers Sequel::Database.extension :pg_inet, :pg_json, :pg_array, :pg_range, :pg_row, :pg_enum counter = Cfg.app.tmout.database_start begin @db = Sequel.connect Cfg.db.to_hash rescue Sequel::DatabaseConnectionError => e Log.error{"Шо-то с базой: #{ ( e.message.dup ).force_encoding('UTF-8') }"} ( counter -= 1 ) > 0 ? ( sleep(1); retry ) : raise end Sequel::Model.db = @db @db.tables.each{ |t| @db.reset_primary_key_sequence t } # Настоящие герои всегда идут в обход @db.freeze if Cfg.env == :production end Kernel.const_set('Db', @db) unless defined?( ::Db ) return @db end
remove()
click to toggle source
# File lib/app-database.rb, line 41 def remove if defined?( Db ) Db.disconnect if @db.test_connection Kernel.send :remove_const, 'Db' end end