gloo 1.2.4 → 1.2.5
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 +4 -4
- data/gloo.gemspec +1 -1
- data/lib/VERSION +1 -1
- data/lib/gloo/objs/data/mysql.rb +5 -3
- data/lib/gloo/objs/data/query.rb +155 -0
- data/lib/gloo/objs/data/query_result.rb +122 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3124373b42fd41dfb3b813d6004ed4a28999179b2d000077a6270aa2c83da134
|
4
|
+
data.tar.gz: 568083d68bde0f76560b7810dbdd22f8ec0a026524ad2bcb82d6bd855d39ddf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bdacb3fcb17db84284e6692498521cff369f7ef0dec2d622259b52d1f47e0fa3f9881344ffc85f15ed239d7f3ebee31579c100d1f9e2d5e804c9bcbe8bd0a85
|
7
|
+
data.tar.gz: a79832408b08efa9f8591cf766d5d3c35fa74743c404014bf73a190bbc7a5b51ee1f559a9240027699b38626e47eebf23770148e40be8d8b038874cac83848c4
|
data/gloo.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
# spec.add_development_dependency 'rake', '~> 10.0'
|
38
38
|
spec.add_development_dependency "rake", '~> 13.0', '>= 13.0.1'
|
39
39
|
|
40
|
-
spec.add_dependency "gloo-lang", '~> 1.2', ">= 1.2.
|
40
|
+
spec.add_dependency "gloo-lang", '~> 1.2', ">= 1.2.5"
|
41
41
|
|
42
42
|
spec.add_dependency "activesupport", '~> 6.1', ">= 6.1.5"
|
43
43
|
# spec.add_dependency "activesupport", '~> 6.1', ">= 6.1.4.6"
|
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.5
|
data/lib/gloo/objs/data/mysql.rb
CHANGED
@@ -121,12 +121,14 @@ module Gloo
|
|
121
121
|
end
|
122
122
|
else
|
123
123
|
rs = client.query( sql, :as => :array )
|
124
|
-
rs
|
125
|
-
|
124
|
+
if rs
|
125
|
+
rs.each do |row|
|
126
|
+
data << row
|
127
|
+
end
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
129
|
-
heads = rs.fields
|
131
|
+
heads = rs.fields if rs
|
130
132
|
return [ heads, data ]
|
131
133
|
end
|
132
134
|
|
@@ -0,0 +1,155 @@
|
|
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 Gloo
|
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
|
+
# Private functions
|
88
|
+
# ---------------------------------------------------------------------
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
#
|
93
|
+
# Get the database connection.
|
94
|
+
#
|
95
|
+
def db_obj
|
96
|
+
o = find_child DB
|
97
|
+
return GlooLang::Objs::Alias.resolve_alias( @engine, o )
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Get the SQL from the child object.
|
102
|
+
# Returns nil if there is none.
|
103
|
+
#
|
104
|
+
def sql_value
|
105
|
+
o = find_child SQL
|
106
|
+
return nil unless o
|
107
|
+
|
108
|
+
return o.value
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Do something with the result of the SQL Query call.
|
113
|
+
# If there's a result container, we'll create objects in it.
|
114
|
+
# If not, we'll just show the output in the console.
|
115
|
+
#
|
116
|
+
def process_result( result )
|
117
|
+
return if result.nil?
|
118
|
+
|
119
|
+
heads = result[0]
|
120
|
+
data = result[1]
|
121
|
+
qr = QueryResult.new heads, data
|
122
|
+
|
123
|
+
result_can = find_child RESULT
|
124
|
+
result_can = GlooLang::Objs::Alias.resolve_alias( @engine, result_can )
|
125
|
+
|
126
|
+
if result_can
|
127
|
+
qr.update_result_container result_can
|
128
|
+
else
|
129
|
+
qr.show
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Get the array of parameters.
|
135
|
+
# If there is no PARAM container of if it is empty,
|
136
|
+
# we'll return a nil value.
|
137
|
+
#
|
138
|
+
def param_array
|
139
|
+
o = find_child PARAMS
|
140
|
+
return nil unless o
|
141
|
+
|
142
|
+
return nil if o.child_count.zero?
|
143
|
+
|
144
|
+
params = []
|
145
|
+
o.children.each do |p|
|
146
|
+
params << p.value
|
147
|
+
end
|
148
|
+
|
149
|
+
return params
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# The result of a SQL database query.
|
5
|
+
#
|
6
|
+
|
7
|
+
module Gloo
|
8
|
+
module Objs
|
9
|
+
class QueryResult
|
10
|
+
|
11
|
+
DB = 'database'.freeze
|
12
|
+
SQL = 'sql'.freeze
|
13
|
+
RESULT = 'result'.freeze
|
14
|
+
PARAMS = 'params'.freeze
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
# ---------------------------------------------------------------------
|
19
|
+
# Set up the Result
|
20
|
+
# ---------------------------------------------------------------------
|
21
|
+
|
22
|
+
#
|
23
|
+
# Create the Result object
|
24
|
+
def initialize( heads, data )
|
25
|
+
@heads = heads
|
26
|
+
@data = data
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# ---------------------------------------------------------------------
|
31
|
+
# Helper Functions
|
32
|
+
# ---------------------------------------------------------------------
|
33
|
+
|
34
|
+
#
|
35
|
+
# Does the data contain a single row?
|
36
|
+
#
|
37
|
+
def single_row_result?
|
38
|
+
return @data.count == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# ---------------------------------------------------------------------
|
43
|
+
# Show Results
|
44
|
+
# ---------------------------------------------------------------------
|
45
|
+
|
46
|
+
#
|
47
|
+
# Show the result of the query
|
48
|
+
#
|
49
|
+
def show
|
50
|
+
single_row_result? ? show_single_row : show_rows
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Show a single row in a vertical, form style view.
|
55
|
+
#
|
56
|
+
def show_single_row
|
57
|
+
row = @data[0]
|
58
|
+
@heads.each_with_index do |h, i|
|
59
|
+
puts "#{h}: \t #{row[i]}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Show multiple rows in a table view.
|
65
|
+
#
|
66
|
+
def show_rows
|
67
|
+
puts @heads.map { |o| o }.join( " \t " ).white
|
68
|
+
|
69
|
+
@data.each do |row|
|
70
|
+
# Show the row data
|
71
|
+
puts row.map { |v| v }.join( " \t " )
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# ---------------------------------------------------------------------
|
76
|
+
# Update results in object(s)
|
77
|
+
# ---------------------------------------------------------------------
|
78
|
+
|
79
|
+
#
|
80
|
+
# Update the result container with the data from the query.
|
81
|
+
#
|
82
|
+
def update_result_container( in_can )
|
83
|
+
@result_can = in_can
|
84
|
+
single_row_result? ? update_single_row : update_rows
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# The result has a single row.
|
89
|
+
# Map values from the result set to objects that are present.
|
90
|
+
#
|
91
|
+
def update_single_row
|
92
|
+
row = @data[0]
|
93
|
+
@heads.each_with_index do |h, i|
|
94
|
+
child = @result_can.find_child h
|
95
|
+
child.set_value row[i] if child
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Put all rows in the result object.
|
101
|
+
#
|
102
|
+
def update_rows
|
103
|
+
@data.each_with_index do |row, i|
|
104
|
+
can = @result_can.find_add_child( i.to_s, 'can' )
|
105
|
+
row.each_with_index do |v, i|
|
106
|
+
o = can.find_add_child( @heads[i], 'untyped' )
|
107
|
+
o.set_value v
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# ---------------------------------------------------------------------
|
113
|
+
# Private functions
|
114
|
+
# ---------------------------------------------------------------------
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Crane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
version: '1.2'
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 1.2.
|
76
|
+
version: 1.2.5
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,7 +83,7 @@ dependencies:
|
|
83
83
|
version: '1.2'
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: 1.2.
|
86
|
+
version: 1.2.5
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: activesupport
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -305,6 +305,8 @@ files:
|
|
305
305
|
- lib/gloo/objs/cli/prompt.rb
|
306
306
|
- lib/gloo/objs/cli/select.rb
|
307
307
|
- lib/gloo/objs/data/mysql.rb
|
308
|
+
- lib/gloo/objs/data/query.rb
|
309
|
+
- lib/gloo/objs/data/query_result.rb
|
308
310
|
- lib/gloo/objs/data/sqlite.rb
|
309
311
|
- lib/gloo/objs/dev/git.rb
|
310
312
|
- lib/gloo/objs/dev/stats.rb
|