micro_sql 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/Gemfile CHANGED
@@ -9,8 +9,10 @@ gem "sqlite3"
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
11
11
  group :development do
12
+ gem "rake"
13
+ gem "rdoc"
14
+
12
15
  gem "bundler"
13
- gem "jeweler"
14
16
  gem 'simplecov', :require => false
15
17
  gem "ruby-debug19"
16
18
  end
@@ -3,19 +3,13 @@ GEM
3
3
  specs:
4
4
  archive-tar-minitar (0.5.2)
5
5
  columnize (0.3.6)
6
- git (1.2.5)
7
- jeweler (1.8.3)
8
- bundler (~> 1.0)
9
- git (>= 1.2.5)
10
- rake
11
- rdoc
12
- json (1.6.6)
6
+ json (1.7.7)
13
7
  linecache19 (0.5.12)
14
8
  ruby_core_source (>= 0.1.4)
15
- multi_json (1.2.0)
16
- pg (0.13.2)
17
- rake (0.9.2.2)
18
- rdoc (3.12)
9
+ multi_json (1.7.2)
10
+ pg (0.15.0)
11
+ rake (10.0.4)
12
+ rdoc (4.0.1)
19
13
  json (~> 1.4)
20
14
  ruby-debug-base19 (0.11.25)
21
15
  columnize (>= 0.3.1)
@@ -27,19 +21,20 @@ GEM
27
21
  ruby-debug-base19 (>= 0.11.19)
28
22
  ruby_core_source (0.1.5)
29
23
  archive-tar-minitar (>= 0.5.2)
30
- simplecov (0.6.1)
24
+ simplecov (0.7.1)
31
25
  multi_json (~> 1.0)
32
- simplecov-html (~> 0.5.3)
33
- simplecov-html (0.5.3)
34
- sqlite3 (1.3.5)
26
+ simplecov-html (~> 0.7.1)
27
+ simplecov-html (0.7.1)
28
+ sqlite3 (1.3.7)
35
29
 
36
30
  PLATFORMS
37
31
  ruby
38
32
 
39
33
  DEPENDENCIES
40
34
  bundler
41
- jeweler
42
35
  pg
36
+ rake
37
+ rdoc
43
38
  ruby-debug19
44
39
  simplecov
45
40
  sqlite3
data/Rakefile CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require "bundler/gem_tasks"
6
+
5
7
  begin
6
8
  Bundler.setup(:default, :development)
7
9
  rescue Bundler::BundlerError => e
@@ -11,20 +13,6 @@ rescue Bundler::BundlerError => e
11
13
  end
12
14
  require 'rake'
13
15
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "micro_sql"
18
- gem.homepage = "http://github.com/radiospiel/micro_sql"
19
- gem.license = "MIT"
20
- gem.summary = %Q{A minimal ruby interface for SQL databases}
21
- gem.description = %Q{You only need a single method to talk to your database...}
22
- gem.email = "eno@open-lab.org"
23
- gem.authors = ["radiospiel"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
16
  require 'rake/testtask'
29
17
  Rake::TestTask.new(:test) do |test|
30
18
  test.libs << 'lib' << 'test'
@@ -51,3 +39,4 @@ Rake::RDocTask.new do |rdoc|
51
39
  rdoc.rdoc_files.include('README*')
52
40
  rdoc.rdoc_files.include('lib/**/*.rb')
53
41
  end
42
+
@@ -4,7 +4,13 @@ require "json"
4
4
 
5
5
  class MicroSql::KeyValueTable < MicroSql::Table
6
6
  def initialize(db, table_name = "settings")
7
- super db, "CREATE TABLE #{table_name}(uid TEXT PRIMARY KEY, value TEXT, ttl INTEGER NOT NULL)"
7
+ sql = if db.is_a?(MicroSql::PgAdapter)
8
+ "CREATE TABLE #{table_name}_b(uid TEXT PRIMARY KEY, value BYTEA, ttl INTEGER NOT NULL)"
9
+ else
10
+ "CREATE TABLE #{table_name}(uid TEXT PRIMARY KEY, value TEXT, ttl INTEGER NOT NULL)"
11
+ end
12
+
13
+ super db, sql
8
14
  end
9
15
 
10
16
  def [](key)
@@ -46,10 +52,16 @@ class MicroSql::KeyValueTable < MicroSql::Table
46
52
 
47
53
  def decode(io)
48
54
  return unless io
55
+ return PG::Connection.unescape_bytea(io) if db.is_a?(MicroSql::PgAdapter)
56
+
49
57
  JSON.parse("[#{io}]").first
50
58
  end
51
59
 
52
60
  def encode(value)
53
- value && value.to_json
61
+ return unless value
62
+
63
+ return db.connection.escape_bytea(value.to_s) if db.is_a?(MicroSql::PgAdapter)
64
+
65
+ value.to_json
54
66
  end
55
67
  end
@@ -15,6 +15,10 @@ class MicroSql::PgAdapter < MicroSql
15
15
 
16
16
  TRANSACTION_STATUSES = %w(PQTRANS_IDLE PQTRANS_ACTIVE PQTRANS_INTRANS PQTRANS_INERROR PQTRANS_UNKNOWN)
17
17
 
18
+ def connection
19
+ @impl
20
+ end
21
+
18
22
  def transaction_status
19
23
  TRANSACTION_STATUSES[@impl.transaction_status]
20
24
  end
@@ -137,9 +141,10 @@ class MicroSql::PgAdapter < MicroSql
137
141
 
138
142
  def nop; end
139
143
 
140
- def string(s); s; end
144
+ def string(s); s; end
141
145
  def unknown(s); s; end
142
146
  def integer(s); s.to_i; end
147
+ def bytea(s); PG::Connection.unescape_bytea(s); end
143
148
  end
144
149
 
145
150
  def conversion_for(ftype, fmod)
@@ -1,72 +1,46 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ class Gem::Specification
2
+ class GemfileEvaluator
3
+ def initialize(scope)
4
+ @scope = scope
5
+ end
6
+
7
+ def load_dependencies(path)
8
+ instance_eval File.read(path)
9
+ end
10
+
11
+ def source(*args); end
12
+ def group(*args); end
13
+
14
+ def gem(name, options = {})
15
+ @scope.add_dependency(name)
16
+ end
17
+ end
18
+
19
+ def load_dependencies(file)
20
+ GemfileEvaluator.new(self).load_dependencies(file)
21
+ end
22
+ end
23
+
24
+ Gem::Specification.new do |gem|
25
+ gem.name = "micro_sql"
26
+ gem.authors = ["radiospiel"]
27
+ gem.email = ["eno@open-lab.org"]
28
+ gem.description = "You only need a single method to talk to your database..."
29
+ gem.summary = gem.description
30
+ gem.homepage = "http://github.com/radiospiel/micro_sql"
31
+ gem.licenses = ["MIT"]
5
32
 
6
- Gem::Specification.new do |s|
7
- s.name = "micro_sql"
8
- s.version = "0.3.2"
33
+ gem.load_dependencies "Gemfile"
34
+
35
+ gem.files = `git ls-files`.split($\)
36
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
37
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
38
+ gem.require_paths = ["lib"]
39
+ gem.version = "0.4.1"
40
+ gem.date = Time.now.strftime "%Y-%m-%d"
9
41
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["radiospiel"]
12
- s.date = "2012-04-04"
13
- s.description = "You only need a single method to talk to your database..."
14
- s.email = "eno@open-lab.org"
15
- s.extra_rdoc_files = [
42
+ gem.extra_rdoc_files = [
16
43
  "LICENSE.txt",
17
44
  "README.rdoc"
18
45
  ]
19
- s.files = [
20
- ".document",
21
- "Gemfile",
22
- "Gemfile.lock",
23
- "LICENSE.txt",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/micro_sql.rb",
28
- "lib/micro_sql/key_value_table.rb",
29
- "lib/micro_sql/pg_adapter.rb",
30
- "lib/micro_sql/sqlite_adapter.rb",
31
- "lib/micro_sql/table.rb",
32
- "micro_sql.gemspec",
33
- "script/watchr",
34
- "test/helper.rb",
35
- "test/test_micro_sql.rb",
36
- "test/test_micro_sql_pg.rb",
37
- "test/test_micro_sql_sqlite3.rb"
38
- ]
39
- s.homepage = "http://github.com/radiospiel/micro_sql"
40
- s.licenses = ["MIT"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = "1.8.17"
43
- s.summary = "A minimal ruby interface for SQL databases"
44
-
45
- if s.respond_to? :specification_version then
46
- s.specification_version = 3
47
-
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<pg>, [">= 0"])
50
- s.add_runtime_dependency(%q<sqlite3>, [">= 0"])
51
- s.add_development_dependency(%q<bundler>, [">= 0"])
52
- s.add_development_dependency(%q<jeweler>, [">= 0"])
53
- s.add_development_dependency(%q<simplecov>, [">= 0"])
54
- s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
55
- else
56
- s.add_dependency(%q<pg>, [">= 0"])
57
- s.add_dependency(%q<sqlite3>, [">= 0"])
58
- s.add_dependency(%q<bundler>, [">= 0"])
59
- s.add_dependency(%q<jeweler>, [">= 0"])
60
- s.add_dependency(%q<simplecov>, [">= 0"])
61
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
62
- end
63
- else
64
- s.add_dependency(%q<pg>, [">= 0"])
65
- s.add_dependency(%q<sqlite3>, [">= 0"])
66
- s.add_dependency(%q<bundler>, [">= 0"])
67
- s.add_dependency(%q<jeweler>, [">= 0"])
68
- s.add_dependency(%q<simplecov>, [">= 0"])
69
- s.add_dependency(%q<ruby-debug19>, [">= 0"])
70
- end
71
46
  end
72
-
@@ -134,14 +134,14 @@ class TestMicroSqlPg < Test::Unit::TestCase
134
134
 
135
135
  def test_kv_table
136
136
  kv = db.key_value_table("kv")
137
- assert_equal [ "kv" ], db.tables
137
+ assert_equal [ "kv_b" ], db.tables
138
138
 
139
139
  kv["x"] = "y"
140
- assert_equal 1, db.ask("SELECT COUNT(*) FROM kv")
140
+ assert_equal 1, db.ask("SELECT COUNT(*) FROM kv_b")
141
141
  assert_equal "y", kv["x"]
142
142
 
143
143
  kv["x"] = nil
144
- assert_equal 0, db.ask("SELECT COUNT(*) FROM kv")
144
+ assert_equal 0, db.ask("SELECT COUNT(*) FROM kv_b")
145
145
  assert_equal nil, kv["x"]
146
146
 
147
147
  count = 0
@@ -152,4 +152,15 @@ class TestMicroSqlPg < Test::Unit::TestCase
152
152
  r = kv.cached "x" do raise "Yo"; "y" end
153
153
  assert_equal(r, "y")
154
154
  end
155
+
156
+
157
+ def test_kv_table_binary
158
+ s = (0..255).to_a.pack('c*')
159
+
160
+ kv = db.key_value_table("kv")
161
+
162
+ kv["bin"] = s
163
+ assert_equal 1, db.ask("SELECT COUNT(*) FROM kv_b")
164
+ assert_equal s, kv["bin"]
165
+ end
155
166
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2013-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
16
- requirement: &70179126169140 !ruby/object:Gem::Requirement
16
+ requirement: &70229637156100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70179126169140
24
+ version_requirements: *70229637156100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70179126168360 !ruby/object:Gem::Requirement
27
+ requirement: &70229637155300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,53 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70179126168360
36
- - !ruby/object:Gem::Dependency
37
- name: bundler
38
- requirement: &70179126167420 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70179126167420
47
- - !ruby/object:Gem::Dependency
48
- name: jeweler
49
- requirement: &70179126166660 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70179126166660
58
- - !ruby/object:Gem::Dependency
59
- name: simplecov
60
- requirement: &70179126165880 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70179126165880
69
- - !ruby/object:Gem::Dependency
70
- name: ruby-debug19
71
- requirement: &70179126165220 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70179126165220
35
+ version_requirements: *70229637155300
80
36
  description: You only need a single method to talk to your database...
81
- email: eno@open-lab.org
37
+ email:
38
+ - eno@open-lab.org
82
39
  executables: []
83
40
  extensions: []
84
41
  extra_rdoc_files:
@@ -86,6 +43,7 @@ extra_rdoc_files:
86
43
  - README.rdoc
87
44
  files:
88
45
  - .document
46
+ - .gitignore
89
47
  - Gemfile
90
48
  - Gemfile.lock
91
49
  - LICENSE.txt
@@ -118,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
76
  version: '0'
119
77
  segments:
120
78
  - 0
121
- hash: -4089216543794682112
79
+ hash: 304612758120307793
122
80
  required_rubygems_version: !ruby/object:Gem::Requirement
123
81
  none: false
124
82
  requirements:
@@ -127,8 +85,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
85
  version: '0'
128
86
  requirements: []
129
87
  rubyforge_project:
130
- rubygems_version: 1.8.17
88
+ rubygems_version: 1.8.10
131
89
  signing_key:
132
90
  specification_version: 3
133
- summary: A minimal ruby interface for SQL databases
134
- test_files: []
91
+ summary: You only need a single method to talk to your database...
92
+ test_files:
93
+ - test/helper.rb
94
+ - test/test_micro_sql.rb
95
+ - test/test_micro_sql_pg.rb
96
+ - test/test_micro_sql_sqlite3.rb