objectstore 2.0.1 → 2.0.2
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/atech/object_store/file.rb +24 -7
- data/lib/atech/object_store/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a7d9b4af24d561be98bb2fd2121d5b309934790
|
4
|
+
data.tar.gz: 20b360b5e44dc1af76cf038f57c0f5a59d3da9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c2b445d15f6a9daab7e409c2bf55e0c035c9a36a7b85829a44e882c7a3fba40498c78e7b3b3cf046975de7d5ff37c280c607afbf22cee65cc97403cf0070f6
|
7
|
+
data.tar.gz: 9696ac2ed74a1439715b4aac51583aa3393cd8c8b037823d0513141c1cfd188b4b5a435895cc6578ad84bb416dfac4dbab2d1d4506bf6592c82cfc44c0b96418
|
@@ -13,6 +13,9 @@ module Atech
|
|
13
13
|
## Raised if the data is larger than the maximum file size
|
14
14
|
class FileDataTooBig < Error; end
|
15
15
|
|
16
|
+
# Raised when a row could not be inserted into the database
|
17
|
+
class InsertError < Error; end
|
18
|
+
|
16
19
|
# Run a single query on a backend connection. This should only be used when running a single query. If you need
|
17
20
|
# to do multiple things on the same connection (e.g. INSERT and then get LAST_INSERT_ID) you should checkot your
|
18
21
|
# own connection using ObejctStore::Connection.client
|
@@ -73,13 +76,7 @@ module Atech
|
|
73
76
|
options[:created_at] = options[:created_at].utc
|
74
77
|
options[:updated_at] = options[:updated_at].utc
|
75
78
|
|
76
|
-
|
77
|
-
last_insert_id = ObjectStore::Connection.client do |client|
|
78
|
-
columns = options.keys.join('`,`')
|
79
|
-
data = options.values.map { |v| escape_and_quote(v) }.join(',')
|
80
|
-
client.query("INSERT INTO files (`#{columns}`) VALUES (#{data})")
|
81
|
-
client.last_id
|
82
|
-
end
|
79
|
+
last_insert_id = insert_into_database(options)
|
83
80
|
|
84
81
|
## Return a new File object
|
85
82
|
self.new(options.merge(:id => last_insert_id))
|
@@ -182,6 +179,26 @@ module Atech
|
|
182
179
|
end
|
183
180
|
end
|
184
181
|
|
182
|
+
def self.insert_into_database(options)
|
183
|
+
retries = 0
|
184
|
+
|
185
|
+
# Create an insert query
|
186
|
+
last_insert_id = ObjectStore::Connection.client do |client|
|
187
|
+
columns = options.keys.join('`,`')
|
188
|
+
data = options.values.map { |v| escape_and_quote(v) }.join(',')
|
189
|
+
client.query("INSERT INTO files (`#{columns}`) VALUES (#{data})")
|
190
|
+
client.last_id
|
191
|
+
end
|
192
|
+
|
193
|
+
raise InsertError if last_insert_id == 0
|
194
|
+
|
195
|
+
last_insert_id
|
196
|
+
rescue InsertError => e
|
197
|
+
raise e if retries >= 2
|
198
|
+
retries += 1
|
199
|
+
retry
|
200
|
+
end
|
201
|
+
|
185
202
|
def self.escape_and_quote(string)
|
186
203
|
string = string.strftime('%Y-%m-%d %H:%M:%S') if string.is_a?(Time)
|
187
204
|
ObjectStore::Connection.client do |client|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: objectstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.6.14.3
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: A SQL based object store library
|