rhubarb 0.2.2 → 0.2.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.
- data/CHANGES +10 -1
- data/TODO +0 -1
- data/VERSION +1 -1
- data/lib/rhubarb/classmixins.rb +18 -10
- data/lib/rhubarb/persistence.rb +11 -2
- data/lib/rhubarb/persisting.rb +9 -4
- data/lib/rhubarb/rhubarb.rb +0 -1
- data/ruby-rhubarb.spec.in +7 -1
- metadata +2 -2
data/CHANGES
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
version 0.2.
|
|
1
|
+
version 0.2.3
|
|
2
|
+
|
|
3
|
+
* Rhubarb now uses prepared statements almost exclusively. This
|
|
4
|
+
should result in an appreciable speedup (I observed around 10% on
|
|
5
|
+
the test suite; a large rhubarb-based application I have previously
|
|
6
|
+
spent over 12% of runtime preparing one-off statemtents).
|
|
7
|
+
|
|
8
|
+
* Fixed a crashing bug introduced in 0.2.2.
|
|
9
|
+
|
|
10
|
+
version 0.2.2 (8859efbbbca5e80d64e3bd8e6e5ba2ffd8a3e83d)
|
|
2
11
|
|
|
3
12
|
* explicit support for :blob-typed columns (blob values will be
|
|
4
13
|
appropriately stored in create statements and attribute assignments).
|
data/TODO
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* Bring code coverage up to 100%
|
|
5
5
|
* Documentation
|
|
6
6
|
* Standalone examples (i.e. not just "please see the test suite")
|
|
7
|
-
* Resolve issues related to using prepared statements
|
|
8
7
|
* Find rows by value of blob-valued field
|
|
9
8
|
* Automatic zlib compression of blobs (:zblob type)
|
|
10
9
|
* Automatic yaml serialization of arbitrary Ruby objects (:rubyobj type)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.3
|
data/lib/rhubarb/classmixins.rb
CHANGED
|
@@ -53,13 +53,18 @@ module Rhubarb
|
|
|
53
53
|
valid_cols = self.colnames.intersection arg_hash.keys
|
|
54
54
|
select_criteria = valid_cols.map {|col| "#{col.to_s} = #{col.inspect}"}.join(" AND ")
|
|
55
55
|
arg_hash.each {|k,v| arg_hash[k] = v.row_id if v.respond_to? :row_id}
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
find_by_text = "select * from #{table_name} where #{select_criteria} order by row_id"
|
|
57
|
+
find_by_stmt = (db.stmts[find_by_text] ||= db.prepare(find_by_text))
|
|
58
|
+
find_by_stmt.execute!(arg_hash).map {|tup| self.new(tup) }
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
# Does what it says on the tin. Since this will allocate an object for each row, it isn't recomended for huge tables.
|
|
61
62
|
def find_all
|
|
62
|
-
|
|
63
|
+
results = []
|
|
64
|
+
find_all_text = "SELECT * from #{table_name}"
|
|
65
|
+
find_all_stmt = (db.stmts[find_all_text] ||= db.prepare(find_all_text))
|
|
66
|
+
find_all_stmt.execute! {|tup| results << self.new(tup)}
|
|
67
|
+
results
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
def delete_all
|
|
@@ -78,8 +83,10 @@ module Rhubarb
|
|
|
78
83
|
define_method name.to_s do |*args|
|
|
79
84
|
# handle reference parameters
|
|
80
85
|
args = args.map {|arg| Util::rhubarb_fk_identity(arg)}
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
cq_text = query.gsub("__TABLE__", "#{self.table_name}")
|
|
87
|
+
cq_stmt = (db.stmts[cq_text] ||= db.prepare(cq_text))
|
|
88
|
+
|
|
89
|
+
res = cq_stmt.execute!(args)
|
|
83
90
|
res.map {|row| self.new(row) }
|
|
84
91
|
end
|
|
85
92
|
end
|
|
@@ -212,8 +219,9 @@ module Rhubarb
|
|
|
212
219
|
new_row[column] = colkinds[column] == :blob ? Util::blobify(value) : Util::rhubarb_fk_identity(value)
|
|
213
220
|
end
|
|
214
221
|
|
|
215
|
-
|
|
216
|
-
db.
|
|
222
|
+
create_text = "insert into #{table_name} (#{colspec}) values (#{valspec})"
|
|
223
|
+
create_stmt = (self.db.stmts[create_text] ||= db.prepare(create_text))
|
|
224
|
+
create_stmt.execute!(new_row)
|
|
217
225
|
res = find(db.last_insert_row_id)
|
|
218
226
|
|
|
219
227
|
res
|
|
@@ -272,11 +280,11 @@ module Rhubarb
|
|
|
272
280
|
self.db.get_first_value("select count(row_id) from #{table_name}").to_i
|
|
273
281
|
end
|
|
274
282
|
|
|
275
|
-
def find_tuple(
|
|
276
|
-
self.db.get_first_row("select * from #{table_name} where row_id = ?",
|
|
283
|
+
def find_tuple(tid)
|
|
284
|
+
self.db.get_first_row("select * from #{table_name} where row_id = ?", tid)
|
|
277
285
|
end
|
|
278
286
|
|
|
279
287
|
include FindFreshest
|
|
280
288
|
|
|
281
289
|
end
|
|
282
|
-
end
|
|
290
|
+
end
|
data/lib/rhubarb/persistence.rb
CHANGED
|
@@ -24,6 +24,13 @@ module Rhubarb
|
|
|
24
24
|
def setup_db(db)
|
|
25
25
|
db.results_as_hash = true
|
|
26
26
|
db.type_translation = true
|
|
27
|
+
db.busy_timeout(150)
|
|
28
|
+
class << db
|
|
29
|
+
def stmts
|
|
30
|
+
@rhubarb_stmts ||= {}
|
|
31
|
+
@rhubarb_stmts
|
|
32
|
+
end
|
|
33
|
+
end
|
|
27
34
|
end
|
|
28
35
|
end
|
|
29
36
|
|
|
@@ -34,9 +41,11 @@ module Rhubarb
|
|
|
34
41
|
end
|
|
35
42
|
|
|
36
43
|
def self.close(which=:default)
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
current_db = dbs[which]
|
|
45
|
+
if current_db
|
|
39
46
|
dbs.delete(which)
|
|
47
|
+
current_db.stmts.values.each {|pstmt| pstmt.close }
|
|
48
|
+
current_db.close
|
|
40
49
|
end
|
|
41
50
|
end
|
|
42
51
|
|
data/lib/rhubarb/persisting.rb
CHANGED
|
@@ -37,7 +37,7 @@ module Rhubarb
|
|
|
37
37
|
|
|
38
38
|
def hash
|
|
39
39
|
freshen
|
|
40
|
-
@row_id ^ self.table_name.hash
|
|
40
|
+
@row_id ^ self.class.table_name.hash
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def ==(other)
|
|
@@ -62,7 +62,9 @@ module Rhubarb
|
|
|
62
62
|
# Deletes the row corresponding to this object from the database;
|
|
63
63
|
# invalidates =self= and any other objects backed by this row
|
|
64
64
|
def delete
|
|
65
|
-
|
|
65
|
+
delete_text = "delete from #{self.class.table_name} where row_id = ?"
|
|
66
|
+
delete_stmt = (self.db.stmts[delete_text] ||= self.db.prepare(delete_text))
|
|
67
|
+
delete_stmt.execute!(@row_id)
|
|
66
68
|
mark_dirty
|
|
67
69
|
@tuple = nil
|
|
68
70
|
@row_id = nil
|
|
@@ -110,7 +112,10 @@ module Rhubarb
|
|
|
110
112
|
# Helper method to update the row in the database when one of our fields changes
|
|
111
113
|
def update(attr_name, value)
|
|
112
114
|
mark_dirty
|
|
113
|
-
|
|
115
|
+
|
|
116
|
+
update_text = "update #{self.class.table_name} set #{attr_name} = ?, updated = ? where row_id = ?"
|
|
117
|
+
update_stmt = (self.db.stmts[update_text] ||= self.db.prepare(update_text))
|
|
118
|
+
update_stmt.execute!(value, Util::timestamp, @row_id)
|
|
114
119
|
end
|
|
115
120
|
|
|
116
121
|
# Resolve any fields that reference other tables, replacing row ids with referred objects
|
|
@@ -129,4 +134,4 @@ module Rhubarb
|
|
|
129
134
|
end
|
|
130
135
|
|
|
131
136
|
end
|
|
132
|
-
end
|
|
137
|
+
end
|
data/lib/rhubarb/rhubarb.rb
CHANGED
data/ruby-rhubarb.spec.in
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
%{!?ruby_sitelib: %global ruby_sitelib %(ruby -rrbconfig -e 'puts Config::CONFIG["sitelibdir"] ')}
|
|
2
|
-
%define rel 0
|
|
2
|
+
%define rel 1.0
|
|
3
3
|
|
|
4
4
|
Summary: Simple versioned object-graph persistence layer
|
|
5
5
|
Name: ruby-rhubarb
|
|
@@ -48,6 +48,12 @@ rm -rf %{buildroot}
|
|
|
48
48
|
%{ruby_sitelib}/rhubarb/persistence.rb
|
|
49
49
|
|
|
50
50
|
%changelog
|
|
51
|
+
* Thu Feb 25 2010 willb <willb@redhat> - 0.2.3-1.0
|
|
52
|
+
* updated to version 0.2.3 from source
|
|
53
|
+
|
|
54
|
+
* Thu Feb 25 2010 willb <willb@redhat> - 0.2.2-2.0
|
|
55
|
+
* removed rubygems include
|
|
56
|
+
|
|
51
57
|
* Fri Feb 5 2010 <rrat@redhat> - 0.2.0-0.3
|
|
52
58
|
- Explicitly list files
|
|
53
59
|
- Added ruby(abi) and dependency
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rhubarb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- William Benton
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2010-02-
|
|
12
|
+
date: 2010-02-26 00:00:00 -06:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|