flounder 0.11.2 → 0.11.3

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: e079992becc4bd6e98eca9e16ae711fe4deb8a95
4
- data.tar.gz: b1a2bea366240854948b9267ba3f96b5eeaefbc1
3
+ metadata.gz: f4ac07a24ace10c1749674bf6267e9a72340dbb6
4
+ data.tar.gz: 727e4e6fd344cf1af92787e82ffd18c505fe5956
5
5
  SHA512:
6
- metadata.gz: 1b5068f9033c63dc84be648f1d484d0a21b90750d3e271a08ed6874df0ec28f2eef4242b5dba6bb5ffe65aaea1926df9c6b6f6257859b28df861db8efc2413cf
7
- data.tar.gz: 18fc4a0a6cb0ab7c164735ccf344039d7169a66fc026719918ca14d4562b14714256586673d4470877bab78f4f38c74b0827dd4ac55779da63744a591dc43427
6
+ metadata.gz: e9397d1aaef91195b6506305ba65738cebb2936cc3e1c507b5650ac3b8da2abc1ad5f221d8c36240a631621f1f1ca4d3c8b7a6261d1fc961b3f2d4200a6ce355
7
+ data.tar.gz: f48c8f2963b7ac31f16dd9e8a52d282221d39670ed12f72ac16c22e55a2d38fec7aa57523c3eaea51deb827a1ac6335fc7d24b7666033874414c2e92064f9e3f
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.11.2'
5
+ s.version = '0.11.3'
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"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_runtime_dependency 'pg', '~> 0.17'
19
19
  s.add_runtime_dependency 'hashie', '~> 3', '>= 3.2'
20
20
  s.add_runtime_dependency 'connection_pool', '~> 2'
21
- s.add_runtime_dependency 'pg-hstore', '~> 1.2.0'
21
+ s.add_runtime_dependency 'pg-hstore', '~> 1.2', '>= 1.2.0'
22
22
 
23
23
  s.files = Dir['**/*']
24
24
  s.test_files = Dir['qed/**/*']
@@ -14,7 +14,6 @@ module Flounder
14
14
  OID_TIMESTAMP = 1114
15
15
  OID_DATE = 1082
16
16
  OID_TIME = 1083
17
- OID_HSTORE = 133538
18
17
 
19
18
  def typecast type_oid, value
20
19
  return nil unless value
@@ -35,13 +34,20 @@ module Flounder
35
34
  value == 't'
36
35
  when OID_TEXT
37
36
  value.to_s
38
- when OID_HSTORE
37
+ when oid_hstore
39
38
  PgHstore.load(value)
40
39
  else
41
40
  value
42
41
  end
43
42
  end
44
43
 
44
+ def oid_hstore
45
+ @oid_hstore ||= begin
46
+ result = exec("SELECT oid FROM pg_type WHERE typname='hstore'")
47
+ result.first.values.first.to_i
48
+ end
49
+ end
50
+
45
51
  def type_oid_to_sym oid
46
52
  case oid
47
53
  when OID_TIMESTAMP
@@ -58,7 +64,7 @@ module Flounder
58
64
  :string
59
65
  when OID_BOOLEAN
60
66
  :boolean
61
- when OID_HSTORE
67
+ when oid_hstore
62
68
  :hash
63
69
  else
64
70
  nil
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'pg_hstore'
2
3
  require 'benchmark'
3
4
 
4
5
  module Flounder::Query
@@ -210,6 +211,10 @@ module Flounder::Query
210
211
  # hash that can be passed to Arel #update.
211
212
  #
212
213
  def transform_tuple_for_set field, value
214
+ if value.kind_of? Hash
215
+ value = PgHstore.dump(value, true)
216
+ end
217
+
213
218
  placeholder = add_binding(value)
214
219
 
215
220
  case field
data/qed/flounder.sql CHANGED
@@ -1,10 +1,13 @@
1
1
  -- Database fixture for these tests. Please import into a database that
2
2
  -- should also be called 'flounder'.
3
3
 
4
+ CREATE EXTENSION IF NOT EXISTS hstore;
5
+
4
6
  DROP TABLE IF EXISTS "users" CASCADE;
5
7
  CREATE TABLE "users" (
6
8
  "id" serial PRIMARY KEY,
7
- "name" varchar(40) NOT NULL
9
+ "name" varchar(40) NOT NULL,
10
+ "attributes" hstore NULL
8
11
  );
9
12
 
10
13
  BEGIN;
data/qed/inserts.md CHANGED
@@ -40,10 +40,15 @@ 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
+ ## Special Types
44
+
45
+ ### HSTORE
46
+
47
+ Flounder supports fields in hstore format through the `pg-hstore` gem.
44
48
 
45
49
  ~~~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
50
+ row = users.insert(name: 'HStore User', attributes: {foo: 'bar'}).kick.first
51
+
52
+ row = users.where(id: row.id).first
53
+ row.attributes.assert == {'foo' => 'bar'}
49
54
  ~~~
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 == 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)
data/qed/updates.md CHANGED
@@ -63,5 +63,5 @@ Updating multiple rows is possible.
63
63
  ~~~ruby
64
64
  updated = users.update(:name => 'Update Multiple Rows').where(:name.not_eq => nil).kick
65
65
 
66
- updated.map(&:name).assert == ['Update Multiple Rows']*6
66
+ updated.map(&:name).assert == ['Update Multiple Rows']*7
67
67
  ~~~
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.11.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaspar Schiess
@@ -84,6 +84,9 @@ dependencies:
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.2'
89
+ - - ">="
87
90
  - !ruby/object:Gem::Version
88
91
  version: 1.2.0
89
92
  type: :runtime
@@ -91,6 +94,9 @@ dependencies:
91
94
  version_requirements: !ruby/object:Gem::Requirement
92
95
  requirements:
93
96
  - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.2'
99
+ - - ">="
94
100
  - !ruby/object:Gem::Version
95
101
  version: 1.2.0
96
102
  description: " Flounder is the missing piece between the database and your Ruby