Module: Mimi::DB
- Extended by:
- Helpers
- Includes:
- Core::Module
- Defined in:
- lib/mimi/db.rb,
lib/mimi/db/lock.rb,
lib/mimi/db/model.rb,
lib/mimi/db/dictate.rb,
lib/mimi/db/helpers.rb,
lib/mimi/db/version.rb,
lib/mimi/db/extensions.rb,
lib/mimi/db/dictate/dsl.rb,
lib/mimi/db/foreign_key.rb,
lib/mimi/db/lock/mysql_lock.rb,
lib/mimi/db/dictate/explorer.rb,
lib/mimi/db/dictate/migrator.rb,
lib/mimi/db/lock/sqlite_lock.rb,
lib/mimi/db/dictate/schema_diff.rb,
lib/mimi/db/lock/postgresql_lock.rb,
lib/mimi/db/dictate/type_defaults.rb,
lib/mimi/db/dictate/schema_definition.rb
Defined Under Namespace
Modules: Dictate, Extensions, ForeignKey, Helpers, Lock Classes: Model
Constant Summary collapse
- VERSION =
'0.3.4'.freeze
Class Method Summary collapse
- .configure ⇒ Object
-
.connection ⇒ Sequel::<...>::Database
Returns active DB connection.
- .logger ⇒ Object
- .module_manifest ⇒ Object
- .module_path ⇒ Object
-
.sequel_config ⇒ Hash
Returns Sequel connection parameters.
-
.sequel_config_canonical_adapter_name(adapter_name) ⇒ String
Returns a standard Sequel adapter name converted from any variation of adapter names.
- .start ⇒ Object
Methods included from Helpers
all_table_names, clear!, create!, create_if_not_exist!, database_exist?, db_table_names, diff_schema, drop!, execute, model_table_names, models, transaction, update_schema!, with_log_level
Class Method Details
.configure ⇒ Object
62 63 64 65 66 67 |
# File 'lib/mimi/db.rb', line 62 def self.configure(*) super if Mimi.const_defined?(:Application) @logger = Mimi::Application.logger end end |
.connection ⇒ Sequel::<...>::Database
Returns active DB connection
77 78 79 |
# File 'lib/mimi/db.rb', line 77 def self.connection @connection end |
.logger ⇒ Object
69 70 71 |
# File 'lib/mimi/db.rb', line 69 def self.logger @logger ||= Mimi::Logger.new end |
.module_manifest ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mimi/db.rb', line 25 def self.module_manifest { db_adapter: { desc: 'Database adapter ("sqlite3", "postgresql", "mysql" etc)', default: 'sqlite3' }, db_database: { desc: 'Database name (e.g. "tmp/mydb")', # required }, db_host: { desc: 'Database host', default: nil }, db_port: { desc: 'Database port', default: nil }, db_username: { desc: 'Database username', default: nil }, db_password: { desc: 'Database password', default: nil }, db_pool: { desc: 'Database connection pool size', default: 15 }, db_log_level: { desc: 'Logging level for database layer ("debug", "info" etc)', default: 'debug' } } end |
.module_path ⇒ Object
21 22 23 |
# File 'lib/mimi/db.rb', line 21 def self.module_path Pathname.new(__dir__).join('..').join('..'). end |
.sequel_config ⇒ Hash
Returns Sequel connection parameters
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/mimi/db.rb', line 113 def self.sequel_config { adapter: sequel_config_canonical_adapter_name([:db_adapter]), database: [:db_database], host: [:db_host], port: [:db_port], user: [:db_username], password: [:db_password], encoding: [:db_encoding], max_connections: [:db_pool], sql_log_level: [:db_log_level], logger: logger } end |
.sequel_config_canonical_adapter_name(adapter_name) ⇒ String
Returns a standard Sequel adapter name converted from any variation of adapter names.
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mimi/db.rb', line 96 def self.sequel_config_canonical_adapter_name(adapter_name) case adapter_name.to_s.downcase when 'sqlite', 'sqlite3' 'sqlite' when 'postgres', 'postgresql' 'postgres' when 'cockroach', 'cockroachdb' 'cockroachdb' else adapter_name.to_s.downcase end end |