micro_sql 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/micro_sql/pg_adapter.rb +41 -0
- data/micro_sql.gemspec +2 -2
- data/test/test_micro_sql_pg.rb +16 -0
- metadata +15 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/micro_sql/pg_adapter.rb
CHANGED
@@ -13,6 +13,47 @@ class MicroSql::PgAdapter < MicroSql
|
|
13
13
|
@impl.set_notice_receiver { |result| MicroSql.logger.info(result.error_message) }
|
14
14
|
end
|
15
15
|
|
16
|
+
TRANSACTION_STATUSES = %w(PQTRANS_IDLE PQTRANS_ACTIVE PQTRANS_INTRANS PQTRANS_INERROR PQTRANS_UNKNOWN)
|
17
|
+
|
18
|
+
def transaction_status
|
19
|
+
TRANSACTION_STATUSES[@impl.transaction_status]
|
20
|
+
end
|
21
|
+
|
22
|
+
def transaction?
|
23
|
+
status = @impl.transaction_status
|
24
|
+
status == PG::Connection::PQTRANS_INTRANS || status == PG::Connection::PQTRANS_INERROR
|
25
|
+
end
|
26
|
+
|
27
|
+
def transaction(&block)
|
28
|
+
return savepoint_transaction(&block) if transaction?
|
29
|
+
|
30
|
+
begin
|
31
|
+
r = nil
|
32
|
+
@impl.transaction do
|
33
|
+
r = yield
|
34
|
+
end
|
35
|
+
r
|
36
|
+
rescue RollbackException
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def savepoint_transaction(&block)
|
44
|
+
savepoint_name = "sqdb_#{object_id}"
|
45
|
+
|
46
|
+
exec! "SAVEPOINT #{savepoint_name}"
|
47
|
+
r = yield
|
48
|
+
exec! "RELEASE SAVEPOINT #{savepoint_name}"
|
49
|
+
r
|
50
|
+
rescue RollbackException
|
51
|
+
exec! "ROLLBACK TO SAVEPOINT #{savepoint_name}"
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
public
|
56
|
+
|
16
57
|
def tables
|
17
58
|
exec("SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' AND tablename NOT LIKE 'sql_%'").map(&:first)
|
18
59
|
end
|
data/micro_sql.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "micro_sql"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["radiospiel"]
|
12
|
-
s.date = "2012-04-
|
12
|
+
s.date = "2012-04-03"
|
13
13
|
s.description = "You only need a single method to talk to your database..."
|
14
14
|
s.email = "eno@open-lab.org"
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_micro_sql_pg.rb
CHANGED
@@ -99,6 +99,22 @@ class TestMicroSqlPg < Test::Unit::TestCase
|
|
99
99
|
assert_equal 1, db.ask("SELECT COUNT(*) FROM t1")
|
100
100
|
end
|
101
101
|
|
102
|
+
def test_nested_transaction
|
103
|
+
db.ask "CREATE TABLE t1(idx INTEGER PRIMARY KEY, b TEXT)"
|
104
|
+
|
105
|
+
foo = db.transaction do
|
106
|
+
db.ask("INSERT INTO t1 (idx,b) VALUES(12, 'twelve')")
|
107
|
+
db.transaction do
|
108
|
+
db.ask("INSERT INTO t1 (idx,b) VALUES(13, 'thirteen')")
|
109
|
+
db.rollback!
|
110
|
+
end
|
111
|
+
"bar"
|
112
|
+
end
|
113
|
+
|
114
|
+
assert_equal "bar", foo
|
115
|
+
assert_equal 1, db.ask("SELECT COUNT(*) FROM t1")
|
116
|
+
end
|
117
|
+
|
102
118
|
def test_insert
|
103
119
|
assert_equal([], db.tables)
|
104
120
|
t1 = db.table "CREATE TABLE t1(idx INTEGER PRIMARY KEY, b TEXT)"
|
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.
|
4
|
+
version: 0.3.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-
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pg
|
16
|
-
requirement: &
|
16
|
+
requirement: &70112976340220 !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: *
|
24
|
+
version_requirements: *70112976340220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &70112976338980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70112976338980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70112976337920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70112976337920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70112976336440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70112976336440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &70112976328460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70112976328460
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ruby-debug19
|
71
|
-
requirement: &
|
71
|
+
requirement: &70112976327360 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70112976327360
|
80
80
|
description: You only need a single method to talk to your database...
|
81
81
|
email: eno@open-lab.org
|
82
82
|
executables: []
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: 2450718260584937907
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|