rdbi-result-driver-json 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
@@ -0,0 +1,2 @@
1
+ require 'rdbi'
2
+ require 'rdbi/result/driver/json'
@@ -19,17 +19,31 @@ class RDBI::Result::Driver::JSON < RDBI::Result::Driver
19
19
 
20
20
  @result.schema.columns.map(&:name).each { |name| index.push(name); obj_hash[name] = nil }
21
21
 
22
- @result.raw_fetch(row_count).each do |row|
22
+ if [:first, :last].include?(row_count)
23
23
  my_hash = obj_hash.dup
24
- row.each_with_index do |col, i|
24
+ @result.raw_fetch(row_count)[0].each_with_index do |col, i|
25
25
  my_hash[index[i]] = col
26
26
  end
27
- results.push my_hash
27
+ return ::JSON.dump(my_hash)
28
+ else
29
+ @result.raw_fetch(row_count).each do |row|
30
+ my_hash = obj_hash.dup
31
+ row.each_with_index do |col, i|
32
+ my_hash[index[i]] = col
33
+ end
34
+ results.push my_hash
35
+ end
36
+
37
+ File.open('/tmp/foo', 'w') << results.inspect
38
+ return ::JSON.dump(results)
28
39
  end
29
40
 
30
- return ::JSON.dump(results)
31
41
  else
32
- return ::JSON.dump(@result.raw_fetch(row_count))
42
+ if [:first, :last].include?(row_count)
43
+ return ::JSON.dump(@result.raw_fetch(row_count)[0])
44
+ else
45
+ return ::JSON.dump(@result.raw_fetch(row_count))
46
+ end
33
47
  end
34
48
  end
35
49
  end
@@ -1,41 +1,40 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rdbi-result-driver-json}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Hollensbe"]
12
- s.date = %q{2010-08-21}
12
+ s.date = %q{2010-12-10}
13
13
  s.description = %q{JSON result output for RDBI}
14
14
  s.email = %q{erik@hollensbe.org}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/rdbi/result/driver/json.rb",
27
- "rdbi-result-driver-json.gemspec",
28
- "test/helper.rb",
29
- "test/test_driver.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/rdbi-result-driver-json.rb",
26
+ "lib/rdbi/result/driver/json.rb",
27
+ "rdbi-result-driver-json.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_driver.rb"
30
30
  ]
31
31
  s.homepage = %q{http://github.com/RDBI/rdbi-result-driver-json}
32
- s.rdoc_options = ["--charset=UTF-8"]
33
32
  s.require_paths = ["lib"]
34
33
  s.rubygems_version = %q{1.3.7}
35
34
  s.summary = %q{JSON result output for RDBI}
36
35
  s.test_files = [
37
36
  "test/helper.rb",
38
- "test/test_driver.rb"
37
+ "test/test_driver.rb"
39
38
  ]
40
39
 
41
40
  if s.respond_to? :specification_version then
@@ -16,7 +16,7 @@ class Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def mock_statement_with_results(dbh, results)
19
- sth = dbh.prepare("some statmeent")
19
+ sth = dbh.prepare("some statement")
20
20
  sth.result = results
21
21
  return sth
22
22
  end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'json'
2
3
 
3
4
  class TestDriver < Test::Unit::TestCase
4
5
  def setup
@@ -18,6 +19,12 @@ class TestDriver < Test::Unit::TestCase
18
19
  json = sth.execute.as(:JSON).fetch(:all)
19
20
  assert_equal('[[1,2,3]]', json)
20
21
 
22
+ json = sth.execute.as(:JSON).first
23
+ assert_equal('[1,2,3]', json)
24
+
25
+ json = sth.execute.as(:JSON).last
26
+ assert_equal('[1,2,3]', json)
27
+
21
28
  sth.finish
22
29
  end
23
30
 
@@ -26,10 +33,37 @@ class TestDriver < Test::Unit::TestCase
26
33
  sth = mock_statement_with_results(@dbh, [[1,2,3]])
27
34
 
28
35
  json = sth.execute.fetch(:all, :JSON, :as_object => true)
29
- assert_equal("[{\"5\":null,\"0\":1,\"6\":null,\"1\":2,\"7\":null,\"2\":3,\"8\":null,\"3\":null,\"9\":null,\"4\":null}]", json)
30
-
36
+ assert_equal(
37
+ {
38
+ "0" => 1,
39
+ "1" => 2,
40
+ "2" => 3,
41
+ }, JSON.load(json)[0].reject { |x,y| y.nil? })
42
+
43
+
31
44
  json = sth.execute.as(:JSON, :as_object => true).fetch(:all)
32
- assert_equal("[{\"5\":null,\"0\":1,\"6\":null,\"1\":2,\"7\":null,\"2\":3,\"8\":null,\"3\":null,\"9\":null,\"4\":null}]", json)
45
+ assert_equal(
46
+ {
47
+ "0" => 1,
48
+ "1" => 2,
49
+ "2" => 3,
50
+ }, JSON.load(json)[0].reject { |x,y| y.nil? })
51
+
52
+ json = sth.execute.as(:JSON, :as_object => true).first
53
+ assert_equal(
54
+ {
55
+ "0" => 1,
56
+ "1" => 2,
57
+ "2" => 3,
58
+ }, JSON.load(json).reject { |x,y| y.nil? })
59
+
60
+ json = sth.execute.as(:JSON, :as_object => true).last
61
+ assert_equal(
62
+ {
63
+ "0" => 1,
64
+ "1" => 2,
65
+ "2" => 3,
66
+ }, JSON.load(json).reject { |x,y| y.nil? })
33
67
 
34
68
  sth.finish
35
69
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdbi-result-driver-json
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
7
+ - 2
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ version: 0.2.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Erik Hollensbe
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-21 00:00:00 -04:00
17
+ date: 2010-12-10 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 3
58
54
  segments:
59
55
  - 0
60
56
  version: "0"
@@ -71,11 +67,11 @@ extra_rdoc_files:
71
67
  - README.rdoc
72
68
  files:
73
69
  - .document
74
- - .gitignore
75
70
  - LICENSE
76
71
  - README.rdoc
77
72
  - Rakefile
78
73
  - VERSION
74
+ - lib/rdbi-result-driver-json.rb
79
75
  - lib/rdbi/result/driver/json.rb
80
76
  - rdbi-result-driver-json.gemspec
81
77
  - test/helper.rb
@@ -85,8 +81,8 @@ homepage: http://github.com/RDBI/rdbi-result-driver-json
85
81
  licenses: []
86
82
 
87
83
  post_install_message:
88
- rdoc_options:
89
- - --charset=UTF-8
84
+ rdoc_options: []
85
+
90
86
  require_paths:
91
87
  - lib
92
88
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -94,7 +90,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
90
  requirements:
95
91
  - - ">="
96
92
  - !ruby/object:Gem::Version
97
- hash: 3
98
93
  segments:
99
94
  - 0
100
95
  version: "0"
@@ -103,7 +98,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
98
  requirements:
104
99
  - - ">="
105
100
  - !ruby/object:Gem::Version
106
- hash: 3
107
101
  segments:
108
102
  - 0
109
103
  version: "0"
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC