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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 484ff8cd8a8111a3d280cad0dc9d4fff81d53df5
4
- data.tar.gz: 87115495df74ecf98166c0f801c787ee1457554f
3
+ metadata.gz: a661579acf9b8efd91248bf500928fa995ae4cf1
4
+ data.tar.gz: 70c604ee69bf1cf6a45b19724e85e865e35a335f
5
5
  SHA512:
6
- metadata.gz: 0f145748074a522cdef6ae67e6148701cd6c256e885f30c4f301e101c4cda1c1a26f47bc013397caf92c45c433474d2982f1afd5c4ecc4bb881d49655412f0da
7
- data.tar.gz: 24104884f69252858840d7ff839db49f1a25f8e3720daf49f38ae467f881f7851aa90882d350171a21da164431ebd943af88a554e9ca26f0313692b32bb976da
6
+ metadata.gz: 0315371d93b05f38a6902ced435eda2811eb2931db4647d4e1fa97610194a4d25b4cf1b4101b280ca4088570d6515743d7c8f48a4d46397c1a0ad4b42b6ed4c6
7
+ data.tar.gz: 16cbfd112bc6362748dedacb4472fdddf727f5f1038f90c74e90e6efd32c152a784b40360f8a1240deb7037118d8912edda7a7ef6115c89880cc6f569678d77f
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "flounder"
5
- s.version = '0.5.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"
@@ -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 || entity
87
- name = processed_name || 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
 
@@ -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
@@ -37,7 +37,7 @@ module Flounder
37
37
  # prefix during this query.
38
38
  attr_reader :projection_prefixes
39
39
 
40
- def where conditions={}
40
+ def where conditions
41
41
  conditions.each do |k, v|
42
42
  manager.where(transform_hash(k, v))
43
43
  end
@@ -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
+ # ~~~
@@ -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
+ ~~~
@@ -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
+ ~~~
@@ -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 == 6
30
+ users.size.assert == 7
31
31
  users.assert.kind_of? Array
32
32
 
33
33
  domain[:users].map(&:id).assert == users.map(&:id)
@@ -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']*6
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.5.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-05 00:00:00.000000000 Z
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