active_record-sequence 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/active_record/sequence.rb +23 -9
- data/lib/active_record/sequence/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f0d7c7abbc69c87cf51109c788c28edb31b08d
|
4
|
+
data.tar.gz: 4c2025194325a6b489811fcfb6c4e012c271b4cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d54e541caf29319fa0d3424474f2905127935bb2888e85f0bf06853a9991e080f342b6a13a3436342bf5bf018bd308f931836d192e5e3e340913eea783d33bb
|
7
|
+
data.tar.gz: c715186042c3d1e78f5d0adde3e2573fe5086c5f07b092eba82034ca81b59d12b41b446c1af0c84cd2c2c69d12a8d6fe4aa84a0632f50ab84758349c9767f1b6
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/bolshakov/active_record-sequence.svg?branch=master)](https://travis-ci.org/bolshakov/active_record-sequence)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/active_record-sequence.svg)](https://badge.fury.io/rb/active_record-sequence)
|
2
3
|
|
3
4
|
# ActiveRecord::Sequence
|
4
5
|
|
@@ -36,7 +36,9 @@ module ActiveRecord
|
|
36
36
|
def create(name, options = {})
|
37
37
|
create_sql = SequenceSQLBuilder.new(name, options).to_sql
|
38
38
|
handle_postgres_errors(CREATE_ERRORS) do
|
39
|
-
connection
|
39
|
+
with_connection do |connection|
|
40
|
+
connection.execute(create_sql)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
new(name)
|
42
44
|
end
|
@@ -50,12 +52,17 @@ module ActiveRecord
|
|
50
52
|
def drop(name)
|
51
53
|
drop_sql = format('DROP SEQUENCE %s', name)
|
52
54
|
handle_postgres_errors(DROP_ERRORS) do
|
53
|
-
connection
|
55
|
+
with_connection do |connection|
|
56
|
+
connection.execute(drop_sql)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
|
-
|
58
|
-
|
61
|
+
# @api private
|
62
|
+
def with_connection
|
63
|
+
ActiveRecord::Base.connection_pool.with_connection do |connection|
|
64
|
+
yield(connection)
|
65
|
+
end
|
59
66
|
end
|
60
67
|
|
61
68
|
# @param mappings [{}] from PG errors to library errors
|
@@ -73,7 +80,6 @@ module ActiveRecord
|
|
73
80
|
# @param name [String]
|
74
81
|
def initialize(name)
|
75
82
|
@name = name
|
76
|
-
@connection = self.class.connection
|
77
83
|
end
|
78
84
|
|
79
85
|
NEXT_ERRORS = {
|
@@ -104,14 +110,22 @@ module ActiveRecord
|
|
104
110
|
|
105
111
|
private
|
106
112
|
|
107
|
-
attr_reader :connection
|
108
113
|
delegate :handle_postgres_errors, to: :class
|
114
|
+
delegate :with_connection, to: :class
|
109
115
|
|
110
116
|
def execute(sql, *args)
|
111
|
-
|
112
|
-
|
117
|
+
with_connection do |connection|
|
118
|
+
connection.select_value(prepare_query(sql, *args)).to_i
|
119
|
+
end
|
120
|
+
end
|
113
121
|
|
114
|
-
|
122
|
+
def prepare_query(sql, *args)
|
123
|
+
quoted_args = args.map do |arg|
|
124
|
+
with_connection do |connection|
|
125
|
+
connection.quote(arg)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
format(sql, *quoted_args)
|
115
129
|
end
|
116
130
|
end
|
117
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-sequence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tema Bolshakov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|