mini_sql 0.2.2 → 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,10 @@ module MiniSql
26
26
  r
27
27
  end
28
28
 
29
+ def query_array(sql, *params)
30
+ run(sql, *params)
31
+ end
32
+
29
33
  def exec(sql, *params)
30
34
 
31
35
  start = raw_connection.total_changes
@@ -46,16 +50,20 @@ module MiniSql
46
50
  end
47
51
  end
48
52
 
53
+ def query_decorator(decorator, sql, *params)
54
+ run(sql, *params) do |set|
55
+ deserializer_cache.materialize(set, decorator)
56
+ end
57
+ end
58
+
49
59
  def escape_string(str)
50
- str.gsub("'","''")
60
+ str.gsub("'", "''")
51
61
  end
52
62
 
53
63
  private
54
64
 
55
65
  def run(sql, *params)
56
- if params && params.length > 0
57
- sql = param_encoder.encode(sql, *params)
58
- end
66
+ sql = param_encoder.encode(sql, *params)
59
67
  if block_given?
60
68
  stmt = SQLite3::Statement.new(raw_connection, sql)
61
69
  yield stmt.execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MiniSql
2
4
  module Sqlite
3
5
  class DeserializerCache
@@ -9,7 +11,7 @@ module MiniSql
9
11
  @max_size = max_size || DEFAULT_MAX_SIZE
10
12
  end
11
13
 
12
- def materialize(result)
14
+ def materialize(result, decorator_module = nil)
13
15
 
14
16
  key = result.columns
15
17
 
@@ -22,6 +24,10 @@ module MiniSql
22
24
  @cache.shift if @cache.length > @max_size
23
25
  end
24
26
 
27
+ if decorator_module
28
+ materializer = materializer.decorated(decorator_module)
29
+ end
30
+
25
31
  r = []
26
32
  # quicker loop
27
33
  while !result.eof?
@@ -39,23 +45,15 @@ module MiniSql
39
45
  fields = result.columns
40
46
 
41
47
  Class.new do
42
- attr_accessor(*fields)
48
+ extend MiniSql::Decoratable
49
+ include MiniSql::Result
43
50
 
44
- # AM serializer support
45
- alias :read_attribute_for_serialization :send
46
-
47
- def to_h
48
- r = {}
49
- instance_variables.each do |f|
50
- r[f.to_s.sub('@','').to_sym] = instance_variable_get(f)
51
- end
52
- r
53
- end
51
+ attr_accessor(*fields)
54
52
 
55
53
  instance_eval <<~RUBY
56
54
  def materialize(data)
57
55
  r = self.new
58
- #{col=-1; fields.map{|f| "r.#{f} = data[#{col+=1}]"}.join("; ")}
56
+ #{col = -1; fields.map { |f| "r.#{f} = data[#{col += 1}]" }.join("; ")}
59
57
  r
60
58
  end
61
59
  RUBY
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module MiniSql
2
- VERSION = "0.2.2"
3
+ VERSION = "1.0"
3
4
  end
@@ -12,29 +12,41 @@ Gem::Specification.new do |spec|
12
12
 
13
13
  spec.summary = %q{A fast, safe, simple direct SQL executor}
14
14
  spec.description = %q{A fast, safe, simple direct SQL executor for PG}
15
- spec.homepage = "https://discourse.org"
15
+ spec.homepage = "https://github.com/discourse/mini_sql"
16
16
  spec.license = "MIT"
17
17
 
18
+ spec.metadata = {
19
+ "bug_tracker_uri" => "https://github.com/discourse/mini_sql/issues",
20
+ "source_code_uri" => "https://github.com/discourse/mini_sql",
21
+ "changelog_uri" => "https://github.com/discourse/mini_sql/blob/master/CHANGELOG"
22
+ }
23
+
18
24
  spec.platform = 'java' if RUBY_ENGINE == 'jruby'
19
25
 
20
26
  # Specify which files should be added to the gem when it is released.
21
27
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ # rubocop:disable Discourse/NoChdir
29
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
30
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
31
  end
32
+ # rubocop:enable Discourse/NoChdir
25
33
  spec.require_paths = ["lib"]
26
34
 
27
35
  spec.add_development_dependency "bundler", "> 1.16"
28
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rake", "> 10"
29
37
  spec.add_development_dependency "minitest", "~> 5.0"
30
38
  spec.add_development_dependency "guard", "~> 2.14"
31
39
  spec.add_development_dependency "guard-minitest", "~> 2.4"
32
40
  spec.add_development_dependency "activesupport", "~> 5.2"
41
+ spec.add_development_dependency 'rubocop', '~> 1.4.0'
42
+ spec.add_development_dependency 'rubocop-discourse', '~> 2.4.1'
43
+ spec.add_development_dependency 'm', '~> 1.5.1'
33
44
 
34
45
  if RUBY_ENGINE == 'jruby'
35
46
  spec.add_development_dependency "activerecord-jdbcpostgresql-adapter", "~> 52.2"
36
47
  else
37
48
  spec.add_development_dependency "pg", "> 1"
49
+ spec.add_development_dependency "mysql2"
38
50
  spec.add_development_dependency "sqlite3", "~> 1.3"
39
51
  end
40
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-11 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.4.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.4.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-discourse
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.4.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: m
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.5.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.5.1
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: pg
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +150,20 @@ dependencies:
108
150
  - - ">"
109
151
  - !ruby/object:Gem::Version
110
152
  version: '1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mysql2
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
111
167
  - !ruby/object:Gem::Dependency
112
168
  name: sqlite3
113
169
  requirement: !ruby/object:Gem::Requirement
@@ -129,8 +185,10 @@ executables: []
129
185
  extensions: []
130
186
  extra_rdoc_files: []
131
187
  files:
188
+ - ".github/workflows/ci.yml"
132
189
  - ".gitignore"
133
- - ".travis.yml"
190
+ - ".rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml"
191
+ - ".rubocop.yml"
134
192
  - CHANGELOG
135
193
  - CODE_OF_CONDUCT.md
136
194
  - Gemfile
@@ -139,28 +197,37 @@ files:
139
197
  - README.md
140
198
  - Rakefile
141
199
  - bench/timestamp_perf.rb
200
+ - bench/topic_mysql_perf.rb
142
201
  - bench/topic_perf.rb
143
202
  - bin/console
144
203
  - bin/setup
145
204
  - lib/mini_sql.rb
146
205
  - lib/mini_sql/builder.rb
147
206
  - lib/mini_sql/connection.rb
207
+ - lib/mini_sql/decoratable.rb
148
208
  - lib/mini_sql/deserializer_cache.rb
149
209
  - lib/mini_sql/inline_param_encoder.rb
210
+ - lib/mini_sql/mysql/connection.rb
211
+ - lib/mini_sql/mysql/deserializer_cache.rb
150
212
  - lib/mini_sql/postgres/coders.rb
151
213
  - lib/mini_sql/postgres/connection.rb
152
214
  - lib/mini_sql/postgres/deserializer_cache.rb
153
215
  - lib/mini_sql/postgres_jdbc/connection.rb
154
216
  - lib/mini_sql/postgres_jdbc/deserializer_cache.rb
217
+ - lib/mini_sql/result.rb
218
+ - lib/mini_sql/serializer.rb
155
219
  - lib/mini_sql/sqlite/connection.rb
156
220
  - lib/mini_sql/sqlite/deserializer_cache.rb
157
221
  - lib/mini_sql/version.rb
158
222
  - mini_sql.gemspec
159
- homepage: https://discourse.org
223
+ homepage: https://github.com/discourse/mini_sql
160
224
  licenses:
161
225
  - MIT
162
- metadata: {}
163
- post_install_message:
226
+ metadata:
227
+ bug_tracker_uri: https://github.com/discourse/mini_sql/issues
228
+ source_code_uri: https://github.com/discourse/mini_sql
229
+ changelog_uri: https://github.com/discourse/mini_sql/blob/master/CHANGELOG
230
+ post_install_message:
164
231
  rdoc_options: []
165
232
  require_paths:
166
233
  - lib
@@ -175,8 +242,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
242
  - !ruby/object:Gem::Version
176
243
  version: '0'
177
244
  requirements: []
178
- rubygems_version: 3.0.3
179
- signing_key:
245
+ rubygems_version: 3.2.3
246
+ signing_key:
180
247
  specification_version: 4
181
248
  summary: A fast, safe, simple direct SQL executor
182
249
  test_files: []
@@ -1,21 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.5.1
4
- - ruby-head
5
-
6
- before_install:
7
- - gem install bundler
8
-
9
- cache: bundler
10
- sudo: false
11
-
12
- addons:
13
- postgresql: 9.6
14
-
15
- install:
16
- - createdb test_mini_sql
17
- - bundle install
18
-
19
- matrix:
20
- allow_failures:
21
- - rvm: ruby-head