turntables 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +6 -0
- data/README.rdoc +13 -3
- data/lib/turntables/db_registry.rb +20 -15
- data/lib/turntables/turntable.rb +3 -2
- data/lib/turntables/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ee4536b7ea7b58f5416c33fa8bdb4cde1e8eaa
|
4
|
+
data.tar.gz: 097c92953b752ab4996cf0a8ed5a12e72a7ba6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef7a8a25ade7dc70efbd2fdcf466df097702d4a758ad0fbe21a739c70b1f1d9f24fb6db8ba01aac93f26732257a81c823392977df9b0cc9b3e83d69d1508cd13
|
7
|
+
data.tar.gz: acfc9fc10852499677a733e5265ec4dd6de00871dbcc84d4c1588b0ac81d57ab902081fe7baac356fac0995abb8248522244310758908ee2867d69e73933d7a5
|
data/ChangeLog.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -6,9 +6,15 @@
|
|
6
6
|
|
7
7
|
== Description
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
You can use this in order to manage your (simple) sqlite3 databases. I wanted
|
10
|
+
something light and simple in order to help on some development I'm doing on
|
11
|
+
my own. I found myself repeating a pattern most of this time, and decided to
|
12
|
+
bring an end to it by writing this gem.
|
13
|
+
|
14
|
+
The concept is inspired by the Rails migrations, and something else I've seen
|
15
|
+
in some Bukkit code. Ultimately the functionality of this library can be
|
16
|
+
further abstracted, and made more modular in the future, as well as translated
|
17
|
+
in other languages. But alas our mortal time is limited.
|
12
18
|
|
13
19
|
== Features
|
14
20
|
|
@@ -115,6 +121,10 @@ The monolithic transactions should be a combinations of all the versions, up to
|
|
115
121
|
the one it denotes. In other words, version 4 would be the combination of all
|
116
122
|
previous ones including itself {1.sql, 2.sql, 3.sql, 4.sql}.
|
117
123
|
|
124
|
+
If you require it, you can also query the version histories in your
|
125
|
+
application. To do so, you just need to use the VersionHistory active record,
|
126
|
+
in the turntables gem.
|
127
|
+
|
118
128
|
== Requirements
|
119
129
|
|
120
130
|
* I've tested this with Ruby Versions = {2.0, 1.9.3}, though you should not
|
@@ -15,8 +15,7 @@ class DbRegistry
|
|
15
15
|
# TODO we need to be able to set this somehow differently - applications
|
16
16
|
# might require to name their database with their own specific name.
|
17
17
|
def initialize(dbname="default.db")
|
18
|
-
@
|
19
|
-
@name = dbname
|
18
|
+
@name = dbname
|
20
19
|
end
|
21
20
|
|
22
21
|
# Execute (any sort) of sql
|
@@ -28,12 +27,9 @@ class DbRegistry
|
|
28
27
|
# DbRegistry.instance.execute(sql,"jon","doe")
|
29
28
|
# @return sql data
|
30
29
|
def execute(*sql)
|
31
|
-
|
30
|
+
get_handle.execute(*sql)
|
32
31
|
rescue => ex
|
33
|
-
|
34
|
-
puts ex.backtrace
|
35
|
-
puts "Offending sql: "
|
36
|
-
puts sql
|
32
|
+
print_exception ex
|
37
33
|
end
|
38
34
|
|
39
35
|
# For special queries that may contain multiple statements. For example a
|
@@ -42,19 +38,16 @@ class DbRegistry
|
|
42
38
|
# tables in sequence.
|
43
39
|
# @param sql is the sql that contains multiple statements
|
44
40
|
def execute_batch(sql)
|
45
|
-
|
41
|
+
get_handle.execute_batch(sql)
|
46
42
|
rescue => ex
|
47
|
-
|
48
|
-
puts ex.backtrace
|
49
|
-
puts "Offending sql: "
|
50
|
-
puts sql
|
43
|
+
print_exception ex
|
51
44
|
end
|
52
45
|
|
53
46
|
# Check if a table exists in the database
|
54
47
|
# @param name is the name of the table to check if exists
|
55
48
|
# @return true if table exists, false if not
|
56
49
|
def table_exists?(name)
|
57
|
-
val =
|
50
|
+
val = get_handle.execute(ExistsSql, "table", name)
|
58
51
|
1 == val.flatten[0]
|
59
52
|
end
|
60
53
|
|
@@ -62,14 +55,14 @@ class DbRegistry
|
|
62
55
|
# @warn This is mainly here for the rspec testing, and should not be used
|
63
56
|
# unless you really know what you're doing.
|
64
57
|
def close!
|
65
|
-
|
58
|
+
get_handle.close unless get_handle.closed?
|
66
59
|
end
|
67
60
|
|
68
61
|
# Open the database, with the name given previously
|
69
62
|
# @warn This is mainly here for the rspec testing, and should not be used
|
70
63
|
# unless you really know what you're doing.
|
71
64
|
def open!
|
72
|
-
@handle = SQLite3::Database.new(@name) if
|
65
|
+
@handle = SQLite3::Database.new(@name) if get_handle.closed?
|
73
66
|
end
|
74
67
|
|
75
68
|
# The database name
|
@@ -78,6 +71,18 @@ class DbRegistry
|
|
78
71
|
private
|
79
72
|
# Other classes should not use the database handle directly
|
80
73
|
attr :handle
|
74
|
+
|
75
|
+
def get_handle
|
76
|
+
@handle = SQLite3::Database.new(@name) if @handle.nil?
|
77
|
+
@handle end
|
78
|
+
|
79
|
+
def print_exception(ex)
|
80
|
+
$stderr.puts ex.message
|
81
|
+
$stderr.puts ex.backtrace
|
82
|
+
$stderr.puts "Offending sql: "
|
83
|
+
$stderr.puts sql
|
84
|
+
end
|
85
|
+
|
81
86
|
end
|
82
87
|
end
|
83
88
|
|
data/lib/turntables/turntable.rb
CHANGED
@@ -20,8 +20,8 @@ class Turntable
|
|
20
20
|
|
21
21
|
# Make the repository at a specific location instead of default.
|
22
22
|
def make_at!(location)
|
23
|
-
DbRegistry.instance.close!
|
24
23
|
DbRegistry.instance.name = location
|
24
|
+
DbRegistry.instance.close!
|
25
25
|
DbRegistry.instance.open!
|
26
26
|
make!
|
27
27
|
end
|
@@ -29,7 +29,8 @@ class Turntable
|
|
29
29
|
# Create the tables by going through each revision
|
30
30
|
def make!
|
31
31
|
if @repository.malformed?
|
32
|
-
raise TurntableException,
|
32
|
+
raise TurntableException,
|
33
|
+
"The directory structure at #{@repository.relative_dir} is malformed."
|
33
34
|
else
|
34
35
|
@repository.make!
|
35
36
|
end
|
data/lib/turntables/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turntables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- psyomn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|