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.
- checksums.yaml +4 -4
- data/lib/pgdog.rb +22 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19fd33ec4a1f17d24527f0c7b8bdb85b32a7bbacbd8371ca328b7b36b9fd7ce5
|
4
|
+
data.tar.gz: 6a516645601309bc73cea474328f4f3b8eebd1d0b23e6938199da842eb59d0aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|