flounder 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/flounder.gemspec +1 -1
- data/lib/flounder/connection.rb +2 -2
- data/lib/flounder/entity.rb +15 -0
- data/lib/flounder/query.rb +1 -1
- data/qed/conditions.md +13 -0
- data/qed/insdate.md +23 -0
- data/qed/inserts.md +7 -1
- data/qed/selects.md +1 -1
- data/qed/updates.md +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a661579acf9b8efd91248bf500928fa995ae4cf1
|
4
|
+
data.tar.gz: 70c604ee69bf1cf6a45b19724e85e865e35a335f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0315371d93b05f38a6902ced435eda2811eb2931db4647d4e1fa97610194a4d25b4cf1b4101b280ca4088570d6515743d7c8f48a4d46397c1a0ad4b42b6ed4c6
|
7
|
+
data.tar.gz: 16cbfd112bc6362748dedacb4472fdddf727f5f1038f90c74e90e6efd32c152a784b40360f8a1240deb7037118d8912edda7a7ef6115c89880cc6f569678d77f
|
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.6.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/connection.rb
CHANGED
@@ -83,8 +83,8 @@ module Flounder
|
|
83
83
|
# Certainly needs refactoring.
|
84
84
|
#
|
85
85
|
processed_entity, processed_name = yield name if block_given?
|
86
|
-
entity = processed_entity
|
87
|
-
name = processed_name
|
86
|
+
entity = processed_entity if processed_entity
|
87
|
+
name = processed_name if processed_name
|
88
88
|
|
89
89
|
typecast_value = typecast(type_oid, value)
|
90
90
|
|
data/lib/flounder/entity.rb
CHANGED
@@ -56,6 +56,21 @@ module Flounder
|
|
56
56
|
u.update(hash)
|
57
57
|
}
|
58
58
|
end
|
59
|
+
|
60
|
+
# Insert or update.
|
61
|
+
#
|
62
|
+
# TODO Envelop in transaction.
|
63
|
+
# Not sure yet where the right level of abstraction is to
|
64
|
+
# insert START TRANSACTION/COMMIT TRANSACTION.
|
65
|
+
#
|
66
|
+
def insdate fields, hash, &if_inserted
|
67
|
+
found = where(hash.select { |k, _| fields.include?(k) }).first
|
68
|
+
if found
|
69
|
+
update(hash).where(:id => hash.delete(:id))
|
70
|
+
else
|
71
|
+
insert(hash, &Proc.new)
|
72
|
+
end
|
73
|
+
end
|
59
74
|
|
60
75
|
# Temporarily creates a new entity that is available as if it was declared
|
61
76
|
# with the given plural and singular, but referencing to the same
|
data/lib/flounder/query.rb
CHANGED
data/qed/conditions.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
A simple use case.
|
2
|
+
|
3
|
+
~~~ruby
|
4
|
+
s2013 = domain[:users].where(:id => 1).first
|
5
|
+
s2013.user.id.assert == 1
|
6
|
+
~~~
|
7
|
+
|
8
|
+
# Using strings in where to allow for cases not covered in Flounder/Arel.
|
9
|
+
#
|
10
|
+
# ~~~ruby
|
11
|
+
# posts = domain[:posts].where('id == (?) OR title == "(?)"', 1, "Hello").all
|
12
|
+
# posts.first.id.assert == 1
|
13
|
+
# ~~~
|
data/qed/insdate.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Flounder offers Insdate.
|
2
|
+
|
3
|
+
~~~ruby
|
4
|
+
user = users.first
|
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
|
+
# Insert if not found.
|
14
|
+
#
|
15
|
+
results = users.insdate([:name], :name => 'Mr. Insdate Insert') do |u|
|
16
|
+
u.assert # Is called.
|
17
|
+
end.returning
|
18
|
+
results.first.name.assert == 'Mr. Insdate Insert'
|
19
|
+
|
20
|
+
# Reset QED.
|
21
|
+
#
|
22
|
+
users.update(:name => 'John Snow').where(:id => user.id).returning('*')
|
23
|
+
~~~
|
data/qed/inserts.md
CHANGED
@@ -40,4 +40,10 @@ Flounder fields can be used as keys.
|
|
40
40
|
results.first.name.assert == 'Mr. Flounder Field'
|
41
41
|
~~~
|
42
42
|
|
43
|
-
TODO It does not yet support multi-row inserts.
|
43
|
+
TODO It does not yet support multi-row inserts.
|
44
|
+
|
45
|
+
~~~ruby
|
46
|
+
# users.insert({ :name => 'Mr. First Row'}, { :name => 'Mr. Second Row' }).returning
|
47
|
+
# OR
|
48
|
+
# users.insert(:name => 'Mr. First Row').insert(:name => 'Mr. Second Row').returning
|
49
|
+
~~~
|
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 == 7
|
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']*7
|
68
68
|
~~~
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flounder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaspar Schiess
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arel
|
@@ -109,9 +109,11 @@ files:
|
|
109
109
|
- qed/applique/ae.rb
|
110
110
|
- qed/applique/flounder.rb
|
111
111
|
- qed/applique/setup_domain.rb
|
112
|
+
- qed/conditions.md
|
112
113
|
- qed/exceptions.md
|
113
114
|
- qed/flounder.sql
|
114
115
|
- qed/index.md
|
116
|
+
- qed/insdate.md
|
115
117
|
- qed/inserts.md
|
116
118
|
- qed/ordering.md
|
117
119
|
- qed/projection.md
|
@@ -146,9 +148,11 @@ test_files:
|
|
146
148
|
- qed/applique/ae.rb
|
147
149
|
- qed/applique/flounder.rb
|
148
150
|
- qed/applique/setup_domain.rb
|
151
|
+
- qed/conditions.md
|
149
152
|
- qed/exceptions.md
|
150
153
|
- qed/flounder.sql
|
151
154
|
- qed/index.md
|
155
|
+
- qed/insdate.md
|
152
156
|
- qed/inserts.md
|
153
157
|
- qed/ordering.md
|
154
158
|
- qed/projection.md
|