motion-sqlite3 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +0 -1
- data/README.md +6 -0
- data/lib/motion-sqlite3/database.rb +15 -0
- data/lib/motion-sqlite3/version.rb +1 -1
- data/motion-sqlite3.gemspec +1 -1
- data/spec/database_spec.rb +33 -0
- metadata +7 -7
- data/.rvmrc +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc0d629a1d4122918dc1a81e793175ca57e82c4
|
4
|
+
data.tar.gz: 1b4a29b64c16b1a731a5124ed12f5cfb8c33b608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcb1864a24499ac5a039990495890dd6c3ee6f144e67856a9d4317e64bd277a8e2756144dbe0a5637091e7b2d80a001a65ca2bd852539b03b8b777387ae10f09
|
7
|
+
data.tar.gz: 904f8427a74a04edc1b5ff88810179405d9bcf43f3ff7211296a7564126c4c9ee4e50eecf01c38b1db1783727344fccd73b912975ba0c7eece26dcd3200a187d
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,12 @@ This is a tiny wrapper around the SQLite C API that's written in RubyMotion. It
|
|
4
4
|
|
5
5
|
Whenever possible, it uses Ruby idioms like blocks and exceptions.
|
6
6
|
|
7
|
+
[![Code Climate](https://codeclimate.com/github/mattgreen/motion-sqlite3.png)](https://codeclimate.com/github/mattgreen/motion-sqlite3) [![Build Status](https://travis-ci.org/mattgreen/motion-sqlite3.png?branch=master)](https://travis-ci.org/mattgreen/motion-sqlite3) [![Gem Version](https://badge.fury.io/rb/motion-sqlite3.png)](http://badge.fury.io/rb/motion-sqlite3)
|
8
|
+
|
9
|
+
Is it any good?
|
10
|
+
---------------
|
11
|
+
Yes.
|
12
|
+
|
7
13
|
Sample code
|
8
14
|
-----------
|
9
15
|
|
@@ -43,6 +43,21 @@ module SQLite3
|
|
43
43
|
execute(*args).first.values.first
|
44
44
|
end
|
45
45
|
|
46
|
+
def transaction(&block)
|
47
|
+
execute("BEGIN TRANSACTION")
|
48
|
+
|
49
|
+
begin
|
50
|
+
result = yield
|
51
|
+
rescue
|
52
|
+
execute("ROLLBACK TRANSACTION")
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
|
56
|
+
execute("COMMIT TRANSACTION")
|
57
|
+
|
58
|
+
result
|
59
|
+
end
|
60
|
+
|
46
61
|
private
|
47
62
|
|
48
63
|
def prepare(sql, params, &block)
|
data/motion-sqlite3.gemspec
CHANGED
data/spec/database_spec.rb
CHANGED
@@ -63,4 +63,37 @@ describe SQLite3::Database do
|
|
63
63
|
@db.execute_scalar("SELECT COUNT(*) FROM test WHERE age > ?", [20]).should == 2
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
describe "#transaction" do
|
68
|
+
it "commits the transaction if no error is raised" do
|
69
|
+
@db.transaction do
|
70
|
+
@db.execute("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
71
|
+
end
|
72
|
+
|
73
|
+
@db.execute_scalar("SELECT COUNT(*) FROM sqlite_master WHERE name = 'test'").should == 1
|
74
|
+
end
|
75
|
+
|
76
|
+
it "returns the value of the block" do
|
77
|
+
@db.transaction do
|
78
|
+
@db.execute("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
79
|
+
|
80
|
+
42
|
81
|
+
end.should == 42
|
82
|
+
end
|
83
|
+
|
84
|
+
it "aborts the transaction if an error is raised" do
|
85
|
+
begin
|
86
|
+
@db.transaction do
|
87
|
+
@db.execute("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
|
88
|
+
@db.execute("INSERT INTO test (name) VALUES (?)", ["brad"])
|
89
|
+
|
90
|
+
raise ArgumentError
|
91
|
+
end
|
92
|
+
|
93
|
+
rescue ArgumentError
|
94
|
+
end
|
95
|
+
|
96
|
+
@db.execute_scalar("SELECT COUNT(*) FROM sqlite_master WHERE name = 'test'").should == 0
|
97
|
+
end
|
98
|
+
end
|
66
99
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: motion.h
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
-
- ".
|
49
|
+
- ".travis.yml"
|
50
50
|
- Gemfile
|
51
51
|
- Guardfile
|
52
52
|
- README.md
|
data/.rvmrc
DELETED