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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +46 -10
- data/lib/sqlite_ext/version.rb +1 -1
- data/lib/sqlite_ext.rb +17 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65d496b1a883d0434eca25d716a17ee3b8601c10
|
4
|
+
data.tar.gz: 072a4e2652b1cd62ae62387e545cb951ca36718d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
'
|
42
|
-
->(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
|
-
|
48
|
-
|
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
|
-
#
|
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
|
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
|
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
|
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
|
103
|
+
The gem is available as open source under the terms of the
|
104
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
69
105
|
|
data/lib/sqlite_ext/version.rb
CHANGED
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
|