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 +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +15 -17
- data/ensql.gemspec +1 -1
- data/gemfiles/maintained.gemfile.lock +1 -1
- data/gemfiles/minimum.gemfile.lock +1 -1
- data/lib/ensql/load_sql.rb +3 -0
- data/lib/ensql/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9e2413596055c82bef5870277ed617889235a66bc6854c762886f14783580c7
|
4
|
+
data.tar.gz: 2993ee9976c316a975fd51dc18b53f187298f7e6e2a4627b0b59dc9bd233ec54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[](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.
|
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
|
-
#
|
34
|
-
Ensql.run("
|
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
|
-
#
|
37
|
-
Ensql.sql
|
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
|
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
|
127
|
-
|
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
|
-
|
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
|
-
|
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
|
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 = "
|
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")
|
data/lib/ensql/load_sql.rb
CHANGED
@@ -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
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
|
+
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-
|
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:
|
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.
|
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
|