Module: JunglePath::DBAccess::IO

Defined in:
lib/jungle_path/db_access/io.rb,
lib/jungle_path/db_access/io/db.rb,
lib/jungle_path/db_access/io/copy.rb,
lib/jungle_path/db_access/io/config.rb,
lib/jungle_path/db_access/io/delete.rb,
lib/jungle_path/db_access/io/insert.rb,
lib/jungle_path/db_access/io/schema.rb,
lib/jungle_path/db_access/io/select.rb,
lib/jungle_path/db_access/io/update.rb,
lib/jungle_path/db_access/io/init_db.rb,
lib/jungle_path/db_access/io/chunked_file_reader.rb

Defined Under Namespace

Modules: InitDB Classes: ChunkedFileReader, Config, Copy, DB, Delete, Insert, Schema, Select, Update

Class Method Summary collapse

Class Method Details

.clone_config(config) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jungle_path/db_access/io.rb', line 66

def self.clone_config(config)
	JunglePath::DBAccess::IO::Config.new(
		name: config.name,
		type: config.type,
		user_name: config.user_name,
		password: config.password,
		host: config.host,
		extensions: config.extensions,
		port: config.port,
		options: config.options
	)
end

.connection(database_type:, user_name:, database_name:, host: "localhost", extensions: [], password: nil, port: nil, options: nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/jungle_path/db_access/io.rb', line 79

def self.connection(database_type:, user_name:, database_name:, host: "localhost", extensions: [], password: nil, port: nil, options: nil)
	Sequel.default_timezone = :utc
	colon_port = ":#{port}" if port
	options = {} unless options
	if password
		puts "Using db connection with explicit password!"
		connection_string = "#{database_type}://#{user_name}:#{password}@#{host}#{colon_port}/#{database_name}"
		puts "connection_string: #{connection_string}."
		db = Sequel.connect(connection_string, options)
		puts "connected."
	else
		puts "no explicit pw."
		connection_string = "#{database_type}://#{user_name}@#{host}#{colon_port}/#{database_name}"
		puts "connection_string: #{connection_string}."
		db = Sequel.connect(connection_string, options)
		puts "connected."
	end
	extensions.each do |extension|
		puts "Adding Sequel extension: #{extension}."
		db.extension extension
	end
	db
end

.connection_from_config(config) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jungle_path/db_access/io.rb', line 17

def self.connection_from_config(config)
	connection(
		database_type: config.type,
		user_name: config.user_name,
		database_name: config.name,
		host: config.host,
		extensions: config.extensions,
		password: config.password,
		port: config.port,
		options: config.options
	)
end

.connection_from_config_unknown_database(config) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/jungle_path/db_access/io.rb', line 30

def self.connection_from_config_unknown_database(config)
	if config.type == 'postgres'
		connection_from_config_use_postgres_db(config)
	elsif config.type == 'tinytds'
		connection_from_config_use_ms_sql_server_db(config)
	else
		throw "Unknown database type: #{config.type}."
	end
end

.connection_from_config_use_ms_sql_server_db(config) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/jungle_path/db_access/io.rb', line 40

def self.connection_from_config_use_ms_sql_server_db(config)
	db = connection(
		database_type: config.type,
		user_name: config.user_name,
		database_name: 'master',
		host: config.host,
		extensions: config.extensions,
		password: config.password,
		port: config.port,
		options: config.options
	)
end

.connection_from_config_use_postgres_db(config) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jungle_path/db_access/io.rb', line 53

def self.connection_from_config_use_postgres_db(config)
	db = connection(
		database_type: config.type,
		user_name: config.user_name,
		database_name: 'postgres',
		host: config.host,
		extensions: config.extensions,
		password: config.password,
		port: config.port,
		options: config.options
	)
end