sqlite_ext 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f6b5d358b16c536bcdad4bb288489e28360658c
4
- data.tar.gz: 138d46d2228bb3fc817590ca9fc034e405237730
3
+ metadata.gz: 8ef79118c67623c9f8ea24483b8546c8ce61a8d9
4
+ data.tar.gz: 82e046090cdf94052b499694feb657f13251d280
5
5
  SHA512:
6
- metadata.gz: 1aa86694f1cab9be067f288c0ac11a87c682cc72ffbca404a21e7ccf26902faecab1183b5a4ecdca83a4bbc25b6a4683d9e4ee1b81470c33c46129177603120d
7
- data.tar.gz: d839f9d594177b9934779fd67d7d50710db7db7626ba50cb77eca31c2426fcb4ea467248ea143996804cc36f6d6fa4380f066b7da619470ca254a2a2c629c6e5
6
+ metadata.gz: 644c88efc1b5b4803ca26c0a355485e426c4fc6a9e1711599c886e04b5a8f5c3ac88a63ebeadbc566b35e74c4da543ac194bcd971bbe61deab2f9497dc488493
7
+ data.tar.gz: d20b161052dd7baa1773d7a451d5a4b8ab7f85f2a95d93772f685710ce7738d6d92d8d799bc030a997ee237a0b05b7d1f0a9bb503a12711bc9d04bfe6090d5af
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # SqliteExt
2
2
 
3
- Note that the work on this gem is still in the early stages, so
4
- the text below represents what it is intended to do. The gem does
5
- not yet accomplish all of that as of yet.
6
-
7
3
  Provides a convenient way of writing functions in Ruby that can
8
4
  be called from with in SQLite queries through the SQLite3 gem.
9
5
 
@@ -41,14 +37,8 @@ Or install it yourself as:
41
37
 
42
38
  ## Usage
43
39
 
44
- SqliteExt.register_create_function 'sqrt', 1 do |fn,x|
45
- fn.result =
46
- case x
47
- when nil then nil
48
- else Math.sqrt(x)
49
- end
50
- end
51
-
40
+ SqliteExt.register_function('sqrt', 1){ |x| Math.sqrt(x) }
41
+
52
42
  SQLite3::Database.new 'data.db' do |db|
53
43
  puts db.execute("SELECT sqrt(25)")[0][0]
54
44
  end
@@ -1,3 +1,3 @@
1
1
  module SqliteExt
2
- VERSION = "0.1.1"
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/sqlite_ext.rb CHANGED
@@ -16,30 +16,54 @@ module SqliteExt
16
16
 
17
17
  class << self
18
18
 
19
+ # Registers a block of ruby code to be used as a function in
20
+ # SQL executed through subsequent new instances of
21
+ # `SQLite3::Database`.
22
+ #
23
+ # Example:
24
+ #
25
+ # SqliteExt.register_function('sqrt', 1){ |x| Math.sqrt(x) }
26
+ #
27
+ # SQLite3::Database.new 'data.db' do |db|
28
+ # puts db.execute("SELECT sqrt(25)")[0][0]
29
+ # end
30
+ # # Output: 5.0
31
+ #
32
+ def register_function(name, &block)
33
+ register_create_function name, block.arity do |fn,*args|
34
+ fn.result = block.call(*args)
35
+ end
36
+ end
37
+
19
38
  # Registers a #create_function call to be invoked on every
20
39
  # new instance of `SQLite3::Database` immidately after it is
21
40
  # instantiated and before it is returned from the call to
22
41
  # `.new` and before the invocation of a block that is passed
23
42
  # to `.new`.
24
43
  #
44
+ # The parameters passed to `#register_create_function` are
45
+ # exactly the same as those that would be passed to
46
+ # `SQLite3::Database#create_function`.
47
+ #
25
48
  # Note that this only affects instances of
26
49
  # `SQLite3::Database` that are subsequently created and has
27
50
  # no effect on previously created instances.
28
51
  #
29
52
  # Example:
30
53
  #
31
- # SqliteExt.register_create_function 'sqrt', 1 do |fn,x|
32
- # fn.result =
33
- # case x
34
- # when nil then nil
35
- # else Math.sqrt(x)
36
- # end
37
- # end
54
+ # SqliteExt.register_create_function 'sqrt', 1 do |fn,x|
55
+ # fn.result =
56
+ # case x
57
+ # when nil then nil
58
+ # else Math.sqrt(x)
59
+ # end
60
+ # end
61
+ #
62
+ # SQLite3::Database.new 'data.db' do |db|
63
+ # puts db.execute("SELECT sqrt(25)")[0][0]
64
+ # end
65
+ # # Output: 5.0
38
66
  #
39
- # SQLite3::Database.new 'data.db' do |db|
40
- # puts db.execute("SELECT sqrt(25)")[0][0]
41
- # end
42
- # # Output: 5.0
43
67
  def register_create_function(name, arity, *other_args, &block)
44
68
  name = "#{name}"
45
69
  registered_function_creations[name] = [
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Jorgensen