Class: DataDuck::SqlDbSource
Instance Attribute Summary
Attributes inherited from Database
#name
Instance Method Summary
collapse
Methods inherited from Source
load_config!, only_source, #schema, skip_these_table_names, source, source_config
Constructor Details
#initialize(name, data) ⇒ SqlDbSource
Returns a new instance of SqlDbSource.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dataduck/sql_db_source.rb', line 8
def initialize(name, data)
@host = data['host']
@port = data['port']
@username = data['username']
@password = data['password']
@database = data['database']
@initialized_db_type = data['db_type']
super
end
|
Instance Method Details
#connection ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/dataduck/sql_db_source.rb', line 19
def connection
@connection ||= Sequel.connect(
adapter: self.db_type,
user: @username,
host: @host,
database: @database,
password: @password,
port: @port
)
end
|
#db_type ⇒ Object
30
31
32
33
34
|
# File 'lib/dataduck/sql_db_source.rb', line 30
def db_type
return @initialized_db_type if @initialized_db_type
raise NotImplementedError.new("Abstract method db_type must be overwritten by subclass, or passed as data when initializing.")
end
|
#escape_char ⇒ Object
36
37
38
|
# File 'lib/dataduck/sql_db_source.rb', line 36
def escape_char
raise NotImplementedError.new("Abstract method escape_char must be overwritten by subclass.")
end
|
#query(sql) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/dataduck/sql_db_source.rb', line 44
def query(sql)
if self.is_mutating_sql?(sql)
raise ArgumentError.new("Database #{ self.name } must not run mutating sql: #{ sql }")
end
Logs.debug("SQL executing on #{ self.name }:\n " + sql)
self.connection.fetch(sql).all
end
|
#table_names ⇒ Object
40
41
42
|
# File 'lib/dataduck/sql_db_source.rb', line 40
def table_names
self.connection.tables.map { |table| DataDuck::Source.skip_these_table_names.include?(table) ? nil : table }.compact
end
|