flounder 0.8.1 → 0.9.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.
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.8.1
4
+ version: 0.9.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-11 00:00:00.000000000 Z
12
+ date: 2014-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arel
@@ -86,10 +86,11 @@ extensions: []
86
86
  extra_rdoc_files: []
87
87
  files:
88
88
  - Gemfile
89
- - Gemfile.lock
90
89
  - HACKING
90
+ - HISTORY
91
91
  - LICENSE
92
92
  - README
93
+ - flounder-0.3.0.gem
93
94
  - flounder.gemspec
94
95
  - lib/flounder.rb
95
96
  - lib/flounder/connection.rb
@@ -100,27 +101,29 @@ files:
100
101
  - lib/flounder/entity_alias.rb
101
102
  - lib/flounder/exceptions.rb
102
103
  - lib/flounder/field.rb
103
- - lib/flounder/immediate.rb
104
- - lib/flounder/insert.rb
105
104
  - lib/flounder/postgres_utils.rb
106
- - lib/flounder/query.rb
105
+ - lib/flounder/query/base.rb
106
+ - lib/flounder/query/immediate.rb
107
+ - lib/flounder/query/insert.rb
108
+ - lib/flounder/query/returning.rb
109
+ - lib/flounder/query/select.rb
110
+ - lib/flounder/query/update.rb
107
111
  - lib/flounder/symbol_extensions.rb
108
- - lib/flounder/update.rb
109
112
  - qed/applique/ae.rb
110
113
  - qed/applique/flounder.rb
111
114
  - qed/applique/setup_domain.rb
115
+ - qed/atomic_insert_update.md
112
116
  - qed/conditions.md
113
117
  - qed/exceptions.md
114
118
  - qed/flounder.sql
115
119
  - qed/index.md
116
- - qed/insdate.md
117
120
  - qed/inserts.md
118
121
  - qed/ordering.md
119
122
  - qed/projection.md
120
123
  - qed/results.md
121
124
  - qed/selects.md
122
125
  - qed/updates.md
123
- homepage: https://bitbucket.org/technologyastronauts/laboratory_flounder
126
+ homepage: https://bitbucket.org/technologyastronauts/oss_flounder
124
127
  licenses: []
125
128
  metadata: {}
126
129
  post_install_message:
@@ -139,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
142
  version: '0'
140
143
  requirements: []
141
144
  rubyforge_project:
142
- rubygems_version: 2.2.0
145
+ rubygems_version: 2.2.2
143
146
  signing_key:
144
147
  specification_version: 4
145
148
  summary: Flounder is a way to write SQL simply in Ruby. It deals with everything BUT
@@ -148,11 +151,11 @@ test_files:
148
151
  - qed/applique/ae.rb
149
152
  - qed/applique/flounder.rb
150
153
  - qed/applique/setup_domain.rb
154
+ - qed/atomic_insert_update.md
151
155
  - qed/conditions.md
152
156
  - qed/exceptions.md
153
157
  - qed/flounder.sql
154
158
  - qed/index.md
155
- - qed/insdate.md
156
159
  - qed/inserts.md
157
160
  - qed/ordering.md
158
161
  - qed/projection.md
data/Gemfile.lock DELETED
@@ -1,33 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- flounder (0.4.0)
5
- arel (~> 5, > 5.0.1)
6
- connection_pool (~> 2)
7
- hashie (~> 3, >= 3.2)
8
- pg (> 0.17)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- ae (1.8.2)
14
- ansi
15
- ansi (1.4.3)
16
- arel (5.0.1.20140414130214)
17
- brass (1.2.1)
18
- connection_pool (2.0.0)
19
- facets (2.9.3)
20
- hashie (3.2.0)
21
- pg (0.17.1)
22
- qed (2.9.1)
23
- ansi
24
- brass
25
- facets (>= 2.8)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- ae
32
- flounder!
33
- qed
@@ -1,73 +0,0 @@
1
- module Flounder
2
-
3
- # An insert.
4
- #
5
- class Insert
6
- def initialize domain, into_entity
7
- @domain = domain
8
- @into_entity = into_entity
9
- @engine = Engine.new(into_entity.domain.connection_pool)
10
- @manager = Arel::InsertManager.new(@engine)
11
-
12
- manager.into into_entity.table
13
- end
14
-
15
- # Domain that this insert was issued for.
16
- attr_reader :domain
17
- # Entity that this insert acts on.
18
- attr_reader :into_entity
19
-
20
- # Arel SqlManager that accumulates this insert.
21
- attr_reader :manager
22
- # Database engine that links Arel to Postgres.
23
- attr_reader :engine
24
-
25
- # Add one row to the inserts.
26
- #
27
- def insert fields
28
- manager.insert fields.map { |k, v| transform_hash_keys(k, v) }
29
- end
30
-
31
- # Kickers
32
- def to_sql
33
- manager.to_sql.tap { |sql|
34
- domain.log_sql(sql) }
35
- end
36
- alias sql to_sql
37
-
38
- # Returns all rows of the insert result as an array. Individual rows are
39
- # mapped to objects using the row mapper.
40
- #
41
- def returning fields = '*'
42
- inserted = []
43
- engine.exec(sql + " RETURNING #{fields}") do |result|
44
- inserted = Array.new(result.ntuples, nil)
45
- result.ntuples.times do |row_idx|
46
- inserted[row_idx] = engine.connection.
47
- objectify_result_row(into_entity, result, row_idx)
48
- end
49
- end
50
- inserted
51
- end
52
-
53
- private
54
-
55
- # Called on each key/value pair of an insert clause, this returns a
56
- # hash that can be passed to Arel #insert.
57
- #
58
- def transform_hash_keys field, value
59
- if value.kind_of? Field
60
- value = value.arel_field
61
- end
62
-
63
- case field
64
- when Symbol, String
65
- [into_entity[field.to_sym].arel_field, value]
66
- when Flounder::Field
67
- [field.arel_field, value]
68
- else
69
- fail "Could not transform condition part. (#{field.inspect}, #{value.inspect})"
70
- end
71
- end
72
- end # class
73
- end # module Flounder
@@ -1,114 +0,0 @@
1
- module Flounder
2
-
3
- # An update obtained by calling any of the chain methods on an entity.
4
- #
5
- class Update
6
- def initialize domain, entity
7
- @domain = domain
8
- @entity = entity
9
- @engine = Engine.new(entity.domain.connection_pool)
10
- @manager = Arel::UpdateManager.new(@engine)
11
-
12
- manager.table entity.table
13
- end
14
-
15
- # Domain that this update was issued from.
16
- attr_reader :domain
17
- # Entity that this update acts on.
18
- attr_reader :entity
19
-
20
- # Arel SqlManager that accumulates this query.
21
- attr_reader :manager
22
- # Database engine that links Arel to Postgres.
23
- attr_reader :engine
24
-
25
- # Add one row to the updates.
26
- #
27
- def update fields
28
- manager.set fields.map { |k, v| transform_hash_keys(k, v) }
29
- end
30
-
31
- def where conditions={}
32
- conditions.each do |k, v|
33
- manager.where(transform_hash_condition(k, v))
34
- end
35
- self
36
- end
37
-
38
- # Kickers
39
- def to_sql
40
- manager.to_sql.tap { |sql|
41
- domain.log_sql(sql) }
42
- end
43
- alias sql to_sql
44
-
45
- # Returns all rows of the update result as an array. Individual rows are
46
- # mapped to objects using the row mapper.
47
- #
48
- def returning fields = '*'
49
- updated = nil
50
- engine.exec(sql + " RETURNING #{fields}") do |result|
51
- updated = Array.new(result.ntuples, nil)
52
- result.ntuples.times do |row_idx|
53
- updated[row_idx] = engine.connection.
54
- objectify_result_row(entity, result, row_idx)
55
- end
56
- end
57
- updated
58
- end
59
-
60
- private
61
-
62
- # Called on each key/value pair of an update clause, this returns a
63
- # hash that can be passed to Arel #update.
64
- #
65
- def transform_hash_keys field, value
66
- if value.kind_of? Field
67
- value = value.arel_field
68
- end
69
-
70
- case field
71
- when Symbol, String
72
- [entity[field.to_sym].arel_field, value]
73
- when Flounder::Field
74
- [field.arel_field, value]
75
- else
76
- fail "Could not transform condition part. (#{field.inspect}, #{value.inspect})"
77
- end
78
- end
79
-
80
- # Called on each key/value pair of a condition clause, this returns a
81
- # condition that can be passed to Arel #where.
82
- #
83
- def transform_hash_condition field, value
84
- if value.kind_of? Field
85
- value = value.arel_field
86
- end
87
-
88
- case field
89
- when Symbol
90
- condition_part(entity[field].arel_field, value)
91
- when Flounder::Field
92
- condition_part(field.arel_field, value)
93
- when Flounder::SymbolExtensions::Modifier
94
- condition_part(
95
- field.to_arel_field(entity),
96
- value,
97
- field.kind)
98
- else
99
- fail "Could not transform condition part. (#{field.inspect}, #{value.inspect})"
100
- end
101
- end
102
- def condition_part arel_field, value, kind=:eq
103
- case value
104
- when Symbol
105
- value_field = entity[value].arel_field
106
- arel_field.send(kind, value_field)
107
- when Range
108
- arel_field.in(value)
109
- else
110
- arel_field.send(kind, value)
111
- end
112
- end
113
- end # class
114
- end # module Flounder
data/qed/insdate.md DELETED
@@ -1,25 +0,0 @@
1
- Flounder offers Insdate.
2
-
3
- ~~~ruby
4
- post = posts.first
5
-
6
- # Insert if not found.
7
- #
8
- post = posts.insdate([:title], :title => 'Insdate Insert', :text => '', :user_id => users.first.id) do |p|
9
- p.first.title.assert == 'Insdate Insert'
10
- end.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 |p|
17
- assert false # Not called on update.
18
- end.first
19
- post.title.assert == 'Insdate Insert'
20
- post.text.assert == 'Insdate Update Text'
21
-
22
- # Reset this particular QED.
23
- #
24
- posts.where(:id => post.id).delete.first
25
- ~~~