mysql2 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,128 +1,163 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mysql2
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.7
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 8
10
+ version: 0.2.8
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Brian Lopez
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-03-28 00:00:00.000000000 -07:00
17
+
18
+ date: 2011-06-14 00:00:00 -07:00
13
19
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: eventmachine
17
- requirement: &2161341260 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :development
24
- prerelease: false
25
- version_requirements: *2161341260
26
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
27
36
  name: rake-compiler
28
- requirement: &2161340760 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
29
39
  none: false
30
- requirements:
40
+ requirements:
31
41
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 0.7.1
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 0
46
+ - 7
47
+ - 7
48
+ version: 0.7.7
34
49
  type: :development
35
- prerelease: false
36
- version_requirements: *2161340760
37
- - !ruby/object:Gem::Dependency
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
38
52
  name: rspec
39
- requirement: &2161340340 !ruby/object:Gem::Requirement
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
40
55
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
45
63
  type: :development
46
- prerelease: false
47
- version_requirements: *2161340340
48
- - !ruby/object:Gem::Dependency
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
49
66
  name: activerecord
50
- requirement: &2161339880 !ruby/object:Gem::Requirement
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
51
69
  none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
56
77
  type: :development
57
- prerelease: false
58
- version_requirements: *2161339880
59
- - !ruby/object:Gem::Dependency
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
60
80
  name: mysql
61
- requirement: &2161339460 !ruby/object:Gem::Requirement
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
62
83
  none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
67
91
  type: :development
68
- prerelease: false
69
- version_requirements: *2161339460
70
- - !ruby/object:Gem::Dependency
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
71
94
  name: do_mysql
72
- requirement: &2161339040 !ruby/object:Gem::Requirement
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
73
97
  none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
78
105
  type: :development
79
- prerelease: false
80
- version_requirements: *2161339040
81
- - !ruby/object:Gem::Dependency
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
82
108
  name: sequel
83
- requirement: &2161338620 !ruby/object:Gem::Requirement
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
84
111
  none: false
85
- requirements:
86
- - - ! '>='
87
- - !ruby/object:Gem::Version
88
- version: '0'
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
89
119
  type: :development
90
- prerelease: false
91
- version_requirements: *2161338620
92
- - !ruby/object:Gem::Dependency
120
+ version_requirements: *id007
121
+ - !ruby/object:Gem::Dependency
93
122
  name: faker
94
- requirement: &2161338200 !ruby/object:Gem::Requirement
123
+ prerelease: false
124
+ requirement: &id008 !ruby/object:Gem::Requirement
95
125
  none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
100
133
  type: :development
101
- prerelease: false
102
- version_requirements: *2161338200
134
+ version_requirements: *id008
103
135
  description:
104
136
  email: seniorlopez@gmail.com
105
137
  executables: []
106
- extensions:
138
+
139
+ extensions:
107
140
  - ext/mysql2/extconf.rb
108
- extra_rdoc_files:
109
- - README.rdoc
110
- files:
141
+ extra_rdoc_files: []
142
+
143
+ files:
111
144
  - .gitignore
112
145
  - .rspec
113
146
  - .rvmrc
114
147
  - CHANGELOG.md
115
148
  - Gemfile
116
149
  - MIT-LICENSE
117
- - README.rdoc
150
+ - README.md
118
151
  - Rakefile
119
152
  - benchmark/active_record.rb
153
+ - benchmark/active_record_threaded.rb
120
154
  - benchmark/allocations.rb
121
155
  - benchmark/escape.rb
122
156
  - benchmark/query_with_mysql_casting.rb
123
157
  - benchmark/query_without_mysql_casting.rb
124
158
  - benchmark/sequel.rb
125
159
  - benchmark/setup_db.rb
160
+ - benchmark/threaded.rb
126
161
  - examples/eventmachine.rb
127
162
  - examples/threaded.rb
128
163
  - ext/mysql2/client.c
@@ -158,31 +193,39 @@ files:
158
193
  has_rdoc: true
159
194
  homepage: http://github.com/brianmario/mysql2
160
195
  licenses: []
196
+
161
197
  post_install_message:
162
- rdoc_options:
198
+ rdoc_options:
163
199
  - --charset=UTF-8
164
- require_paths:
200
+ require_paths:
165
201
  - lib
166
202
  - ext
167
- required_ruby_version: !ruby/object:Gem::Requirement
203
+ required_ruby_version: !ruby/object:Gem::Requirement
168
204
  none: false
169
- requirements:
170
- - - ! '>='
171
- - !ruby/object:Gem::Version
172
- version: '0'
173
- required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ hash: 3
209
+ segments:
210
+ - 0
211
+ version: "0"
212
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
213
  none: false
175
- requirements:
176
- - - ! '>='
177
- - !ruby/object:Gem::Version
178
- version: '0'
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ hash: 3
218
+ segments:
219
+ - 0
220
+ version: "0"
179
221
  requirements: []
222
+
180
223
  rubyforge_project:
181
- rubygems_version: 1.6.1
224
+ rubygems_version: 1.3.10
182
225
  signing_key:
183
226
  specification_version: 3
184
227
  summary: A simple, fast Mysql library for Ruby, binding to libmysql
185
- test_files:
228
+ test_files:
186
229
  - examples/eventmachine.rb
187
230
  - examples/threaded.rb
188
231
  - spec/em/em_fiber_spec.rb
data/README.rdoc DELETED
@@ -1,248 +0,0 @@
1
- = Mysql2 - A modern, simple and very fast Mysql library for Ruby - binding to libmysql
2
-
3
- The Mysql2 gem is meant to serve the extremely common use-case of connecting, querying and iterating on results.
4
- Some database libraries out there serve as direct 1:1 mappings of the already complex C API's available.
5
- This one is not.
6
-
7
- It also forces the use of UTF-8 [or binary] for the connection [and all strings in 1.9, unless Encoding.default_internal is set then it'll convert from UTF-8 to that encoding] and uses encoding-aware MySQL API calls where it can.
8
-
9
- The API consists of two clases:
10
-
11
- Mysql2::Client - your connection to the database
12
-
13
- Mysql2::Result - returned from issuing a #query on the connection. It includes Enumerable.
14
-
15
- == Installing
16
-
17
- gem install mysql2
18
-
19
- You may have to specify --with-mysql-config=/some/random/path/bin/mysql_config
20
-
21
- == Usage
22
-
23
- Connect to a database:
24
-
25
- # this takes a hash of options, almost all of which map directly
26
- # to the familiar database.yml in rails
27
- # See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/MysqlAdapter.html
28
- client = Mysql2::Client.new(:host => "localhost", :username => "root")
29
-
30
- Then query it:
31
-
32
- results = client.query("SELECT * FROM users WHERE group='githubbers'")
33
-
34
- Need to escape something first?
35
-
36
- escaped = client.escape("gi'thu\"bbe\0r's")
37
- results = client.query("SELECT * FROM users WHERE group='#{escaped}'")
38
-
39
- Finally, iterate over the results:
40
-
41
- results.each do |row|
42
- # conveniently, row is a hash
43
- # the keys are the fields, as you'd expect
44
- # the values are pre-built ruby primitives mapped from their corresponding field types in MySQL
45
- # Here's an otter: http://farm1.static.flickr.com/130/398077070_b8795d0ef3_b.jpg
46
- end
47
-
48
- Or, you might just keep it simple:
49
-
50
- client.query("SELECT * FROM users WHERE group='githubbers'").each do |row|
51
- # do something with row, it's ready to rock
52
- end
53
-
54
- How about with symbolized keys?
55
-
56
- # NOTE: the :symbolize_keys and future options will likely move to the #query method soon
57
- client.query("SELECT * FROM users WHERE group='githubbers'").each(:symbolize_keys => true) do |row|
58
- # do something with row, it's ready to rock
59
- end
60
-
61
- == Cascading config
62
-
63
- The default config hash is at:
64
-
65
- Mysql2::Client.default_query_options
66
-
67
- which defaults to:
68
-
69
- {:async => false, :as => :hash, :symbolize_keys => false}
70
-
71
- that can be used as so:
72
-
73
- # these are the defaults all Mysql2::Client instances inherit
74
- Mysql2::Client.default_query_options.merge!(:as => :array)
75
-
76
- or
77
-
78
- # this will change the defaults for all future results returned by the #query method _for this connection only_
79
- c = Mysql2::Client.new
80
- c.query_options.merge!(:symbolize_keys => true)
81
-
82
- or
83
-
84
- # this will set the options for the Mysql2::Result instance returned from the #query method
85
- c = Mysql2::Client.new
86
- c.query(sql, :symbolize_keys => true)
87
-
88
- == Result types
89
-
90
- === Array of Arrays
91
-
92
- Pass the :as => :array option to any of the above methods of configuration
93
-
94
- === Array of Hashes
95
-
96
- The default result type is set to :hash, but you can override a previous setting to something else with :as => :hash
97
-
98
- === Others...
99
-
100
- I may add support for :as => :csv or even :as => :json to allow for *much* more efficient generation of those data types from result sets.
101
- If you'd like to see either of these (or others), open an issue and start bugging me about it ;)
102
-
103
- === Timezones
104
-
105
- Mysql2 now supports two timezone options:
106
-
107
- :database_timezone - this is the timezone Mysql2 will assume fields are already stored as, and will use this when creating the initial Time objects in ruby
108
- :application_timezone - this is the timezone Mysql2 will convert to before finally handing back to the caller
109
-
110
- In other words, if :database_timezone is set to :utc - Mysql2 will create the Time objects using Time.utc(...) from the raw value libmysql hands over initially.
111
- Then, if :application_timezone is set to say - :local - Mysql2 will then convert the just-created UTC Time object to local time.
112
-
113
- Both options only allow two values - :local or :utc - with the exception that :application_timezone can be [and defaults to] nil
114
-
115
- === Casting "boolean" columns
116
-
117
- You can now tell Mysql2 to cast tinyint(1) fields to boolean values in Ruby with the :cast_booleans option.
118
-
119
- client = Mysql2::Client.new
120
- result = client.query("SELECT * FROM table_with_boolean_field", :cast_booleans => true)
121
-
122
- === Async
123
-
124
- Mysql2::Client takes advantage of the MySQL C API's (undocumented) non-blocking function mysql_send_query for *all* queries.
125
- But, in order to take full advantage of it in your Ruby code, you can do:
126
-
127
- client.query("SELECT sleep(5)", :async => true)
128
-
129
- Which will return nil immediately. At this point you'll probably want to use some socket monitoring mechanism
130
- like EventMachine or even IO.select. Once the socket becomes readable, you can do:
131
-
132
- # result will be a Mysql2::Result instance
133
- result = client.async_result
134
-
135
- NOTE: Because of the way MySQL's query API works, this method will block until the result is ready.
136
- So if you really need things to stay async, it's best to just monitor the socket with something like EventMachine.
137
- If you need multiple query concurrency take a look at using a connection pool.
138
-
139
- === Row Caching
140
-
141
- By default, Mysql2 will cache rows that have been created in Ruby (since this happens lazily).
142
- This is especially helpful since it saves the cost of creating the row in Ruby if you were to iterate over the collection again.
143
-
144
- If you only plan on using each row once, then it's much more efficient to disable this behavior by setting the :cache_rows option to false.
145
- This would be helpful if you wanted to iterate over the results in a streaming manner. Meaning the GC would cleanup rows you don't need anymore as you're iterating over the result set.
146
-
147
- == ActiveRecord
148
-
149
- To use the ActiveRecord driver (with our without rails), all you should need to do is have this gem installed and set the adapter in your database.yml to "mysql2".
150
- That was easy right? :)
151
-
152
- == Asynchronous ActiveRecord
153
-
154
- You can also use Mysql2 with asynchronous Rails (first introduced at http://www.mikeperham.com/2010/04/03/introducing-phat-an-asynchronous-rails-app/) by
155
- setting the adapter in your database.yml to "em_mysql2". You must be running Ruby 1.9, thin and the rack-fiber_pool middleware for it to work.
156
-
157
- == Sequel
158
-
159
- The Sequel adapter was pulled out into Sequel core (will be part of the next release) and can be used by specifying the "mysql2://" prefix to your connection specification.
160
-
161
- == EventMachine
162
-
163
- The mysql2 EventMachine deferrable api allows you to make async queries using EventMachine,
164
- while specifying callbacks for success for failure. Here's a simple example:
165
-
166
- require 'mysql2/em'
167
-
168
- EM.run do
169
- client1 = Mysql2::EM::Client.new
170
- defer1 = client1.query "SELECT sleep(3) as first_query"
171
- defer1.callback do |result|
172
- puts "Result: #{result.to_a.inspect}"
173
- end
174
-
175
- client2 = Mysql2::EM::Client.new
176
- defer2 = client2.query "SELECT sleep(1) second_query"
177
- defer2.callback do |result|
178
- puts "Result: #{result.to_a.inspect}"
179
- end
180
- end
181
-
182
- == Lazy Everything
183
-
184
- Well... almost ;)
185
-
186
- Field name strings/symbols are shared across all the rows so only one object is ever created to represent the field name for an entire dataset.
187
-
188
- Rows themselves are lazily created in ruby-land when an attempt to yield it is made via #each.
189
- For example, if you were to yield 4 rows from a 100 row dataset, only 4 hashes will be created. The rest will sit and wait in C-land until you want them (or when the GC goes to cleanup your Mysql2::Result instance).
190
- Now say you were to iterate over that same collection again, this time yielding 15 rows - the 4 previous rows that had already been turned into ruby hashes would be pulled from an internal cache, then 11 more would be created and stored in that cache.
191
- Once the entire dataset has been converted into ruby objects, Mysql2::Result will free the Mysql C result object as it's no longer needed.
192
-
193
- This caching behavior can be disabled by setting the :cache_rows option to false.
194
-
195
- As for field values themselves, I'm workin on it - but expect that soon.
196
-
197
- == Compatibility
198
-
199
- The specs pass on my system (SL 10.6.3, x86_64) in these rubies:
200
-
201
- * 1.8.7-p249
202
- * ree-1.8.7-2010.01
203
- * 1.9.1-p378
204
- * ruby-trunk
205
- * rbx-head - broken at the moment, working with the rbx team for a solution
206
-
207
- The ActiveRecord driver should work on 2.3.5 and 3.0
208
-
209
- == Yeah... but why?
210
-
211
- Someone: Dude, the Mysql gem works fiiiiiine.
212
-
213
- Me: It sure does, but it only hands you nil and strings for field values. Leaving you to convert
214
- them into proper Ruby types in Ruby-land - which is slow as balls.
215
-
216
-
217
- Someone: OK fine, but do_mysql can already give me back values with Ruby objects mapped to MySQL types.
218
-
219
- Me: Yep, but it's API is considerably more complex *and* can be ~2x slower.
220
-
221
- == Benchmarks
222
-
223
- Performing a basic "SELECT * FROM" query on a table with 30k rows and fields of nearly every Ruby-representable data type,
224
- then iterating over every row using an #each like method yielding a block:
225
-
226
- # These results are from the query_with_mysql_casting.rb script in the benchmarks folder
227
- user system total real
228
- Mysql2
229
- 0.750000 0.180000 0.930000 ( 1.821655)
230
- do_mysql
231
- 1.650000 0.200000 1.850000 ( 2.811357)
232
- Mysql
233
- 7.500000 0.210000 7.710000 ( 8.065871)
234
-
235
- == Development
236
-
237
- To run the tests, you can use RVM and Bundler to create a pristine environment for mysql2 development/hacking.
238
- Use 'bundle install' to install the necessary development and testing gems:
239
-
240
- bundle install
241
- rake
242
-
243
- == Special Thanks
244
-
245
- * Eric Wong - for the contribution (and the informative explanations) of some thread-safety, non-blocking I/O and cleanup patches. You rock dude
246
- * Yury Korolev (http://github.com/yury) - for TONS of help testing the ActiveRecord adapter
247
- * Aaron Patterson (http://github.com/tenderlove) - tons of contributions, suggestions and general badassness
248
- * Mike Perham (http://github.com/mperham) - Async ActiveRecord adapter (uses Fibers and EventMachine)