flounder 0.6.1 → 0.7.0
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/flounder.gemspec +1 -1
- data/lib/flounder/entity.rb +2 -2
- data/lib/flounder/query.rb +12 -0
- data/qed/insdate.md +15 -13
- data/qed/selects.md +1 -1
- data/qed/updates.md +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3cf7329905c8c1b1379adeb8474f9ec7f594b77
|
4
|
+
data.tar.gz: 9806546b6fbb16077607e0b60930a051fbab9d1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c74c0f97d0a716d094d0af54a3292ba5060c051e913a2b46046942ec92291005474abad4dbe3c692f1391bc3d323d7cd16d514fe92be18d2488f4b4491050156
|
7
|
+
data.tar.gz: b026b324cc4589a2da8c3ae677dbcbd65ad334637ce97b4ad8af5233180e67265bf396199771f625cad198114ad9c2f7c6974a4cfe98029a38045cd4718ab645
|
data/flounder.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "flounder"
|
5
|
-
s.version = '0.
|
5
|
+
s.version = '0.7.0'
|
6
6
|
s.summary = "Flounder is a way to write SQL simply in Ruby. It deals with everything BUT object relational mapping. "
|
7
7
|
s.email = "kaspar.schiess@technologyastronauts.ch"
|
8
8
|
s.homepage = "https://bitbucket.org/technologyastronauts/laboratory_flounder"
|
data/lib/flounder/entity.rb
CHANGED
@@ -66,7 +66,7 @@ module Flounder
|
|
66
66
|
def insdate fields, hash, &inserted
|
67
67
|
found = where(hash.select { |k, _| fields.include?(k) }).first
|
68
68
|
if found
|
69
|
-
update(hash).where(:id =>
|
69
|
+
update(hash).where(:id => found.id)
|
70
70
|
else
|
71
71
|
insert(hash, &inserted)
|
72
72
|
end
|
@@ -99,7 +99,7 @@ module Flounder
|
|
99
99
|
end
|
100
100
|
|
101
101
|
# Kickers
|
102
|
-
[:first, :all, :size].each do |name|
|
102
|
+
[:first, :all, :size, :delete].each do |name|
|
103
103
|
define_method name do |*args|
|
104
104
|
q = query
|
105
105
|
q.send(name, *args)
|
data/lib/flounder/query.rb
CHANGED
@@ -140,6 +140,18 @@ module Flounder
|
|
140
140
|
|
141
141
|
all.first.count
|
142
142
|
end
|
143
|
+
def delete
|
144
|
+
# things.where(...).delete.all
|
145
|
+
#
|
146
|
+
# Code that I actually want:
|
147
|
+
#
|
148
|
+
# @manager = manager.compile_delete
|
149
|
+
# self
|
150
|
+
#
|
151
|
+
# But for now it's a kicker:
|
152
|
+
#
|
153
|
+
engine.exec(manager.compile_delete.to_sql)
|
154
|
+
end
|
143
155
|
|
144
156
|
# Returns all rows of the query result as an array. Individual rows are
|
145
157
|
# mapped to objects using the row mapper.
|
data/qed/insdate.md
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
Flounder offers Insdate.
|
2
2
|
|
3
3
|
~~~ruby
|
4
|
-
|
4
|
+
post = posts.first
|
5
5
|
|
6
|
-
# Update if found.
|
7
|
-
#
|
8
|
-
results = users.insdate([:id], :id => user.id, :name => 'Mr. Insdate Update') do |u|
|
9
|
-
assert false # Not called.
|
10
|
-
end.returning
|
11
|
-
results.first.name.assert == 'Mr. Insdate Update'
|
12
|
-
|
13
6
|
# Insert if not found.
|
14
7
|
#
|
15
|
-
|
8
|
+
post = posts.insdate([:title], :title => 'Insdate Insert', :text => '', :user_id => users.first.id) do |u|
|
16
9
|
u.assert # Is called.
|
17
|
-
end.returning
|
18
|
-
|
10
|
+
end.returning.first
|
11
|
+
post.title.assert == 'Insdate Insert'
|
12
|
+
post.text.assert == ''
|
13
|
+
|
14
|
+
# Update if found with the fields.
|
15
|
+
#
|
16
|
+
post = posts.insdate([:title], :title => 'Insdate Insert', :text => 'Insdate Update Text') do |u|
|
17
|
+
assert false # Not called.
|
18
|
+
end.returning.first
|
19
|
+
post.title.assert == 'Insdate Insert'
|
20
|
+
post.text.assert == 'Insdate Update Text'
|
19
21
|
|
20
|
-
# Reset QED.
|
22
|
+
# Reset this particular QED.
|
21
23
|
#
|
22
|
-
|
24
|
+
posts.where(:id => post.id).delete.first
|
23
25
|
~~~
|
data/qed/selects.md
CHANGED
@@ -27,7 +27,7 @@ If we want to see all records, we use the `all` kicker, which has some synonyms.
|
|
27
27
|
|
28
28
|
~~~ruby
|
29
29
|
users = domain[:users].all
|
30
|
-
users.size.assert ==
|
30
|
+
users.size.assert == 6
|
31
31
|
users.assert.kind_of? Array
|
32
32
|
|
33
33
|
domain[:users].map(&:id).assert == users.map(&:id)
|
data/qed/updates.md
CHANGED
@@ -64,5 +64,5 @@ Updating multiple rows is possible.
|
|
64
64
|
~~~ruby
|
65
65
|
updated = users.update(:name => 'Update Multiple Rows').where(:name.not_eq => nil).returning
|
66
66
|
|
67
|
-
updated.map(&:name).assert == ['Update Multiple Rows']*
|
67
|
+
updated.map(&:name).assert == ['Update Multiple Rows']*6
|
68
68
|
~~~
|