gloo-mysql 1.0 → 1.2
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/README.md +22 -0
- data/lib/mysql.rb +85 -48
- metadata +88 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a1b5f86ddb44b51299e14599208fb5276529e7675e47decdee1d7572ce28745
|
|
4
|
+
data.tar.gz: 3589a40a1974de5cc576471bfbe5e73008b887157a851f9cde8ee834ed9ce224
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4778f6a9ec72070177b2059267d8421998c7b11f181594211ac9f49daa3c6b2ec2fa2f8105050ea615e285a416f52d317cc3d2017fafedbff36e38285944f990
|
|
7
|
+
data.tar.gz: 18bd34ada82a4fffb813066d3384f7d04f26010c2ddd3e7a149d048bec5423ac92d297162090538276221380131bf8123c62398eb45c57b7ef0f4e96673b9542
|
data/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# gloo-mysql
|
|
2
|
+
|
|
3
|
+
A core gloo library for mysql.
|
|
4
|
+
|
|
5
|
+
Use alongside `gloo-db` — this gem provides the MySQL driver, `gloo-db` provides `query`/`table`.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Load this library in a gloo script:
|
|
10
|
+
|
|
11
|
+
```gloo
|
|
12
|
+
> load lib db
|
|
13
|
+
> load lib mysql
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Objects
|
|
17
|
+
|
|
18
|
+
- `mysql` — a MySQL database connection
|
|
19
|
+
|
|
20
|
+
## Full Reference
|
|
21
|
+
|
|
22
|
+
The object's children and messages are documented in-app once the library is loaded — `help> object mysql`.
|
data/lib/mysql.rb
CHANGED
|
@@ -17,9 +17,13 @@
|
|
|
17
17
|
# flags = opts[:flags] || 0
|
|
18
18
|
#
|
|
19
19
|
require 'mysql2'
|
|
20
|
+
require 'db_connection'
|
|
20
21
|
|
|
21
22
|
class Mysql < Gloo::Core::Obj
|
|
22
23
|
|
|
24
|
+
# Shared driver behaviour from gloo-db: errors, verify, setup problems.
|
|
25
|
+
include DbConnection
|
|
26
|
+
|
|
23
27
|
KEYWORD = 'mysql'.freeze
|
|
24
28
|
KEYWORD_SHORT = 'mysql'.freeze
|
|
25
29
|
|
|
@@ -80,12 +84,22 @@ class Mysql < Gloo::Core::Obj
|
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
#
|
|
83
|
-
#
|
|
87
|
+
# Verify that the database connection can be established.
|
|
88
|
+
# It is true if it can, false if not (with the reason in the error).
|
|
84
89
|
#
|
|
85
90
|
def msg_verify
|
|
86
|
-
|
|
91
|
+
verify_connection do
|
|
92
|
+
client = Mysql2::Client.new( connection_params )
|
|
93
|
+
client.close
|
|
94
|
+
end
|
|
95
|
+
end
|
|
87
96
|
|
|
88
|
-
|
|
97
|
+
#
|
|
98
|
+
# The exception classes that are database errors (DbConnection):
|
|
99
|
+
# Query reports these as 'Query failed: …'.
|
|
100
|
+
#
|
|
101
|
+
def database_errors
|
|
102
|
+
return [ Mysql2::Error ]
|
|
89
103
|
end
|
|
90
104
|
|
|
91
105
|
|
|
@@ -112,13 +126,7 @@ class Mysql < Gloo::Core::Obj
|
|
|
112
126
|
@engine.log.debug "Opening a new Connection."
|
|
113
127
|
end
|
|
114
128
|
|
|
115
|
-
|
|
116
|
-
host: host_value,
|
|
117
|
-
database: db_value,
|
|
118
|
-
username: user_value,
|
|
119
|
-
password: passwd_value
|
|
120
|
-
}
|
|
121
|
-
client = Mysql2::Client.new( h )
|
|
129
|
+
client = Mysql2::Client.new( connection_params )
|
|
122
130
|
|
|
123
131
|
app.cache_db_client( self, client ) if app
|
|
124
132
|
|
|
@@ -134,33 +142,30 @@ class Mysql < Gloo::Core::Obj
|
|
|
134
142
|
|
|
135
143
|
heads = []
|
|
136
144
|
data = []
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
data << arr
|
|
145
|
+
# Database errors come out as exceptions, for Query to report.
|
|
146
|
+
if params
|
|
147
|
+
pst = client.prepare( sql )
|
|
148
|
+
rs = pst.execute( *params, :as => :array )
|
|
149
|
+
if rs
|
|
150
|
+
rs.each do |row|
|
|
151
|
+
arr = []
|
|
152
|
+
row.each do |o|
|
|
153
|
+
arr << o
|
|
148
154
|
end
|
|
155
|
+
data << arr
|
|
149
156
|
end
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
end
|
|
158
|
+
else
|
|
159
|
+
rs = client.query( sql, :as => :array )
|
|
160
|
+
if rs
|
|
161
|
+
rs.each do |row|
|
|
162
|
+
data << row
|
|
156
163
|
end
|
|
157
164
|
end
|
|
158
|
-
|
|
159
|
-
heads = rs.fields if rs
|
|
160
|
-
rescue => e
|
|
161
|
-
@engine.log_exception e
|
|
162
165
|
end
|
|
163
166
|
|
|
167
|
+
heads = rs.fields if rs
|
|
168
|
+
|
|
164
169
|
return [ heads, data ]
|
|
165
170
|
end
|
|
166
171
|
|
|
@@ -227,24 +232,56 @@ class Mysql < Gloo::Core::Obj
|
|
|
227
232
|
end
|
|
228
233
|
|
|
229
234
|
#
|
|
230
|
-
#
|
|
231
|
-
# Returns true if we can establish a connection.
|
|
235
|
+
# The settings for a connection, from the children.
|
|
232
236
|
#
|
|
233
|
-
def
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
237
|
+
def connection_params
|
|
238
|
+
return {
|
|
239
|
+
host: host_value,
|
|
240
|
+
database: db_value,
|
|
241
|
+
username: user_value,
|
|
242
|
+
password: passwd_value
|
|
243
|
+
}
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# ---------------------------------------------------------------------
|
|
247
|
+
# Object Documentation
|
|
248
|
+
# ---------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
#
|
|
251
|
+
# Get the object's documentation data.
|
|
252
|
+
#
|
|
253
|
+
def self.doc_data
|
|
254
|
+
{
|
|
255
|
+
:name => KEYWORD,
|
|
256
|
+
:shortcut => KEYWORD_SHORT,
|
|
257
|
+
:description => 'A MySQL database connection.',
|
|
258
|
+
:children => [
|
|
259
|
+
'host (string) — The database server host.',
|
|
260
|
+
'database (string) — The name of the database.',
|
|
261
|
+
'username (string) — The username with which to connect.',
|
|
262
|
+
"password (string) — The user's password."
|
|
263
|
+
],
|
|
264
|
+
:messages => [
|
|
265
|
+
'verify — Verify that the database connection can be established. It is true if it can, false if not (with the reason in the error).'
|
|
266
|
+
],
|
|
267
|
+
:examples => <<~EXAMPLES.strip
|
|
268
|
+
mysql [can] :
|
|
269
|
+
on_load [script] :
|
|
270
|
+
run mysql.get_passwd
|
|
271
|
+
run mysql.sql
|
|
272
|
+
db [mysql] :
|
|
273
|
+
host : localhost
|
|
274
|
+
database : my_database
|
|
275
|
+
username : my_user
|
|
276
|
+
password [alias] : mysql.get_passwd.result
|
|
277
|
+
sql [query] :
|
|
278
|
+
database [alias] : mysql.db
|
|
279
|
+
sql : SELECT first, last, phone FROM people
|
|
280
|
+
get_passwd [ask] :
|
|
281
|
+
prompt [string] : Database Password?
|
|
282
|
+
result [string] :
|
|
283
|
+
EXAMPLES
|
|
284
|
+
}
|
|
248
285
|
end
|
|
249
286
|
|
|
250
287
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gloo-mysql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '1.
|
|
4
|
+
version: '1.2'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eric Crane
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: mysql2
|
|
@@ -30,6 +29,88 @@ dependencies:
|
|
|
30
29
|
- - ">="
|
|
31
30
|
- !ruby/object:Gem::Version
|
|
32
31
|
version: 0.5.3
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: gloo
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '7.0'
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '7.0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: gloo-db
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '1.3'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '1.3'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: bundler
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
- !ruby/object:Gem::Dependency
|
|
75
|
+
name: minitest
|
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - "~>"
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '5.1'
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: 5.14.2
|
|
84
|
+
type: :development
|
|
85
|
+
prerelease: false
|
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - "~>"
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '5.1'
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: 5.14.2
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: rake
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - "~>"
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '13.0'
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 13.0.1
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '13.0'
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: 13.0.1
|
|
33
114
|
description: Adds MySQL support to Gloo.
|
|
34
115
|
email:
|
|
35
116
|
- eric.crane@mac.com
|
|
@@ -37,14 +118,15 @@ executables: []
|
|
|
37
118
|
extensions: []
|
|
38
119
|
extra_rdoc_files: []
|
|
39
120
|
files:
|
|
121
|
+
- README.md
|
|
40
122
|
- lib/gloo-mysql.rb
|
|
41
123
|
- lib/mysql.rb
|
|
42
|
-
homepage: https://
|
|
124
|
+
homepage: https://github.com/ecrane/gloo
|
|
43
125
|
licenses:
|
|
44
126
|
- MIT
|
|
45
127
|
metadata:
|
|
46
128
|
gloo.type: core-library
|
|
47
|
-
|
|
129
|
+
documentation_uri: https://github.com/ecrane/gloo
|
|
48
130
|
rdoc_options: []
|
|
49
131
|
require_paths:
|
|
50
132
|
- lib
|
|
@@ -59,8 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
59
141
|
- !ruby/object:Gem::Version
|
|
60
142
|
version: '0'
|
|
61
143
|
requirements: []
|
|
62
|
-
rubygems_version:
|
|
63
|
-
signing_key:
|
|
144
|
+
rubygems_version: 4.0.17
|
|
64
145
|
specification_version: 4
|
|
65
146
|
summary: Gloo core library. MySQL support.
|
|
66
147
|
test_files: []
|