github-ds 0.2.8 → 0.2.9

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
  SHA1:
3
- metadata.gz: e72707c0bbfc8fcf2e846d4e16e6735b8b457728
4
- data.tar.gz: 11e5d2059aafe9dc81e7cd343c0a1b7218ca23e6
3
+ metadata.gz: 716ec52fb178302c762091225dc4ab8b1b61a793
4
+ data.tar.gz: dd79687dfd3a302ebff1978a9f2ea18adf649a05
5
5
  SHA512:
6
- metadata.gz: a9f34c95c26ee3edd98d27acefa2d1ea8ca6c1197c36f1616c0dbc387e2f76c4a16c497024565a85de00138031ec8955ab40bd61c6545e3a6ef0e28f4ef1bfbe
7
- data.tar.gz: 38586c9b89eaefa299d45e94ed9beb03cbc21b230c301aada2db21aeab27ff8a851cce41ddfc7f7cec0cfd56193e66a1ff62588f57d930ef3089cecbf3c2634f
6
+ metadata.gz: f23f9d2e7467159b263ec39352c22f1e400198a81dc5294fea08c0e99361f9fe76a44f5a694979fe72359cf8d174dd9655503e8c7f8ea3aa3a0bc8cbb4c28468
7
+ data.tar.gz: 732716e7a5a28b5526934ad854e1148b17c35322546d01fce321b26417067dd9542d026ef69dfed371dede8a744871a3a505053fc93a7c560de851a845e663e5
@@ -1,11 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.7
4
- - 2.3.4
5
- - 2.4.0
6
- before_script: gem install bundler -v 1.14.6
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
7
  script: bundle exec rake
8
8
  env:
9
- - RAILS_VERSION=5.1.0
10
- - RAILS_VERSION=5.0.0
11
- - RAILS_VERSION=4.2.5
9
+ - RAILS_VERSION=5.1.5
10
+ - RAILS_VERSION=5.0.6
11
+ - RAILS_VERSION=4.2.10
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.9
4
+
5
+ Fixes
6
+
7
+ * Passing duplicate values to columns in a SQL statement (ex `SELECT id, NULL, NULL, name from repositories`) used to return an array of results with de-duplicated values. (ex `[[1, nil, "github"]]` instead of `[[1, nil, nil, "github"]]`. This had some unfortunate side-effects when parsing results so we changed the code to behave closer to `ActiveRecord::Result` objects. Now if you pass duplicated columns the `results` array will return all the values. The hash will only return unique columns because hashes cannot contain duplicate keys.
8
+
3
9
  ## 0.2.8
4
10
 
5
11
  Fixes
data/Gemfile CHANGED
@@ -2,5 +2,11 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  DEFAULT_RAILS_VERSION = '5.0.2'
5
+
6
+ if ENV['RAILS_VERSION'] = '4.2.10'
7
+ gem 'mysql2', '~> 0.3.18'
8
+ else
9
+ gem "mysql2"
10
+ end
5
11
  gem "rails", "~> #{ENV['RAILS_VERSION'] || DEFAULT_RAILS_VERSION}"
6
12
  gem "activerecord", "~> #{ENV['RAILS_VERSION'] || DEFAULT_RAILS_VERSION}"
data/README.md CHANGED
@@ -191,6 +191,8 @@ KV supports expiring keys and obeys expiration when performing operations, but d
191
191
 
192
192
  After checking out the repo, run `script/bootstrap` to install dependencies. Then, run `script/test` to run the tests. You can also run `script/console` for an interactive prompt that will allow you to experiment.
193
193
 
194
+ **Note**: You will need a MySQL database with no password set for the root user for the tests. Running `docker-compose up` will boot just that. This functionality is not currently used by GitHub and was from a contributor, so please let us know if it does not work or gets out of date (pull request is best, but an issue will do).
195
+
194
196
  To install this gem onto your local machine, run `script/install`. To release a new version, update the version number in `version.rb`, commit, and then run `script/release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
195
197
 
196
198
  ## Contributing
@@ -0,0 +1,8 @@
1
+ version: '3'
2
+ services:
3
+ mysql:
4
+ image: mysql:5.6
5
+ environment:
6
+ - MYSQL_ALLOW_EMPTY_PASSWORD=yes
7
+ ports:
8
+ - "3306:3306"
@@ -1,5 +1,5 @@
1
1
  module GitHub
2
2
  module DS
3
- VERSION = "0.2.8"
3
+ VERSION = "0.2.9"
4
4
  end
5
5
  end
@@ -270,6 +270,29 @@ module GitHub
270
270
  nil
271
271
  end
272
272
 
273
+ # ttl :: String -> Result<[Time | nil]>
274
+ #
275
+ # Returns the expires_at time for the specified key or nil.
276
+ #
277
+ # Example:
278
+ #
279
+ # kv.ttl("foo")
280
+ # # => #<Result value: 2018-04-23 11:34:54 +0200>
281
+ #
282
+ # kv.ttl("foo")
283
+ # # => #<Result value: nil>
284
+ #
285
+ def ttl(key)
286
+ validate_key(key)
287
+
288
+ Result.new {
289
+ GitHub::SQL.value(<<-SQL, :key => key, :connection => connection)
290
+ SELECT expires_at FROM key_values
291
+ WHERE `key` = :key AND (expires_at IS NULL OR expires_at > NOW())
292
+ SQL
293
+ }
294
+ end
295
+
273
296
  private
274
297
  def validate_key(key, error_message: nil)
275
298
  unless key.is_a?(String)
@@ -21,11 +21,18 @@ module GitHub
21
21
  # * `nil` is always considered an error and not a usable value. If you need a
22
22
  # SQL NULL, use the NULL constant instead.
23
23
  #
24
- # * Identical column names in SELECTs will be overridden:
25
- # `SELECT t1.id, t2.id FROM...` will only return one value for `id`. To get
26
- # more than one column of the same name, use aliases:
24
+ # * Identical column names in SELECTs will be overridden for hash_results:
25
+ # `SELECT t1.id, t2.id FROM...` will only return one value for `id`. The
26
+ # second ID colum won't be included in the hash:
27
+ #
28
+ # [{ "id" => "1" }]
29
+ #
30
+ # To get more than one column of the same name, use aliases:
27
31
  # `SELECT t1.id t1_id, t2.id t2_id FROM ...`
28
32
  #
33
+ # Calling `results` however will return an array with all the values:
34
+ # [[1, 1]]
35
+ #
29
36
  # * Arrays are escaped as `(item, item, item)`. If you need to insert multiple
30
37
  # rows (Arrays of Arrays), you must specify the bind value using
31
38
  # GitHub::SQL::ROWS(array_of_arrays).
@@ -232,9 +239,9 @@ module GitHub
232
239
 
233
240
  when /\ASELECT/i
234
241
  # Why not execute or select_rows? Because select_all hits the query cache.
235
- @hash_results = connection.select_all(query, "#{self.class.name} Select").to_ary
236
- @results = @hash_results.map(&:values)
237
-
242
+ ar_results = connection.select_all(query, "#{self.class.name} Select")
243
+ @hash_results = ar_results.to_ary
244
+ @results = ar_results.rows
238
245
  else
239
246
  @results = connection.execute(query, "#{self.class.name} Execute").to_a
240
247
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-ds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-10-16 00:00:00.000000000 Z
12
+ date: 2018-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -147,6 +147,7 @@ files:
147
147
  - LICENSE.txt
148
148
  - README.md
149
149
  - Rakefile
150
+ - docker-compose.yml
150
151
  - examples/example_setup.rb
151
152
  - examples/kv.rb
152
153
  - examples/result.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  version: '0'
192
193
  requirements: []
193
194
  rubyforge_project:
194
- rubygems_version: 2.5.2
195
+ rubygems_version: 2.4.5
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: A collection of libraries for working with SQL on top of ActiveRecord's connection.