gloo-lang 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6fb484cd2e5faaa8242211141633af07c599895b2eb381ea082eced44d8f34af
4
- data.tar.gz: fbc868966050778f392b7629febf82a18378a5f6970710d71c9ec4167ffb3a4f
3
+ metadata.gz: a72f890d762fc81128cf2e0108ac3659e50577cfbe7bac14c65fd6a9a2a2054d
4
+ data.tar.gz: 76ce6d65e94e17e2640393e24380fdaef4652aa03a27e1ccc8cb152fdff69f25
5
5
  SHA512:
6
- metadata.gz: 1234d3e6413ccd0def80cf023c5d7733e29993cc0025c91b948b875643c640785100a1598207aa5f45381cff46be51db46ec3764d2ca39dd10c47202c388c38b
7
- data.tar.gz: df8136cd373b4922682779b91c4523976ee3ffcc0c3376fccc160328ec4f6e7163bec0c4cc682c6450e3cde55368fe7b5d9ad6b3afe4e8b674a45cd6dd6d4459
6
+ metadata.gz: a202a6d526985f7aa570a2ec4e74727dbe3cdaec06e4984d8bc0b1017dd536c25eb4e5ce87376783e7405d5d410c6b093960a96c57c1e2d1521317aef10286ca
7
+ data.tar.gz: 3861b2af545bd83c23a336010185eac174504d3412bf22c839600c71c15e084497d5d86ee7e47a52bc2fc7be15a2a9cbb5a23716ad62f7ca91d96d22e7e5fa47
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.5
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo-lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-14 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -261,7 +261,6 @@ files:
261
261
  - lib/gloo_lang/objs/ctrl/each.rb
262
262
  - lib/gloo_lang/objs/ctrl/repeat.rb
263
263
  - lib/gloo_lang/objs/data/markdown.rb
264
- - lib/gloo_lang/objs/data/query.rb
265
264
  - lib/gloo_lang/objs/data/table.rb
266
265
  - lib/gloo_lang/objs/dt/date.rb
267
266
  - lib/gloo_lang/objs/dt/datetime.rb
@@ -1,212 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A SQL database query.
5
- # Relies on a database connection object.
6
- #
7
-
8
- module GlooLang
9
- module Objs
10
- class Query < GlooLang::Core::Obj
11
-
12
- KEYWORD = 'query'.freeze
13
- KEYWORD_SHORT = 'sql'.freeze
14
-
15
- DB = 'database'.freeze
16
- SQL = 'sql'.freeze
17
- RESULT = 'result'.freeze
18
- PARAMS = 'params'.freeze
19
-
20
- DB_MISSING_ERR = 'The database connection is missing!'.freeze
21
-
22
- #
23
- # The name of the object type.
24
- #
25
- def self.typename
26
- return KEYWORD
27
- end
28
-
29
- #
30
- # The short name of the object type.
31
- #
32
- def self.short_typename
33
- return KEYWORD_SHORT
34
- end
35
-
36
- # ---------------------------------------------------------------------
37
- # Children
38
- # ---------------------------------------------------------------------
39
-
40
- #
41
- # Does this object have children to add when an object
42
- # is created in interactive mode?
43
- # This does not apply during obj load, etc.
44
- #
45
- def add_children_on_create?
46
- return true
47
- end
48
-
49
- #
50
- # Add children to this object.
51
- # This is used by containers to add children needed
52
- # for default configurations.
53
- #
54
- def add_default_children
55
- fac = @engine.factory
56
- fac.create_alias DB, nil, self
57
- fac.create_string SQL, nil, self
58
- fac.create_can RESULT, self
59
- end
60
-
61
- # ---------------------------------------------------------------------
62
- # Messages
63
- # ---------------------------------------------------------------------
64
-
65
- #
66
- # Get a list of message names that this object receives.
67
- #
68
- def self.messages
69
- return super + [ 'run' ]
70
- end
71
-
72
- #
73
- # SSH to the host and execute the command, then update result.
74
- #
75
- def msg_run
76
- db = db_obj
77
- unless db
78
- @engine.err DB_MISSING_ERR
79
- return
80
- end
81
-
82
- result = db.query( sql_value, param_array )
83
- process_result result
84
- end
85
-
86
- # ---------------------------------------------------------------------
87
- # Show Results
88
- # ---------------------------------------------------------------------
89
-
90
- #
91
- # The first row will be a header row,
92
- # so if there are exactly 2 rows, then we have only
93
- # a single row of data.
94
- #
95
- def single_row_result?( data )
96
- return data.count == 2
97
- end
98
-
99
- #
100
- # Show a single row in a vertical, form style view.
101
- #
102
- def show_single_row( data )
103
- head = data[0]
104
- row = data[1]
105
-
106
- head.each_with_index do |h, i|
107
- puts "#{h}: \t #{row[i]}"
108
- end
109
- end
110
-
111
- #
112
- # Show multiple rows in a table view.
113
- #
114
- def show_rows( data )
115
- data.each_with_index do |row, i|
116
- # Show header for the first row
117
- puts row.map { |k, _| k }.join( " \t " ).white if i.zero?
118
-
119
- # Show the row data
120
- puts row.map { |_, v| v }.join( " \t " )
121
- end
122
- end
123
-
124
- # ---------------------------------------------------------------------
125
- # Private functions
126
- # ---------------------------------------------------------------------
127
-
128
- private
129
-
130
- #
131
- # Get the database connection.
132
- #
133
- def db_obj
134
- o = find_child DB
135
- return GlooLang::Objs::Alias.resolve_alias( @engine, o )
136
- end
137
-
138
- #
139
- # Get the SQL from the child object.
140
- # Returns nil if there is none.
141
- #
142
- def sql_value
143
- o = find_child SQL
144
- return nil unless o
145
-
146
- return o.value
147
- end
148
-
149
- #
150
- # Do something with the result of the SQL Query call.
151
- # If there's a result container, we'll create objects in it.
152
- # If not, we'll just show the output in the console.
153
- #
154
- def process_result( data )
155
- r = find_child RESULT
156
- if r
157
- update_result_contaier data
158
- else
159
- show_result data
160
- end
161
- end
162
-
163
- #
164
- # Get the arrya of parameters.
165
- # If there is no PARAM container of if it is empty,
166
- # we'll return a nil value.
167
- #
168
- def param_array
169
- o = find_child PARAMS
170
- return nil unless o
171
-
172
- return nil if o.child_count.zero?
173
-
174
- params = []
175
- o.children.each do |p|
176
- params << p.value
177
- end
178
-
179
- return params
180
- end
181
-
182
- #
183
- # Show the result of the query in the console.
184
- #
185
- def show_result( data )
186
- return if data.nil?
187
-
188
- if single_row_result?( data )
189
- show_single_row( data )
190
- else
191
- show_rows( data )
192
- end
193
- end
194
-
195
- #
196
- # Update the result container with the data from the query.
197
- #
198
- def update_result_contaier( data )
199
- r = find_child RESULT
200
- r = GlooLang::Objs::Alias.resolve_alias( @engine, r )
201
- data.each_with_index do |row, i|
202
- can = r.find_add_child( i.to_s, 'can' )
203
- row.each do |k, v|
204
- o = can.find_add_child( k, 'untyped' )
205
- o.set_value v
206
- end
207
- end
208
- end
209
-
210
- end
211
- end
212
- end