carrierwave-postgresql-table 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/circle.yml +2 -1
- data/gemfiles/carrierwave_0.11_rails_4.2.gemfile.lock +2 -2
- data/gemfiles/carrierwave_1.0.0_rails_4.2.gemfile.lock +2 -2
- data/gemfiles/carrierwave_1.0.0_rails_5.0.gemfile.lock +2 -2
- data/lib/carrierwave/postgresql_table/version.rb +1 -1
- data/lib/carrierwave/storage/postgresql_table.rb +37 -35
- 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: 764a5c85b7937568cc214e4ba49dd3bbac7ccdef
|
4
|
+
data.tar.gz: 1800fb54ffcd1e5518db1afe702fa6353696c2b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a73a0cb83935b7359fde2b33717050aecbefe7b39417d57806c555500e9c131f02067da4560bb079a47febfc22a7327d62c6f825c7f96cd6f5c1211ca894324
|
7
|
+
data.tar.gz: 50caf0ae944e1e96260c066f0769bcf18965a36e6c72d146b94ff9d54001dcdf6e428a2786b0ae313302c7a6c80540271607412a96b78a91a354c4e1cf7dc088
|
data/circle.yml
CHANGED
@@ -5,7 +5,8 @@ dependencies:
|
|
5
5
|
- bundle exec appraisal install
|
6
6
|
database:
|
7
7
|
override:
|
8
|
-
- psql -c "CREATE
|
8
|
+
- psql -c "CREATE USER carrierwave_postgresql_table_test WITH PASSWORD '';" -U postgres
|
9
|
+
- psql -c "CREATE DATABASE carrierwave_postgresql_table_test OWNER carrierwave_postgresql_table_test;" -U postgres
|
9
10
|
test:
|
10
11
|
override:
|
11
12
|
- bundle exec appraisal rake
|
@@ -71,7 +71,7 @@ module CarrierWave
|
|
71
71
|
data = raw_connection.lo_read(lo, length)
|
72
72
|
@read_pos = raw_connection.lo_tell(lo)
|
73
73
|
else
|
74
|
-
data = raw_connection.lo_read(lo, size)
|
74
|
+
data = raw_connection.lo_read(lo, self.size)
|
75
75
|
end
|
76
76
|
ensure
|
77
77
|
raw_connection.lo_close(lo) if(lo)
|
@@ -88,6 +88,7 @@ module CarrierWave
|
|
88
88
|
def to_tempfile
|
89
89
|
Tempfile.new(:binmode => true).tap do |tempfile|
|
90
90
|
IO.copy_stream(self, tempfile)
|
91
|
+
self.rewind
|
91
92
|
tempfile.rewind
|
92
93
|
tempfile.fsync
|
93
94
|
end
|
@@ -102,7 +103,15 @@ module CarrierWave
|
|
102
103
|
end
|
103
104
|
|
104
105
|
def size
|
105
|
-
@record.size
|
106
|
+
@size = @record.size || fetch_size
|
107
|
+
end
|
108
|
+
|
109
|
+
def eof?
|
110
|
+
@read_pos == self.size
|
111
|
+
end
|
112
|
+
|
113
|
+
def rewind
|
114
|
+
@read_pos = 0
|
106
115
|
end
|
107
116
|
|
108
117
|
def content_type
|
@@ -123,23 +132,23 @@ module CarrierWave
|
|
123
132
|
raw_connection = connection.raw_connection
|
124
133
|
oid = nil
|
125
134
|
if(new_file.kind_of?(CarrierWave::Storage::PostgresqlTable::File))
|
126
|
-
|
135
|
+
file = new_file
|
127
136
|
else
|
128
137
|
file = new_file.to_file
|
138
|
+
end
|
129
139
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
file.close
|
140
|
-
ensure
|
141
|
-
raw_connection.lo_close(handle)
|
140
|
+
begin
|
141
|
+
oid = @record.pg_largeobject_oid || raw_connection.lo_creat
|
142
|
+
handle = raw_connection.lo_open(oid, PG::INV_WRITE)
|
143
|
+
raw_connection.lo_truncate(handle, 0)
|
144
|
+
buffer = ""
|
145
|
+
until file.eof?
|
146
|
+
file.read(READ_CHUNK_SIZE, buffer)
|
147
|
+
raw_connection.lo_write(handle, buffer)
|
142
148
|
end
|
149
|
+
file.rewind
|
150
|
+
ensure
|
151
|
+
raw_connection.lo_close(handle)
|
143
152
|
end
|
144
153
|
|
145
154
|
begin
|
@@ -164,26 +173,6 @@ module CarrierWave
|
|
164
173
|
end
|
165
174
|
end
|
166
175
|
|
167
|
-
def copy_to(new_path)
|
168
|
-
CarrierWaveFile.transaction do
|
169
|
-
connection = CarrierWaveFile.connection
|
170
|
-
|
171
|
-
result = connection.execute("INSERT INTO pg_largeobject_metadata(lomowner, lomacl)
|
172
|
-
SELECT lomowner, lomacl
|
173
|
-
FROM pg_largeobject_metadata
|
174
|
-
WHERE oid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}
|
175
|
-
RETURNING oid AS new_oid")
|
176
|
-
new_oid = Integer(result.values[0][0])
|
177
|
-
|
178
|
-
connection.execute("INSERT INTO pg_largeobject(loid, pageno, data)
|
179
|
-
SELECT #{new_oid}, pageno, data
|
180
|
-
FROM pg_largeobject
|
181
|
-
WHERE loid = #{CarrierWaveFile.sanitize(@record.pg_largeobject_oid)}")
|
182
|
-
|
183
|
-
new_oid
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
176
|
def move_to(new_path)
|
188
177
|
CarrierWaveFile.transaction do
|
189
178
|
# Remove any existing files at the current path.
|
@@ -197,6 +186,19 @@ module CarrierWave
|
|
197
186
|
def delete
|
198
187
|
CarrierWaveFile.delete_all_files("id = #{CarrierWaveFile.sanitize(@record.id)}")
|
199
188
|
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def fetch_size
|
193
|
+
size = nil
|
194
|
+
CarrierWaveFile.transaction do
|
195
|
+
raw_connection = CarrierWaveFile.connection.raw_connection
|
196
|
+
lo = raw_connection.lo_open(@record.pg_largeobject_oid)
|
197
|
+
size = raw_connection.lo_lseek(lo, 0, PG::SEEK_END)
|
198
|
+
end
|
199
|
+
|
200
|
+
size
|
201
|
+
end
|
200
202
|
end
|
201
203
|
end
|
202
204
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-postgresql-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Muerdter
|
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
|