simple-sql 0.5.36 → 0.9.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5185777df8efad3d0d17334a70d30b35551f4abd7adf0fded3549dd2d1b1325
4
- data.tar.gz: e34ee800440259bfbe8ef88f9f70fb1675dee4a91e441c162a8bdc6313e5d88f
3
+ metadata.gz: 75d235ac454cec6f58662af61d97c7fddf980da80c8bb6f9369db3f0e28e5c68
4
+ data.tar.gz: 6f047d1c86fdc3308d0b4f32616640d9c083c9bcab2360539ecf16d940bbf1da
5
5
  SHA512:
6
- metadata.gz: 9b03b9f204d9bd0e87e0c349f1f2ab962bc94101f14ab33cb2522c0287861e801ddca3cd98e97f4317716df7a07a054f6acf26837309f18bc14b8a50f95eac4a
7
- data.tar.gz: 5eb4fe4c83ca847aef2263251b56f95b3ea450c15abc1e8289ed92bbcaaaa5d5d8a3683814c009c2dd4928d679a4072d10717a616e3cbac2978d59f2d2f453e8
6
+ metadata.gz: d7e366a2dd129d99b3ca48fb9b1bd49e37f7bb403f97b7c2fcc87c7f305417fc23ba333e76bbfa457fe57e27bf2df707c2214adf75382ae280cdde9f9c155b34
7
+ data.tar.gz: 07ed66bd39a8c7db53807ad0f54bab797d6a72d6ee63f38a011e5da753ba170ff865fb00705eee82835d53b8fbdd5c97cc494926f2944ec5089972db4897d309
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ Gemfile.lock
8
8
  .rspec.status
9
9
  .DS_Store
10
10
  tmp
11
+ log/integration_tests.log
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 3.2
3
+ NewCops: disable
3
4
  Exclude:
4
5
  - 'spec/**/*'
5
6
  - 'test/**/*'
@@ -79,3 +80,7 @@ Style/TrailingUnderscoreVariable:
79
80
 
80
81
  Style/StderrPuts:
81
82
  Enabled: false
83
+
84
+ # https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashSyntax
85
+ Style/HashSyntax:
86
+ EnforcedShorthandSyntax: never
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7
1
+ 3.3.8
data/Gemfile CHANGED
@@ -1,7 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'pry-byebug'
4
- gem 'rubocop', '~> 0.57.2'
4
+ gem 'rubocop', '~> 1.54.1'
5
+
6
+ gem 'rake', '>= 12.3.3'
7
+ gem 'rspec', '~> 3.7'
8
+ gem 'simplecov', '~> 0'
5
9
 
6
10
  # Specify your gem's dependencies in {gemname}.gemspec
7
11
  gemspec
data/Makefile CHANGED
@@ -1,16 +1,8 @@
1
- tests: test4 test5 test6
1
+ default:
2
+ bundle exec rspec
2
3
 
3
- test4:
4
- SIMPLE_SQL_ACTIVERECORD_SPECS="> 4,< 5" bundle
5
- rspec
6
-
7
- test5:
8
- SIMPLE_SQL_ACTIVERECORD_SPECS="> 5,< 6" bundle update activerecord
9
- rspec
10
-
11
- test6:
12
- SIMPLE_SQL_ACTIVERECORD_SPECS="> 6,< 7" bundle update activerecord
13
- rspec
4
+ tests:
5
+ ./scripts/integration_tests
14
6
 
15
7
  stats:
16
8
  @scripts/stats lib/simple/sql
data/README.md CHANGED
@@ -1,85 +1,112 @@
1
1
  # simple-sql
2
2
 
3
- The simple-sql gem defines a module `Simple::SQL`, which you can use to execute
4
- SQL statements on a Postgresql database. Care has been taken to provide the
5
- simplest interface we could come up with.
3
+ The simple-sql gem defines a module `Simple::SQL`, which you can use to execute SQL statements on a Postgresql database. Care has been taken to provide the simplest interface we could come up with.
6
4
 
7
- **Note:** Databases other than Postgresql are not supported, and there are no
8
- plans to do so. If you deem that necessary, feel free to fork this code into a
9
- `simple-sql-<yourdatabase>` gem to provide the same or a similar interface.
5
+ However, apart from providing a simple interface `simple-sql` also provides a huge performance boon over `ActiveRecord` when interacting with your database, by cutting out all the `ActiveRecord` layers between the `pg` gem and you ruby code. However, `simple-sql` is still using ActiveRecord to manage connections.
10
6
 
11
- ## Installation
7
+ **Note:** Databases other than Postgresql are not supported, and there are no plans to do so.
8
+
9
+ <!-- TOC -->
12
10
 
13
- The gem is available on rubygems as `simple-sql`. To use it add the following
14
- line to your `Gemfile` and bundle us usual:
11
+ ## Installation
15
12
 
16
- gem 'simple-sql' # + version
13
+ The gem is available on rubygems as `simple-sql`.
17
14
 
18
- ## Usage
15
+ Also make sure to add the `pg` gem to your Gemfile. `simple-sql` should be pretty flexible about the `pg` version: the earliest supported version is `0.21`.
19
16
 
20
- ### Connecting to a database
17
+ To use it add the following lines to your `Gemfile` and bundle up usual:
21
18
 
22
- Before you can send SQL commands to a database you need to connect first. `simple-sql`
23
- gives you the following options:
19
+ ```ruby
20
+ gem 'simple-sql' # + version
21
+ gem 'pg' # + version
22
+ ```
24
23
 
25
- 1. **Use the current ActiveRecord connection:** when running inside a Rails application
26
- you typically have a connection to Postgresql configured already. In that case you
27
- don't need to do anything; `simple-sql` will just use the current database connection.
28
-
29
- This is usually the right thing, especially since `simple-sql`, when called from inside
30
- a controller action, is using the connection valid in the current context.
24
+ ## Connecting to a database
31
25
 
32
- 2. **Explicitely connect** on standalone applications you need to connect to a Postgresql
33
- server. **Note that in this case there are no pooled connections!** simple-sql is not
34
- thread-/fiber-safe in this mode.
26
+ Before you can send SQL commands to a database you need to connect first. `simple-sql` gives you the following options:
35
27
 
36
- You can explictely connect to a server by calling
28
+ ### Explicitly connect to the database
37
29
 
38
- ::Simple::SQL.connect! "postgres://user:password@server[:port]/database"
30
+ In a standalone applications you need to connect to a Postgresql server. `simple-sql` uses ActiveRecord's connection handling.
39
31
 
40
- Alternatively, you can have `simple-sql` figure out the details automatically:
32
+ You can explicitly connect to a server by calling
41
33
 
42
- ::Simple::SQL.connect!
34
+ ```ruby
35
+ db = ::Simple::SQL.connect! "postgres://user:password@server[:port]/database"
36
+ ```
43
37
 
44
- In that case we try to find connection parameters in the following places:
45
-
46
- - the `DATABASE_URL` environment value
47
- - the `config/database.yml` file from the current directory, taking `RAILS_ENV`/`RACK_ENV` into account.
38
+ You can then use `db.ask`, `db.all`, etc. (See below)
48
39
 
49
- ### Using placeholders
40
+ ### Automatically determine connection details
50
41
 
51
- Note: whenever you run a query `simple-sql` takes care of sending query parameters over the wire properly. That means that you use placeholders `$1`, `$2`, etc. to use these inside your queries; the following is a correct example:
42
+ Alternatively, you can have `simple-sql` figure out the details automatically:
52
43
 
53
44
  ```ruby
54
- Simple::SQL.all "SELECT * FROM users WHERE email=$1", "foo@bar.local"
45
+ db = ::Simple::SQL.connect!
55
46
  ```
56
47
 
57
- Also note that it is not possible to use an array as the argument for the `IN(?)` SQL construct. Instead you want to use `ANY`, for example:
48
+ In that case we try to find connection parameters in the following places:
49
+
50
+ - the `DATABASE_URL` environment value
51
+ - the `config/database.yml` file from the current directory, taking `RAILS_ENV`/`RACK_ENV` into account.
52
+
53
+ ### Using the default connection
54
+
55
+ You don't need to call `::Simple::SQL.connect!` inside a Rails application. `simple-sql` automatically uses the default connection when using `Simple::SQL` instead of an explicit database handle; i.e. typically you can use
58
56
 
59
57
  ```ruby
60
- Simple::SQL.all "SELECT * FROM users WHERE id = ANY($1)", [1,2,3]
58
+ Simple::SQL.ask "SELECT ..."
61
59
  ```
62
60
 
61
+ and `simple-sql` will be doing the right thing.
62
+
63
+ This is especially true in a Rails' applications controller action, because it allows you to mix Simple::SQL and ActiveRecord interactions with the database.
64
+
65
+ ## Simple queries
66
+
63
67
  ### Simple::SQL.all: Fetching all results of a query
64
68
 
65
69
  `Simple::SQL.all` runs a query, with optional arguments, and returns the result. Usage example:
66
70
 
67
- Simple::SQL.all "SELECT id, email FROM users WHERE id = ANY($1)", [1,2,3]
71
+ ```ruby
72
+ # returns an array of arrays `[ <id>, <email> ]`.
73
+ Simple::SQL.all "SELECT id, email FROM users WHERE id = ANY($1)", [1,2,3]
74
+ ```
75
+
76
+ If a block is passed to SQL.all, each row is yielded into the block:
77
+
78
+ ```ruby
79
+ Simple::SQL.all "SELECT id, email FROM users" do |id, email|
80
+ # do something
81
+ end
82
+ ```
68
83
 
69
- If the SQL query returns rows with one column, this method returns an array of these values.
70
- Otherwise it returns an array of arrays.
84
+ Typically the SQL query returns an array of arrays (1 per row). If, however, the query is set up to only return a single column, this method returns an array of these values instead. This is especially useful with the block version:
71
85
 
72
86
  Examples:
73
87
 
74
88
  ```ruby
75
89
  Simple::SQL.all("SELECT id FROM users") # returns an array of id values, but
76
- Simple::SQL.all("SELECT id, email FROM users") # returns an array of arrays `[ <id>, <email> ]`.
90
+
91
+ Simple::SQL.all "SELECT id FROM users" do |id|
92
+ # do something with the users' ids.
93
+ end
77
94
  ```
78
95
 
79
- If a block is passed to SQL.all, each row is yielded into the block:
96
+ ### Simple::SQL.each: run a block with each result of a query
97
+
98
+ This is identical to `.all`. It might offer beneficial optimisations, but this is theoretical at this point.
80
99
 
81
100
  ```ruby
82
- Simple::SQL.all "SELECT id, email FROM users" do |id, email|
101
+ Simple::SQL.each "SELECT id, email FROM users" do |id, email|
102
+ # do something
103
+ end
104
+ ```
105
+
106
+ ### Simple::SQL.print: Printing results of a query
107
+
108
+ ```ruby
109
+ Simple::SQL.print "SELECT id, email FROM users" do |id, email|
83
110
  # do something
84
111
  end
85
112
  ```
@@ -88,9 +115,13 @@ end
88
115
 
89
116
  `Simple::SQL.ask` runs a query, with optional arguments, and returns the first result row or nil, if there was no result.
90
117
 
91
- Simple::SQL.ask "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1", [1,2,3]
118
+ ```ruby
119
+ Simple::SQL.ask "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1", [1,2,3]
120
+ ```
121
+
122
+ If the SQL query only returns a single column, this method returns the column value of the first row; otherwise it returns an array (or `nil` if there was no result).
92
123
 
93
- If the SQL query returns rows with one column, this method returns the column value of the first row; otherwise it returns an array (or `nil` if there was no result).
124
+ Usually all attributes are converted to its corresponding ruby type.
94
125
 
95
126
  Examples:
96
127
 
@@ -99,75 +130,146 @@ Simple::SQL.ask "SELECT id FROM users WHERE email=$1", "foo@local" # ret
99
130
  Simple::SQL.ask "SELECT id, email FROM users WHERE email=$?", "foo@local" # returns an array `[ <id>, <email> ]` (or `nil`)
100
131
  ```
101
132
 
102
- ### Simple::SQL.ask/Simple::SQL.all: fetching hashes
133
+ ### Using placeholders
134
+
135
+ Note: whenever you run a query `simple-sql` takes care of sending query parameters over the wire properly. That means that you use placeholders `$1`, `$2`, etc. to use these inside your queries; the following is a correct example:
136
+
137
+ ```ruby
138
+ Simple::SQL.all "SELECT * FROM users WHERE email=$1", "foo@bar.local"
139
+ ```
140
+
141
+ Usually arguments are converted correctly when sending over to the database. One notable exception is sending `jsonb` data - you must use JSON.encode on the argument:
142
+
143
+ ```ruby
144
+ Simple::SQL.ask "INSERT INTO table (column) VALUES($1)", JSON.encode(..)
145
+ ```
146
+
147
+ It is probably worth pointing out that you cannotto use an array as the argument for the `IN(?)` SQL construct. Instead you want to use `ANY`, for example:
148
+
149
+ ```ruby
150
+ Simple::SQL.all "SELECT * FROM users WHERE id = ANY($1)", [1,2,3]
151
+ ```
152
+
153
+ ### Determining the result type
154
+
155
+ By default `ask` and `all` convert each result row into an Array. Sometimes you might want to use Hashes or similar objects instead. To do so, you use the `into:` keyword argument:
156
+
157
+ ```ruby
158
+ # returns a single Hash (or nil)
159
+ Simple::SQL.ask("SELECT id FROM users", into: Hash)
160
+ ```
161
+
162
+ If you want the returned record to be in a structure which is not a Hash, you can use the `into: <klass>` option. The following would return an array of up to two `OpenStruct` objects:
103
163
 
104
- While `ask` and `all` convert each result row into an Array, sometimes you might want
105
- to use Hashes or similar objects instead. To do so, you use the `into:` keyword argument:
164
+ ```ruby
165
+ sql = "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1",
166
+ Simple::SQL.all sql, [1,2,3], into: OpenStruct
167
+ ```
106
168
 
107
- # returns a single Hash (or nil)
108
- Simple::SQL.ask("SELECT id FROM users", into: Hash)
169
+ This supports all target types that take a constructor accepting Hash arguments.
109
170
 
110
- If you want the returned record to be in a structure which is not a Hash, you can use
111
- the `into: <klass>` option. The following would return an array of up to two `OpenStruct`
112
- objects:
171
+ It also supports a `:struct` argument, in which case simple-sql creates uses a Struct-class. Struct classes are reused when possible, and are maintained by `Simple::SQL`. This is potentially the best performing option when you want to use dot-notation.
113
172
 
114
- sql = "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1",
115
- Simple::SQL.all sql, [1,2,3], into: OpenStruct
173
+ ```ruby
174
+ sql = "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1",
175
+ Simple::SQL.all sql, [1,2,3], into: :struct
176
+ ```
116
177
 
117
- This supports all target types that take a contructor which acceps Hash arguments.
178
+ ### Running non-`SELECT` queries
118
179
 
119
- It also supports a :struct argument, in which case simple-sql creates uses a Struct-class.
120
- Struct classes are reused when possible, and are maintained by Simple::SQL.
180
+ You can use `all` and `ask` with other queries as well. However, both only support running a single query. If you want to run multiple queries (i.e. a SQL script) you would probably look into `Simple::SQL.exec` instead.
121
181
 
122
- sql = "SELECT id, email FROM users WHERE id = ANY($1) LIMIT 1",
123
- Simple::SQL.all sql, [1,2,3], into: :struct
182
+ Be aware that `Simple::SQL.exec` does not support placeholders: you cannot pass in arguments into `Simple::SQL.exec`.
124
183
 
125
184
  ### Transaction support
126
185
 
127
- `simple-sql` has limited support for nested transactions. When running with a ActiveRecord
128
- connection, we use ActiveRecord's transaction implementation (which uses savepoints for nested
129
- transactions, so you might be able to rollback from inside a nested transaction).
186
+ `simple-sql` borrows transaction support from `ActiveRecord`.
130
187
 
131
- When connecting via `Simple::SQL.connect!` we do not support the same level of nesting support (yet). You can still nest transactions, but raising an error terminates *all* current transactions.
188
+ ## Using scopes
132
189
 
133
- ## Logging
190
+ A scope lets you build a condition over time, like this:
191
+
192
+ ```ruby
193
+ scope = db.scope "SELECT * FROM users"
194
+ scope = scope.where(email: ["foo@foobar.test", "bar@foobar.test"])
195
+ scope = scope.where("deleted_at is NULL")
196
+ users = scope.all
197
+ ```
134
198
 
135
- `simple-sql` builds a logger which logs all queries. The logger, by default, is
136
- created to write to STDERR; to get another logger use code like
199
+ This also works with the default connection, via `scope = Simple::SQL.scope ...`.
137
200
 
138
- Simple::SQL.logger = Rails.logger
201
+ A scope supports the following methods to set up a scope:
139
202
 
140
- ## Bugs and Limitations
203
+ | | |
204
+ |---------------------------|---------------------------------------------|
205
+ | `where(args...)` | add additional conditions. `where` also has additional support for using `?` instead of `$nn`, and supports JSONB query conditions. See [where.rb](lib/simple/sql/connection/scope/where.rb) for details.|
206
+ | `order_by(sql_fragment)` ||
207
+ | `limit(limit)` ||
208
+ | `offset(offset)` ||
209
+ | `paginate(per:, page:)` | adds pagination (calls `limit` and `offset`) |
141
210
 
142
- ### 1. Multiple connections
143
211
 
144
- It is currently not possible to run SQL queries against a database which is not
145
- connected via ActiveRecord::Base.connection.
212
+ These methods can then be used to evaluate the scope:
146
213
 
147
- ### 2. Postgresql only
214
+ | | |
215
+ |---------------------------|---------------------------------------------|
216
+ | `all(into: ...)` | returns all matching entries |
217
+ | `first(into: ...)` | returns the first matching entry|
218
+ | `count` | returns the exact count of matching records|
219
+ | `count_estimate` | returns a fast estimate of the count of matching records. Note that this needs suitable and up-to-date indices.|
220
+ | `enumerate_groups(sql)` | returns all groups |
221
+ | `count_by(sql)` | counts by groups |
222
+ | `print` | print all matching entries|
223
+ | `explain` | returns the query plan|
148
224
 
149
- Only Postgresql is supported.
225
+ ## Inserting objects
150
226
 
151
- ### 3. Limited support for types
227
+ Inserting objects is much faster via `simple-sql`. You should be able to insert ~1000 or so records per second into a table with no trouble.
152
228
 
153
- This gem does not use `pg`'s support for encoding and decoding types, since
154
- that might probably interfere with how ActiveRecord is setting up the `pg`
155
- gem.
229
+ ```ruby
230
+ Simple::SQL.insert :users, first_name: "foo", last_name: "bar"
231
+ ```
232
+
233
+ ```ruby
234
+ users = []
235
+ users.push first_name: "first", last_name: "user"
236
+ users.push first_name: "second", last_name: "user"
237
+
238
+ Simple::SQL.insert :users, users
239
+ ```
240
+
241
+ The `.insert` method lets you set up conflict resolution, via
242
+
243
+ ```ruby
244
+ Simple::SQL.insert :users, users, on_conflict: :ignore
245
+ ```
246
+
247
+ ## Advisory Locks
248
+
249
+ ```ruby
250
+ Simple::SQL.transaction do
251
+ Simple::SQL.lock!(4711)
252
+
253
+ # do something.
254
+ end
255
+ ```
256
+
257
+ ## Logging
156
258
 
157
- It therefore assumes ActiveRecord is used in the same project, which sets up
158
- pg to not decode data in any meaningful way, and provides some code to decode
159
- the data returned from the database. Only a handful of types is currently
160
- supported by the Decoder - it is fairly easy to add new types, though.
259
+ `simple-sql` builds a logger which logs all queries. The logger, by default, is created to write to STDERR; to get another logger use code like
161
260
 
162
- ### 4. text arrays
261
+ ```ruby
262
+ Simple::SQL.logger = Rails.logger
263
+ ```
264
+
265
+ ## Bugs and Limitations
266
+
267
+ **Limited support for types:** This gem does not use `pg`'s support for encoding and decoding types, since that might probably interfere with how ActiveRecord is setting up the `pg` gem.
163
268
 
164
- The library used to parse array results seems to be buggy if the array contains
165
- strings containing the "`" character.
269
+ It therefore assumes ActiveRecord is used in the same project, which sets up pg to not decode data in any meaningful way, and provides some code to decode the data returned from the database. Only a handful of types is currently supported by the Decoder - it is fairly easy to add new types, though.
166
270
 
167
271
  ## Test
168
272
 
169
273
  1. `createdb simple-sql-test`
170
274
  2. `bundle install`
171
275
  3. `bin/rspec`
172
-
173
- ## Test again
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.36
1
+ 0.9.0
data/bin/db_restore CHANGED
@@ -3,7 +3,13 @@ require 'yaml'
3
3
 
4
4
  env = ENV["POSTJOB_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
5
5
 
6
- configs = YAML.load_file "config/database.yml"
6
+ path = "config/database.yml"
7
+ configs = if Psych::VERSION > '4.0'
8
+ YAML.safe_load(File.read(path), aliases: true)
9
+ else
10
+ YAML.safe_load(File.read(path), [], [], true)
11
+ end
12
+
7
13
  config = configs.fetch(env) { configs.fetch("defaults") }
8
14
 
9
15
  ENV["PGHOST"] = config["host"]
data/bin/pg CHANGED
@@ -3,7 +3,13 @@ require 'yaml'
3
3
 
4
4
  env = ENV["POSTJOB_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
5
5
 
6
- configs = YAML.load_file "config/database.yml"
6
+ path = "config/database.yml"
7
+ configs = if Psych::VERSION > '4.0'
8
+ YAML.safe_load(File.read(path), aliases: true)
9
+ else
10
+ YAML.safe_load(File.read(path), [], [], true)
11
+ end
12
+
7
13
  config = configs.fetch(env) { configs.fetch("defaults") }
8
14
 
9
15
  ENV["PGHOST"] = config["host"]
data/config/database.yml CHANGED
@@ -2,8 +2,8 @@ defaults: &defaults
2
2
  adapter: postgresql
3
3
  encoding: utf8
4
4
  host: '127.0.0.1'
5
- username: admin
6
- password: admin
5
+ # username: admin
6
+ # password: admin
7
7
  pool: 5
8
8
  timeout: 5000
9
9
 
@@ -16,7 +16,7 @@ module Simple::SQL::Config
16
16
 
17
17
  config = {
18
18
  dbname: uri.path.sub(%r{^/}, ""),
19
- host: uri.hostname
19
+ host: uri.hostname
20
20
  }
21
21
  config[:port] = uri.port if uri.port
22
22
  config[:user] = uri.user if uri.user
@@ -55,7 +55,12 @@ module Simple::SQL::Config
55
55
 
56
56
  def load_activerecord_base_configuration(path:, env:)
57
57
  require "yaml"
58
- database_config = YAML.load_file(path)
58
+ database_config = if Psych::VERSION > '4.0'
59
+ YAML.safe_load(File.read(path), aliases: true)
60
+ else
61
+ YAML.safe_load(File.read(path), [], [], true)
62
+ end
63
+
59
64
  env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
60
65
 
61
66
  database_config[env] ||
@@ -81,6 +81,7 @@ class Simple::SQL::Connection
81
81
  # - <tt>Simple::SQL.ask "SELECT id, email FROM users WHERE email=$?", "foo@local"</tt>
82
82
  # returns an array <tt>[ <id>, <email> ]</tt> (or +nil+)
83
83
  def ask(sql, *args, into: nil)
84
+ # rubocop:disable Lint/UnreachableLoop
84
85
  catch(:ok) do
85
86
  each(sql, *args, into: into) { |row| throw :ok, row }
86
87
  nil
@@ -28,9 +28,9 @@ class Simple::SQL::Connection
28
28
 
29
29
  class Inserter
30
30
  CONFICT_HANDLING = {
31
- nil => "",
31
+ nil => "",
32
32
  :nothing => "ON CONFLICT DO NOTHING",
33
- :ignore => "ON CONFLICT DO NOTHING"
33
+ :ignore => "ON CONFLICT DO NOTHING"
34
34
  }
35
35
 
36
36
  #
@@ -89,6 +89,7 @@ class Simple::SQL::Connection
89
89
 
90
90
  def json_encode(value)
91
91
  return value unless value.is_a?(Hash) || value.is_a?(Array)
92
+
92
93
  JSON.generate(value)
93
94
  end
94
95
  end
@@ -1,5 +1,7 @@
1
1
  # rubocop:disable Metrics/ClassLength
2
2
 
3
+ require "ostruct"
4
+
3
5
  class Simple::SQL::Connection
4
6
  def reset_reflection
5
7
  @reflection = nil