pgdog 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pgdog.rb +22 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7c6d2bc154cf558bc61be658c14fd0cb30ab53d44bd0beed5ccd0b0b69c0f72
4
- data.tar.gz: b861aec2cf7e56316da42e588ba434365ebe159779651d913d3b7a9038325ed6
3
+ metadata.gz: 19fd33ec4a1f17d24527f0c7b8bdb85b32a7bbacbd8371ca328b7b36b9fd7ce5
4
+ data.tar.gz: 6a516645601309bc73cea474328f4f3b8eebd1d0b23e6938199da842eb59d0aa
5
5
  SHA512:
6
- metadata.gz: 85397cbe9c812c068af754822ae838e8826ebee3a0326952a2e6c8cef872b4a4ae789bfd48e4c897c6ae332198a9abab9ec54e8fd3810558f1acb18cd6bbad2b
7
- data.tar.gz: 0522ec89011c0c3259c85370a7db82231c92ff2a4f108f19e8a21146f9cc494588c319f72770cbaf873c1140702ea6df889997f4bdce093780e3f1dda78743ea
6
+ metadata.gz: 2fac30df58c4e40247aa60145e0a3aaa5e61f1e0f3529a5573c593c6c58cbdbac0b949b562b1a5ca9dc07e698953ba95e5e86e61016ff52f4ede4a1ec76c22ed
7
+ data.tar.gz: 9ae56e2701326d4c2341a55fb9df3f1c865d41eb702127c9a379dd08bef31deee6ddc7d5539f654efc270b77ab5dd9c804dc2ac7dcc2bc5ae413eb8d3b9b8026
data/lib/pgdog.rb CHANGED
@@ -21,7 +21,7 @@ class PgDog
21
21
  # manually using SET.
22
22
  def self.with_sharding_key(key)
23
23
  # Basic SQL injection protection.
24
- key.to_s.sub "'", "''"
24
+ key = key.to_s.sub "'", "''"
25
25
 
26
26
  PgDog.check_transaction
27
27
  ActiveRecord::Base.transaction do
@@ -30,6 +30,17 @@ class PgDog
30
30
  end
31
31
  end
32
32
 
33
+ # Get the number of configured shards
34
+ #
35
+ # Can only work outside of a transaction, because
36
+ # a started transaction is most likely already routed to a shard
37
+ # and the PgDog query parser won't be used.
38
+ def self.shards
39
+ PgDog.check_transaction
40
+ shards = self.connection.execute "SHOW \"pgdog.shards\""
41
+ return shards[0]["shards"].to_i
42
+ end
43
+
33
44
  # Get currently set shard, if any.
34
45
  def self.shard
35
46
  shard = self.connection.execute "SELECT current_setting('pgdog.shard', true)"
@@ -59,3 +70,13 @@ end
59
70
  # Error raised if a transaction is already started.
60
71
  class PgDogError < StandardError
61
72
  end
73
+
74
+ # class ActiveRecord::Schema
75
+ # def self.install_sharded_primary_key(table)
76
+ # shards = PgDog.shards
77
+ # table = table.to_s.sub "'", "''"
78
+ # shards.times do |shard|
79
+ # PgDog.connection.execute "/* pgdog_shard: #{shard} */ SELECT pgdog.install_next_id('public', '#{table}', 'id', #{shards}, #{shard})"
80
+ # end
81
+ # end
82
+ # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgdog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lev Kokotov