From d3b97633a7d0fd7cfabfd3c2f16bc3ca4f198a17 Mon Sep 17 00:00:00 2001 From: Vassil Kovatchev Date: Sun, 9 Dec 2018 16:57:10 -0500 Subject: [PATCH] Add support for azure databases --- bin/slacker | 6 ++---- lib/slacker/application.rb | 3 ++- lib/slacker/configuration.rb | 16 ++++++++++++++-- lib/slacker_new/project/database.yml | 4 ++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bin/slacker b/bin/slacker index 921bae1..0ad3617 100755 --- a/bin/slacker +++ b/bin/slacker @@ -14,8 +14,6 @@ end # Preset the application to run on the console Slacker.configure do |config| - config.console_enabled = true - # Setup the target connection based on the contents in database.yml db_config = db_config_from_file(config.expand_path('database.yml')) @@ -25,8 +23,8 @@ Slacker.configure do |config| config.db_password = db_config["password"] config.db_port = db_config["port"] if !!db_config["port"] config.db_driver = db_config["driver"] if !!db_config["driver"] - # Override console_enabled value with the value from configuration yaml - config.console_enabled = db_config["console_enabled"] if db_config["console_enabled"] != nil + config.azure = db_config["azure"] if !!db_config["azure"] + config.console_enabled = db_config["console_enabled"] if !!db_config["console_enabled"] end if Slacker.application.run diff --git a/lib/slacker/application.rb b/lib/slacker/application.rb index 057e52d..b0249ba 100644 --- a/lib/slacker/application.rb +++ b/lib/slacker/application.rb @@ -165,7 +165,8 @@ def configure_db_tiny_tds :password => @configuration.db_password, :host => @configuration.db_server, :database => @configuration.db_name, - :port => @configuration.db_port + :port => @configuration.db_port, + :azure => @configuration.azure @database.query_options[:symbolize_keys] = true rescue TinyTds::Error => e diff --git a/lib/slacker/configuration.rb b/lib/slacker/configuration.rb index 03f875a..9dcce16 100644 --- a/lib/slacker/configuration.rb +++ b/lib/slacker/configuration.rb @@ -1,9 +1,19 @@ module Slacker class Configuration - attr_accessor :base_dir, :error_stream, :output_stream, :formatter, :db_server, :db_name, :db_user, :db_password, :db_port, :db_driver, :console_enabled + attr_accessor :base_dir, + :error_stream, + :output_stream, + :formatter, + :db_server, + :db_name, + :db_user, + :db_password, + :db_port, + :db_driver, + :azure, + :console_enabled def initialize - @console_enabled = true @base_dir = Dir.pwd @error_stream = nil @output_stream = nil @@ -15,6 +25,8 @@ def initialize @db_password = nil @db_port = 1433 @db_driver = 'odbc' + @azure = false + @console_enabled = true end def expand_path(path) diff --git a/lib/slacker_new/project/database.yml b/lib/slacker_new/project/database.yml index 8fc3640..7a09b0f 100644 --- a/lib/slacker_new/project/database.yml +++ b/lib/slacker_new/project/database.yml @@ -7,6 +7,10 @@ # See https://github.com/vassilvk/slacker/wiki/Slacker-Project#odbc-vs-tds for more information. driver: odbc +# Enable connections to azure databases. +# Applies only to tiny_tds driver. +azure: false + # Full instance name when using odbc; hostname or IP when using tiny_tds. server: my_server