example/activerecord.rb in jdbc-vertica-0.0.1 vs example/activerecord.rb in jdbc-vertica-0.0.2
- old
+ new
@@ -1,21 +1,35 @@
require 'activerecord-jdbc-adapter'
require 'jdbc-vertica'
+require 'dotenv'
class JdbcTest < ActiveRecord::Base
end
-$username = 'dbadmin'
-$password = '********'
-$host = 'veritica.jp'
+# Create .env file containing
+# HOSTNAME=
+# PORT=
+# DATABASE=
+# USERNAME=
+# PASSWORD=
+Dotenv.load
+config = {
+ hostname: ENV['HOSTNAME'],
+ port: ENV['PORT'] || "5433",
+ username: ENV['USERNAME'],
+ password: ENV['PASSWORD'],
+ database: ENV['DATABASE'] || "vmain",
+}
+puts config
+
Jdbc::Vertica.load_driver
ActiveRecord::Base.establish_connection adapter: 'jdbc',
driver: 'com.vertica.jdbc.Driver',
- url: "jdbc:vertica://#{$host}:5433/",
- username: $username,
- password: $password,
- database: 'vmain',
+ url: "jdbc:vertica://#{config[:hostname]}:#{config[:port]}/",
+ username: config[:username],
+ password: config[:password],
+ database: config[:database],
schema_search_path: 'sandbox'
ActiveRecord::Base.connection.execute "SET search_path TO sandbox;"
p JdbcTest.all