sqlite_ext 0.3.0 → 1.0.0

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: cc98b5174c0640ce74feba4c553d0061600bffef
4
- data.tar.gz: 5d617dd109ed311c43c8b066f6d74d3505da4568
3
+ metadata.gz: 65d496b1a883d0434eca25d716a17ee3b8601c10
4
+ data.tar.gz: 072a4e2652b1cd62ae62387e545cb951ca36718d
5
5
  SHA512:
6
- metadata.gz: 9a918310e21666283174b41a6b87f85fe42052e052bf6774fb8ee7d3fb57f85314bf6f7d9b36811517e30003c7930994dfce55992fd4159cb8a74b15b07c076b
7
- data.tar.gz: e57a95e894c8be15190ba915ee9810d534f0b64754c23f252225e01d649cf1d79235ff1c7c1162ced5298608c30bffd5c17b2aa2fb05bb935bb0137310550f7a
6
+ metadata.gz: edde829aee324957431fdef3e21cbc571ee2bf27d5428f8414eddc6af8e4e1762d4e1978bdaaf8ca998332219877898d6637cb9e39dfc15a3cc0f7802a380fb3
7
+ data.tar.gz: 949450c43351bdfd193da438b247e01faf495fdc2435198db4bff6e6789279c1dbeccb9d246678eec1aa9e06169662cfaffe7eef4e4df984a114918e7a91a4bf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 1.0.0 - 2016-06-23
2
+ * Features
3
+ * Added `SqliteExt.register_ruby_math`. Registers most of Ruby's `Math`
4
+ module methods as SQLite SQL functions.
5
+
1
6
  ### 0.3.0 - 2016-06-23
2
7
  * Removals
3
8
  * Removed support for a block argument to `SqliteExt.register_function`.
data/README.md CHANGED
@@ -38,32 +38,68 @@ Or install it yourself as:
38
38
  ## Usage
39
39
 
40
40
  SqliteExt.register_function(
41
- 'sqrt',
42
- ->(x){ Math.sqrt(x) }
41
+ 'sign',
42
+ ->(x){ x <=> 0 }
43
43
  )
44
44
 
45
45
  SQLite3::Database.new 'data.db' do |db|
46
- puts db.execute(
47
- "SELECT sqrt(25), COALESCE(sqrt(NULL), -1)"
48
- ).first
46
+ puts db.execute(<<-EOS).first
47
+ SELECT
48
+ sign(2)
49
+ , sign(-3)
50
+ , sign(0)
51
+ , COALESCE(sign(NULL), 'n/a')
52
+ EOS
49
53
  end
50
54
 
51
55
  # == Output ==
52
- # 5.0
56
+ # 1
53
57
  # -1
58
+ # 0
59
+ # n/a
60
+
61
+ SqliteExt.register_ruby_math
62
+
63
+ SQLite3::Database.new 'data.db' do |db|
64
+ puts db.execute(<<-EOS).first
65
+ SELECT
66
+ sqrt(25)
67
+ , cos(asin(3.0/5.0))
68
+ , COALESCE(sqrt(NULL), 'n/a')
69
+ EOS
70
+ end
71
+
72
+ # == Output ==
73
+ # 5.0
74
+ # 0.8
75
+ # n/a
54
76
 
55
77
  ## Development
56
78
 
57
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+ After checking out the repo, run `bin/setup` to install
80
+ dependencies. Then, run `rake spec` to run the tests. You can
81
+ also run `bin/console` for an interactive prompt that will allow
82
+ you to experiment.
58
83
 
59
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake 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).
84
+ To install this gem onto your local machine, run `bundle exec
85
+ rake install`. To release a new version, update the version
86
+ number in `version.rb`, and then run `bundle exec rake release`,
87
+ which will create a git tag for the version, push git commits and
88
+ tags, and push the `.gem` file to
89
+ [rubygems.org](https://rubygems.org).
60
90
 
61
91
  ## Contributing
62
92
 
63
- Bug reports and pull requests are welcome on GitHub at https://github.com/stevecj/sqlite_ext. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
93
+ Bug reports and pull requests are welcome on GitHub at
94
+ https://github.com/stevecj/sqlite_ext. This project is intended
95
+ to be a safe, welcoming space for collaboration, and
96
+ contributors are expected to adhere to the
97
+ [Contributor Covenant](http://contributor-covenant.org) code of
98
+ conduct.
64
99
 
65
100
 
66
101
  ## License
67
102
 
68
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
103
+ The gem is available as open source under the terms of the
104
+ [MIT License](http://opensource.org/licenses/MIT).
69
105
 
@@ -1,3 +1,3 @@
1
1
  module SqliteExt
2
- VERSION = '0.3.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/sqlite_ext.rb CHANGED
@@ -69,6 +69,23 @@ module SqliteExt
69
69
  end
70
70
  end
71
71
 
72
+ # Registers most of the public module methods of Ruby's `Math`
73
+ # module to be used as a functions in SQL code executed
74
+ # through subsequent new instances of `SQLite3::Database`.
75
+ #
76
+ # The `Math.frexp` method is omitted becuse it returns an
77
+ # array, and there is no way to return an array from a SQL
78
+ # function in SQLite.
79
+ #
80
+ # `NULL`s are propagated as described in the documentation
81
+ # for `register_function`.
82
+ def register_ruby_math
83
+ fn_methods = Math.public_methods - (Module.instance_methods << :frexp)
84
+ fn_methods.each do |m|
85
+ register_function m, Math.method(m)
86
+ end
87
+ end
88
+
72
89
  # Registers a #create_function call to be invoked on every
73
90
  # new instance of `SQLite3::Database` immidately after it is
74
91
  # instantiated and before it is returned from the call to
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlite_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Jorgensen