flounder 0.18.1 → 0.18.2

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: 370d0a1cfd677a805e751dc4532e59b910b06eea
4
- data.tar.gz: 49c396164c6dcab26cd99fc5422e9da446875312
3
+ metadata.gz: f60fabc94bf34a924e2415c6afeef19c98d565c9
4
+ data.tar.gz: 831d3c9e63fcecc02fc7b82f8814159358341435
5
5
  SHA512:
6
- metadata.gz: 10b2cc277db56cd71d20e19c1ab1cbd6d69408a9710e1ba48c48f33be90dba2be6bcbd55045babf05a29a6916718f82f86aca471cdfd285281897bbfc8aa9c16
7
- data.tar.gz: e691b31f51aa335a3f868650b166d6758e72706e5baea29674002897090b26522da0aac40fa5678d5f6320108dfb5a1baaf4b300faa578a0ef9d63b5e98b53f5
6
+ metadata.gz: eb48e10532ba0c3febdc3aa57c4d1671ab24b8990c6e16539f11a91971c2ac1fc5e3440ea5e51710fd1a58155bf9903668c5480b87f7cffa1d43bcd04c971a55
7
+ data.tar.gz: feffebf6cf853a97f1d240c4cebcf482bd9f77084efe6dbdcc38079e3a12dd2cf9c2c13736e9001d22abf04c31f9d3c8bec551c67b75cfed68df6fe82cd0e417
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flounder (0.18.0)
4
+ flounder (0.18.1)
5
5
  aggregate (~> 0.2, >= 0.2.2)
6
6
  arel (~> 5, > 5.0.1)
7
7
  connection_pool (~> 2)
@@ -18,9 +18,9 @@ GEM
18
18
  ansi (1.4.3)
19
19
  arel (5.0.1.20140414130214)
20
20
  brass (1.2.1)
21
- connection_pool (2.0.0)
21
+ connection_pool (2.1.0)
22
22
  facets (2.9.3)
23
- hashie (3.3.1)
23
+ hashie (3.3.2)
24
24
  pg (0.17.1)
25
25
  pg-hstore (1.2.0)
26
26
  qed (2.9.1)
data/HISTORY CHANGED
@@ -1,5 +1,6 @@
1
1
  # 0.18
2
2
  + Allows usage of relation names in where clauses.
3
+ + Remaps entity oids automatically if a mismatch exists.
3
4
 
4
5
  # 0.17
5
6
  + A call to order_by fully replaces previously set ordering.
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.18.1'
5
+ s.version = '0.18.2'
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/oss_flounder"
@@ -22,8 +22,13 @@ module Flounder
22
22
  @plural = {}
23
23
  @singular = {}
24
24
 
25
+ # Maps table names to entities
26
+ @entity_by_table_name = {}
27
+
25
28
  # maps OIDs of entities to entities
26
- @oids_entity_map = {}
29
+ @oids_entity_map = Hash.new { |hash, oid|
30
+ hash[oid] = entity_from_oid(oid)
31
+ }
27
32
 
28
33
  @logger = Logger.new(NilDevice.new)
29
34
 
@@ -109,11 +114,12 @@ module Flounder
109
114
  entity = Entity.new(self, plural, singular, table_name).
110
115
  tap { |e| yield e if block_given? }
111
116
 
117
+ raise ArgumentError, "Table #{table_name} was already associated with an entity." \
118
+ if @entity_by_table_name.has_key?(table_name)
119
+
112
120
  @plural[plural] = entity
113
121
  @singular[singular] = entity
114
-
115
- # Also maps OID to entities for field resolution
116
- @oids_entity_map[table_oid(table_name)] = entity
122
+ @entity_by_table_name[table_name] = entity
117
123
 
118
124
  entity
119
125
  end
@@ -121,6 +127,7 @@ module Flounder
121
127
  # Returns an entity by table oid.
122
128
  #
123
129
  def by_oid oid
130
+ return nil if oid==0 # computed fields
124
131
  @oids_entity_map[oid]
125
132
  end
126
133
 
@@ -157,11 +164,12 @@ module Flounder
157
164
  end
158
165
  end
159
166
 
160
- def table_oid table_name
167
+ def entity_from_oid oid
161
168
  connection_pool.with_connection do |conn|
162
- # TBD
163
- conn.exec(%Q(select oid from pg_class where relname = #{conn.quote(table_name)})).
164
- getvalue(0,0).to_i
169
+ table_name = conn.exec(%Q(SELECT #{oid}::regclass)).
170
+ getvalue(0,0)
171
+
172
+ @entity_by_table_name[table_name]
165
173
  end
166
174
  end
167
175
  end
data/qed/projection.md CHANGED
@@ -19,7 +19,7 @@ When projecting, all result data will be toplevel and only the projected data is
19
19
  project(users[:name]).first
20
20
 
21
21
  result.id.assert == nil # Not loaded.
22
- result.name.assert == 'John Snow'
22
+ result.user.name.assert == 'John Snow'
23
23
  ~~~
24
24
 
25
25
  Otherwise a projected query can be treated like an ordinary query, including appending stuff by joining it in.
@@ -33,3 +33,24 @@ Otherwise a projected query can be treated like an ordinary query, including app
33
33
  post.user.name.assert == 'John Snow'
34
34
  post.approver.name.assert == 'John Doe'
35
35
  ~~~
36
+
37
+ The same (by name) field can be used from multiple tables without issues.
38
+
39
+ ~~~ruby
40
+ result = posts.
41
+ join(users).on(:user_id => :id).
42
+ project(users[:id], users[:name], posts[:id], posts[:title]).
43
+ first
44
+
45
+ result.title.assert == "First Light"
46
+ result.post.title.assert == "First Light"
47
+ result.user.name.assert == 'John Snow'
48
+ ~~~
49
+
50
+ Fields that are created during the select are toplevel as well.
51
+
52
+ ~~~ruby
53
+ result = posts.project('42 as answer').first
54
+ result.answer.assert = 42
55
+ ~~~
56
+
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.18.1
4
+ version: 0.18.2
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-11-27 00:00:00.000000000 Z
12
+ date: 2014-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arel