data_conduit 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4728fe7837c0f6320159cbfe98a9055b3b133455fde00f4b3405dea927c73118
4
- data.tar.gz: c80098e893921f812450dfb165fb652b68a4e2777b1720da2ec88b47218bda0e
3
+ metadata.gz: d521831adb1cee94daa5c95fb4e29f039ee0a31f0fe77dd4126b43ad6cf653ff
4
+ data.tar.gz: e9cfc515a02cc8031777b4d581accf35a6db0d36dc35f17fa8d872be39035edd
5
5
  SHA512:
6
- metadata.gz: e90575c8f67573c1db6907ee57bb3a36abc1f858edced91aa62056fce051d2d545a7ca09403554f8f2f9bcf1bd10eaf1f7547ab081bda3c3517aa1b3bb59f863
7
- data.tar.gz: 2ad16dba62af7f45c686aff12ba5916d33220d16b6054bd3d5b21d89b4c773521035f2083c316d3b1d595dbf449686aa76f0f95a0ed22f216799bf3250bbd588
6
+ metadata.gz: f7b17a1a849e8152013ffbc78bde9129a7bbdb535b061522d1447c1210af23dbdb11c14b3c57edcc79c8ba716ae1d0551db183c0270b2f4099535571432f2065
7
+ data.tar.gz: 505302e548bcf2796bc09acea5c6bf9a60ace419617401b0dc17be31785f8366dc87ad2a093a7693bb1550a28693da87eaef191237477b26565946f21f28f4e4
@@ -25,16 +25,29 @@ module DataConduit
25
25
  validate_config!
26
26
  end
27
27
 
28
+ def self.tables(config)
29
+ repo = new(nil, nil, config)
30
+ response_data = repo.send(:response_to, "SHOW tables")
31
+ response_data[:result_data]&.flatten&.sort
32
+ end
33
+
28
34
  def query(sql_query = nil)
29
35
  sql_query ||= build_query
30
36
  execute(sql_query)
31
37
  end
32
38
 
33
39
  def execute(sql_query)
34
- response_data = process_response(send_query(sql_query))
40
+ response_data = response_to(sql_query)
35
41
  transform_response(response_data[:result_data], response_data[:result_columns])
36
42
  end
37
43
 
44
+ def last_updated
45
+ response_data = response_to("SELECT made_current_at FROM \"#{table_name}$history\" " \
46
+ "ORDER BY made_current_at DESC LIMIT 1")
47
+ datetime_string = response_data[:result_data]&.flatten&.first
48
+ datetime_string.nil? ? nil : DateTime.parse(datetime_string)
49
+ end
50
+
38
51
  private
39
52
 
40
53
  def default_config
@@ -78,16 +91,26 @@ module DataConduit
78
91
  end
79
92
  end
80
93
 
94
+ def response_to(sql)
95
+ process_response(send_query(sql))
96
+ end
97
+
81
98
  def process_response(initial_response)
82
99
  result_data = []
83
100
  result_columns = nil
84
101
  response_data = initial_response
85
102
 
86
103
  while response_data
87
- result_data.concat(response_data["data"]) if response_data["data"]
88
- result_columns ||= response_data["columns"]
89
- next_uri = response_data["nextUri"]
90
- response_data = next_uri ? fetch_next(next_uri) : nil
104
+ if response_data["error"]
105
+ result_data = { "error" => response_data["error"] }
106
+ result_columns = nil
107
+ response_data = nil
108
+ else
109
+ result_data.concat(response_data["data"]) if response_data["data"]
110
+ result_columns ||= response_data["columns"]
111
+ next_uri = response_data["nextUri"]
112
+ response_data = next_uri ? fetch_next(next_uri) : nil
113
+ end
91
114
  end
92
115
 
93
116
  { result_data: result_data, result_columns: result_columns }
@@ -18,6 +18,10 @@ module DataConduit
18
18
  raise NotImplementedError, "You must implement the initialize method"
19
19
  end
20
20
 
21
+ def self.tables(_config = {})
22
+ raise NotImplementedError, "You must implement the tables method"
23
+ end
24
+
21
25
  def query(_sql_query = nil)
22
26
  raise NotImplementedError, "You must implement the query method"
23
27
  end
@@ -26,6 +30,10 @@ module DataConduit
26
30
  raise NotImplementedError, "You must implement the execute method"
27
31
  end
28
32
 
33
+ def last_updated
34
+ raise NotImplementedError, "You must implement the last_updated method"
35
+ end
36
+
29
37
  protected
30
38
 
31
39
  def validate_table_name(table_name)
@@ -39,6 +47,7 @@ module DataConduit
39
47
 
40
48
  def transform_response(result_data, result_columns)
41
49
  return [] if result_data.nil? || result_data.empty?
50
+ return [result_data] if result_data.is_a?(Hash) && result_data["error"]
42
51
 
43
52
  columns = extract_column_names(result_columns)
44
53
  result_data.map do |row|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DataConduit
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_conduit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinicius Dittgen
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 3.6.7
203
+ rubygems_version: 3.6.9
204
204
  specification_version: 4
205
205
  summary: A Ruby connector for data warehouses
206
206
  test_files: []