ensql 0.6.4 → 0.6.5

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: 689e8e2af4e7e8c941ed6f14937288a3e080f822b71ee22938898ac0a15f5277
4
- data.tar.gz: 9693bc5e2476794d9f60feb70e80c821596ec18a4e71993d45aee65a26a152f1
3
+ metadata.gz: a9e2413596055c82bef5870277ed617889235a66bc6854c762886f14783580c7
4
+ data.tar.gz: 2993ee9976c316a975fd51dc18b53f187298f7e6e2a4627b0b59dc9bd233ec54
5
5
  SHA512:
6
- metadata.gz: 10c90d7568c1c6ed34b9cb04e4a2e4a9af0ed6bb788ea6ec88f206b807468091e9d541f6dfc79ae7eb3d5e90b92e33a12718aae1c4d7e6977352331a499fbee1
7
- data.tar.gz: 6b945c42734e68a599b2d32d825fa6c9d8b61a7eb1175086afae237c21fb58d30d4753eb916a69716a2c0c3a43dd51da34d655fb6b145352814d5256aa137d9d
6
+ metadata.gz: 47ee3648dc665dacc57263befd5c46466f36688138120d7c7b82b5a3464daf3c262e28bcc2eb9dd7f58f6cdea13838a352fe93d9b58f63a9543eca2aadcab40d
7
+ data.tar.gz: 51afecfd75ac23a5820538cd6c1914d48aeba21fea5e2b8f07a2bb193f4474329b9a6723c43addb5bcfc24642d3ca96c6efd7883ce1762ecc2ee57598f495461
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
 
3
- ## [0.6.4] - unreleased
3
+ ## [0.6.5] - 2021-03-24
4
+
5
+ - Raises `Ensql::Error` with a more helpful message when `load_sql` can't find a file.
6
+
7
+ ## [0.6.4] - 2021-03-12
4
8
 
5
9
  - Exposes `PostgresAdapter#query_type_map` to extend PG type mapping.
6
10
  - Defers building type maps for PostgreSQL connections, to avoid bugs with ActiveRecord.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ensql (0.6.4)
4
+ ensql (0.6.5)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
7
7
 
8
8
  Ensql provides a light-weight wrapper over your existing database connections, letting you write plain SQL for your
9
- application safely and simply. Ditch your ORM and embrace the power and ease of writing SQL again.
9
+ application safely and simply. Escape your ORM and embrace the power and ease of writing SQL again.
10
10
 
11
11
  * **Write exactly the SQL you want.** Don't limit your queries to what's in the Rails docs. Composable scopes and
12
12
  dynamic includes can cripple performance for non-trivial queries. Break through the ORM abstraction and unlock the
@@ -30,14 +30,12 @@ application safely and simply. Ditch your ORM and embrace the power and ease of
30
30
  ActiveRecord or Sequel so you don't need to manage a separate connection to the database.
31
31
 
32
32
  ```ruby
33
- # Run adhoc statements
34
- Ensql.run("SET TIME ZONE 'UTC'")
33
+ # Safely interpolate parameters into adhoc statements with correct quoting and escaping.
34
+ Ensql.run("INSERT INTO users (email) VALUES (%{email})", email: params[:email])
35
+ Ensql.sql("DELETE FROM logs WHERE timestamp < %{expiry}", expiry: 1.month.ago).count # => 100
35
36
 
36
- # Run adhoc D/U/I statements and get the affected row count
37
- Ensql.sql('DELETE FROM logs WHERE timestamp < %{expiry}', expiry: 1.month.ago).count # => 100
38
-
39
- # Organise your SQL and fetch results as convenient Ruby primitives
40
- Ensql.sql_path = 'app/sql'
37
+ # Organise your SQL and fetch results as convenient Ruby primitives.
38
+ Ensql.sql_path = 'app/sql' # Defaults to './sql'. This can be set in an initializer or similar.
41
39
  Ensql.load_sql('customers/revenue_report', params).rows # => [{ "customer_id" => 100, "revenue" => 1000}, … ]
42
40
 
43
41
  # Easily retrive results in the simplest shape
@@ -54,7 +52,7 @@ result = { data: current_results.rows, total: total.first_field }
54
52
  Links:
55
53
 
56
54
  * [Source Code](https://github.com/danielfone/ensql)
57
- * [API Documentation](https://rubydoc.info/gems/ensql/Ensql/SQL)
55
+ * [API Documentation](https://rubydoc.info/gems/ensql)
58
56
  * [Ruby Gem](https://rubygems.org/gems/ensql)
59
57
 
60
58
  ## Installation
@@ -123,15 +121,15 @@ app/sql
123
121
  ### Interpolation
124
122
 
125
123
  All interpolation is marked by `%{}` placeholders in the SQL. This is the only place that user-supplied input should be
126
- allowed. Only various forms of literal interpolation are supported - identifier interpolation is not supported at this
127
- stage.
124
+ allowed. Only literal interpolation is supported - identifier interpolation is not supported at this stage.
125
+
126
+ There are 3 types of safe (correctly quoted/escaped) interpolation:
128
127
 
129
- There are 4 types of interpolation:
128
+ 1. `%{param}` interpolates a Ruby object as a single SQL literal.
129
+ 2. `%{(param)}` expands a Ruby Array into a list of SQL literals.
130
+ 3. `%{param( nested sql )}` interpolates an Array of Hashes into the nested sql with each hash in an array.
130
131
 
131
- 1. `%{param}` interpolates a Ruby object as a SQL literal.
132
- 2. `%{(param)}` expands an array into a list of SQL literals.
133
- 3. `%{param( nested sql )}` interpolates the nested sql with each hash in an array.
134
- 4. `%{!sql_param}` only interpolates Ensql::SQL objects as SQL fragments.
132
+ In addition you can interpolate raw SQL with `%{!sql_param}`. It's up to you to ensure this is safe!
135
133
 
136
134
  ```ruby
137
135
  # Interpolate a literal
@@ -148,7 +146,7 @@ Ensql.sql('INSERT INTO users (name, created_at) VALUES %{users( %{name}, now() )
148
146
  )
149
147
  # INSERT INTO users VALUES ('Claudia Buss', now()), ('Lundy L''Anglais', now())
150
148
 
151
- # Interpolate a SQL fragement
149
+ # Interpolate a raw SQL fragment without quoting. Use with care!
152
150
  Ensql.sql('SELECT * FROM users ORDER BY %{!orderby}', orderby: Ensql.sql('name asc'))
153
151
  # SELECT * FROM users ORDER BY name asc
154
152
  ```
data/ensql.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["daniel@fone.net.nz"]
10
10
 
11
11
  spec.summary = "Write SQL the safe and simple way"
12
- spec.description = "Ditch your ORM and embrace the power and simplicity of writing plain SQL again."
12
+ spec.description = "Escape your ORM and embrace the power and simplicity of writing plain SQL again."
13
13
  spec.homepage = "https://github.com/danielfone/ensql"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ensql (0.6.4)
4
+ ensql (0.6.5)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- ensql (0.6.4)
4
+ ensql (0.6.5)
5
5
  connection_pool (>= 0.9.3, < 3)
6
6
 
7
7
  GEM
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "sql"
4
+ require_relative "error"
4
5
 
5
6
  module Ensql
6
7
  class << self
@@ -31,6 +32,8 @@ module Ensql
31
32
  def load_sql(name, params = {})
32
33
  path = File.join(sql_path, "#{name}.sql")
33
34
  SQL.new(File.read(path), params, name)
35
+ rescue Errno::ENOENT
36
+ raise Error, "couldn't load SQL from file '#{path}' (sql_path: '#{sql_path}')"
34
37
  end
35
38
  end
36
39
  end
data/lib/ensql/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Ensql
4
4
  # Gem version
5
- VERSION = "0.6.4"
5
+ VERSION = "0.6.5"
6
6
  # Versions of activerecord compatible with the {ActiveRecordAdapter}
7
7
  SUPPORTED_ACTIVERECORD_VERSIONS = [">= 5.0", "< 6.2"].freeze
8
8
  # Versions of sequel compatible with the {SequelAdapter}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Fone
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 0.9.26
89
- description: Ditch your ORM and embrace the power and simplicity of writing plain
89
+ description: Escape your ORM and embrace the power and simplicity of writing plain
90
90
  SQL again.
91
91
  email:
92
92
  - daniel@fone.net.nz
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.2.9
148
+ rubygems_version: 3.2.14
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Write SQL the safe and simple way