swift 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'tempfile'
2
+ require_relative 'helper'
3
+
4
+ describe 'Swift' do
5
+ supported_by Swift::DB::Sqlite3 do
6
+ describe 'Trace' do
7
+ before do
8
+ Swift.trace(false)
9
+ @file = Tempfile.new('swift-test')
10
+ end
11
+
12
+ after do
13
+ @file.unlink
14
+ end
15
+
16
+ it 'should trace commands' do
17
+ sql = 'create table users (id integer, name text)'
18
+ Swift.trace(true, @file)
19
+ Swift.db.execute(sql)
20
+
21
+ log = @file.rewind && @file.read
22
+ assert_match sql, log
23
+ end
24
+
25
+ it 'should trace commands in block form' do
26
+ sql1 = 'create table users (id integer, name text)'
27
+ sql2 = 'drop table users'
28
+
29
+ res = Swift.trace(true, @file) { Swift.db.execute(sql1) && 'foobar' }
30
+ assert_equal 'foobar', res
31
+
32
+ Swift.db.execute(sql2)
33
+
34
+ log = @file.rewind && @file.read
35
+ assert_match sql1, log
36
+ refute_match sql2, log
37
+ end
38
+
39
+ it 'should trace commands in block form and preserve state' do
40
+ sql1 = 'create table users (id integer, name text)'
41
+ sql2 = 'drop table users'
42
+
43
+ Swift.trace(true, @file)
44
+
45
+ Swift.trace(false) do
46
+ Swift.db.execute(sql1)
47
+ end
48
+
49
+ Swift.db.execute(sql2)
50
+
51
+ log = @file.rewind && @file.read
52
+ refute_match sql1, log
53
+ assert_match sql2, log
54
+ end
55
+
56
+ it 'should cascade exceptions in block form trace' do
57
+ sql1 = 'create table users (id integer, name text)'
58
+
59
+ assert_raises(RuntimeError) do
60
+ Swift.trace(true, @file) do
61
+ Swift.db.execute(sql1)
62
+ raise "foo"
63
+ end
64
+ end
65
+
66
+ log = @file.rewind && @file.read
67
+ assert_match sql1, log
68
+ end
69
+ end
70
+ end
71
+ end
metadata CHANGED
@@ -1,63 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: swift
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 10
8
- - 0
9
- version: 0.10.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shane Hanna
13
9
  - Bharanee 'Barney' Rathna
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-04-04 00:00:00 +10:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-09-30 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: minitest
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &10219940 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 1
31
- - 7
32
- - 0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
33
22
  version: 1.7.0
34
23
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: eventmachine
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *10219940
26
+ - !ruby/object:Gem::Dependency
27
+ name: eventmachine
28
+ requirement: &10219160 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 0
46
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
47
34
  type: :development
48
- version_requirements: *id002
35
+ prerelease: false
36
+ version_requirements: *10219160
49
37
  description: A rational rudimentary database abstraction.
50
- email:
38
+ email:
51
39
  - shane.hanna@gmail.com
52
40
  - deepfryed@gmail.com
53
41
  executables: []
54
-
55
- extensions:
42
+ extensions:
56
43
  - ext/extconf.rb
57
- extra_rdoc_files:
44
+ extra_rdoc_files:
58
45
  - LICENSE
59
46
  - README.rdoc
60
- files:
47
+ files:
61
48
  - API.rdoc
62
49
  - LICENSE
63
50
  - README.rdoc
@@ -84,6 +71,7 @@ files:
84
71
  - ext/swift.h
85
72
  - lib/swift.rb
86
73
  - lib/swift/adapter.rb
74
+ - lib/swift/adapter/sql.rb
87
75
  - lib/swift/attribute.rb
88
76
  - lib/swift/db.rb
89
77
  - lib/swift/header.rb
@@ -96,6 +84,7 @@ files:
96
84
  - swift.gemspec
97
85
  - test/helper.rb
98
86
  - test/house-explode.jpg
87
+ - test/minitest_teardown_hack.rb
99
88
  - test/test_adapter.rb
100
89
  - test/test_encoding.rb
101
90
  - test/test_error.rb
@@ -103,58 +92,33 @@ files:
103
92
  - test/test_io.rb
104
93
  - test/test_pool.rb
105
94
  - test/test_scheme.rb
95
+ - test/test_swift.rb
106
96
  - test/test_timestamps.rb
107
97
  - test/test_transactions.rb
108
98
  - test/test_types.rb
109
99
  - test/test_validations.rb
110
- - examples/async.rb
111
- - examples/db.rb
112
- - examples/scheme.rb
113
- has_rdoc: true
114
100
  homepage: http://github.com/shanna/swift
115
101
  licenses: []
116
-
117
102
  post_install_message:
118
103
  rdoc_options: []
119
-
120
- require_paths:
104
+ require_paths:
121
105
  - lib
122
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
123
107
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- segments:
128
- - 0
129
- version: "0"
130
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
113
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- segments:
136
- - 0
137
- version: "0"
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
138
118
  requirements: []
139
-
140
119
  rubyforge_project:
141
- rubygems_version: 1.3.7
120
+ rubygems_version: 1.8.5
142
121
  signing_key:
143
122
  specification_version: 3
144
123
  summary: A rational rudimentary database abstraction.
145
- test_files:
146
- - examples/async.rb
147
- - examples/db.rb
148
- - examples/scheme.rb
149
- - test/helper.rb
150
- - test/test_adapter.rb
151
- - test/test_encoding.rb
152
- - test/test_error.rb
153
- - test/test_identity_map.rb
154
- - test/test_io.rb
155
- - test/test_pool.rb
156
- - test/test_scheme.rb
157
- - test/test_timestamps.rb
158
- - test/test_transactions.rb
159
- - test/test_types.rb
160
- - test/test_validations.rb
124
+ test_files: []
data/examples/async.rb DELETED
@@ -1,65 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require_relative '../lib/swift'
4
- require_relative '../lib/swift/pool'
5
-
6
- adapter = ARGV.first =~ /mysql/i ? Swift::DB::Mysql : Swift::DB::Postgres
7
- puts "Using DB: #{adapter}"
8
-
9
- Swift.setup :default, adapter, db: 'swift'
10
- Swift.trace true
11
-
12
- # create test table
13
- Swift.db do |db|
14
- puts '-- create --'
15
- db.execute('DROP TABLE IF EXISTS users')
16
- db.execute('CREATE TABLE users(id serial, name text, email text)')
17
-
18
- sample = DATA.read.split(/\n/).map {|v| v.split(/\t+/) }
19
-
20
- puts '-- insert --'
21
- ins = db.prepare('insert into users(name, email) values(?, ?)')
22
- 9.times {|n| ins.execute(*sample[n%3]) }
23
- end
24
-
25
- sleep_clause = {
26
- Swift::DB::Postgres => "case length(pg_sleep(%s)::text) when 0 then '%s' else '%s' end as sleep",
27
- Swift::DB::Mysql => "if (sleep(%s), '%s', '%s') as sleep"
28
- }
29
-
30
- puts '-- select 9 times with a pool of size 5 --'
31
- Swift.trace false
32
- Swift.pool(5) do |db|
33
- (1..9).each do |n|
34
- pause = '%0.3f' % ((20-n)/20.0)
35
- pause = sleep_clause[adapter] % 3.times.map { pause }
36
- db.execute("select *, #{pause} from users where id = ?", n) {|r| p r.first }
37
- end
38
- end
39
- Swift.trace true
40
-
41
- puts '-- multiple pools: size 2, size 1 --'
42
- EM.run {
43
- pool1 = Swift.pool(2)
44
- pool2 = Swift.pool(1)
45
-
46
- pool1.execute("select * from users limit 3 offset 0") do |rs|
47
- puts '-- Inside pool1 #callback --'
48
- rs.each {|r| p r }
49
- pool1.execute("select * from users limit 3 offset 3") do |rs|
50
- puts '-- Inside pool1 #callback again --'
51
- rs.each {|r| p r }
52
- EM.stop
53
- end
54
- end
55
-
56
- pool2.execute("select * from users limit 3 offset 6") do |rs|
57
- puts '-- Inside pool2 #callback --'
58
- rs.each {|r| p r }
59
- end
60
- }
61
-
62
- __END__
63
- Apple Arthurton apple@example.com
64
- Benny Arthurton benny@example.com
65
- James Arthurton james@example.com
data/examples/db.rb DELETED
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
-
5
- require 'pp'
6
- require 'swift'
7
- require 'swift/migrations'
8
-
9
- class User < Swift::Scheme
10
- store :users
11
- attribute :id, Swift::Type::Integer, serial: true, key: true
12
- attribute :name, Swift::Type::String
13
- attribute :email, Swift::Type::String
14
- end # User
15
-
16
- adapter = ARGV.first =~ /mysql/i ? Swift::DB::Mysql : Swift::DB::Postgres
17
- puts "Using DB: #{adapter}"
18
-
19
- Swift.setup :default, adapter, db: 'swift'
20
- Swift.trace true
21
-
22
- Swift.db do |db|
23
- db.migrate! User
24
-
25
- puts '-- create --'
26
- db.create(User,
27
- {name: 'Apple Arthurton', email: 'apple@arthurton.local'},
28
- {name: 'Benny Arthurton', email: 'benny@arthurton.local'}
29
- )
30
-
31
- puts '', '-- select --'
32
- pp users = db.prepare(User, 'select * from users').execute.to_a
33
-
34
- puts '', '-- update --'
35
- db.update(User, *users.map!{|user| user.name = 'Fred Nurk'; user})
36
- pp db.prepare(User, 'select * from users').execute.to_a
37
-
38
- puts '', '-- get --'
39
- pp db.get(User, id: 1)
40
-
41
- puts '', '-- destroy --'
42
- pp db.destroy(User, id: 1).map(&:rows).first
43
- end
44
-
data/examples/scheme.rb DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
-
5
- require 'pp'
6
- require 'swift'
7
- require 'swift/migrations'
8
- require 'swift/validations'
9
-
10
- class User < Swift::Scheme
11
- store :users
12
- attribute :id, Swift::Type::Integer, serial: true, key: true
13
- attribute :name, Swift::Type::String
14
- attribute :email, Swift::Type::String
15
- attribute :active, Swift::Type::Boolean
16
- attribute :created, Swift::Type::Time, default: proc { Time.now }
17
- attribute :optional, Swift::Type::String, default: 'woot'
18
-
19
- validations do |errors|
20
- errors << [:name, 'is blank'] if name.to_s.empty?
21
- end
22
- end # User
23
-
24
- adapter = ARGV.first =~ /mysql/i ? Swift::DB::Mysql : Swift::DB::Postgres
25
- puts "Using DB: #{adapter}"
26
-
27
- Swift.setup :default, adapter, db: 'swift'
28
- Swift.trace true
29
-
30
- puts '-- migrate! --'
31
- User.migrate!
32
-
33
- puts '', '-- create --'
34
- User.create name: 'Apple Arthurton', email: 'apple@arthurton.local'
35
- User.create name: 'Benny Arthurton', email: 'benny@arthurton.local'
36
-
37
- puts '', '-- all --'
38
- pp User.all.to_a
39
-
40
- puts '', '-- first --'
41
- pp User.first(':name like ?', '%Arthurton')
42
-
43
- puts '', '-- get --'
44
- pp user = User.get(id: 2)
45
- pp user = User.get(id: 2)
46
-
47
- puts '', '-- update --'
48
- user.update(name: 'Jimmy Arthurton')
49
-
50
- puts '', '-- destroy --'
51
- user.destroy
52
-
53
- puts '', '-- all --'
54
- pp User.all.to_a