lucid_sql 0.0.1
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 +7 -0
- data/README.md +33 -0
- data/lib/lucid_sql.rb +7 -0
- data/lib/lucid_sql/repository.rb +40 -0
- data/lib/lucid_sql/sequel_repository.rb +20 -0
- data/lib/lucid_sql/version.rb +5 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c00444e0fe6bc55aa9c3981a8860ef47ac697627e49df1bd94ed38555a49e1c8
|
4
|
+
data.tar.gz: 79f39519dc3c1f7a93693db609e7c3b2873f0b6a85c50134a5ec12d9ebd7e0e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd6a75ab3688e675d9e4043f5f0de0c65efeae6a2a9e179ab659f28d917cee5a1efec680f5c136b6c7b516eb31d1ec433d1483dbe8b9dc910848e6062b91ba99
|
7
|
+
data.tar.gz: 4c89cc2d9e9fcc258f93b32c45896f40784bbd8b6f01dd681994ac5db13efef2d1c2986ed223a2745d62f3befc5a67b1eae3b99ad718369e4f10842e02e3c483
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
lucid_sql
|
2
|
+
=========
|
3
|
+
|
4
|
+
Installation
|
5
|
+
------------
|
6
|
+
|
7
|
+
Add the gem to your ‘Gemfile’:
|
8
|
+
|
9
|
+
gem 'lucid_sql'
|
10
|
+
|
11
|
+
|
12
|
+
Usage
|
13
|
+
-----
|
14
|
+
|
15
|
+
### Without Sequel gem
|
16
|
+
|
17
|
+
sql = LucidSQL::Repository.new('sql/*.sql')
|
18
|
+
|
19
|
+
sql.select_unpublished_products # sql/select_unpublished_products.sql
|
20
|
+
|
21
|
+
Interpolate trusted data for query reuse (see `String#%`).
|
22
|
+
|
23
|
+
sql.copy_from_stdin(table: 'products')
|
24
|
+
|
25
|
+
Does not support bind parameters.
|
26
|
+
|
27
|
+
### With Sequel gem
|
28
|
+
|
29
|
+
sql = LucidSQL::SequelRepository.new('sql/*.sql')
|
30
|
+
|
31
|
+
Splat arguments are bind parameters (see `Sequel.lit`).
|
32
|
+
|
33
|
+
sql.copy_from('/path/to/copy_data/products', table: 'products')
|
data/lib/lucid_sql.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LucidSQL
|
4
|
+
class Repository
|
5
|
+
#
|
6
|
+
# @param glob [String, #to_s] glob pattern for .sql file paths
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# LucidSQL::Repository.new(Hanami.root.join('sql', '*.sql'))
|
10
|
+
#
|
11
|
+
def initialize(glob)
|
12
|
+
Dir.glob(glob.to_s).each do |f|
|
13
|
+
m = File.basename(f, '.sql')
|
14
|
+
s = File.read(f).strip.gsub(/\s+/, ' ')
|
15
|
+
|
16
|
+
define_reader(m, s)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# @param method_name [String]
|
22
|
+
# @param sql [String]
|
23
|
+
#
|
24
|
+
private def define_reader(method_name, sql)
|
25
|
+
define_singleton_method(method_name) do |*args, **kwargs|
|
26
|
+
format(sql, *args, **kwargs)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# @param sql [String] the raw SQL string
|
32
|
+
# @param **kwargs [Hash] direct interpolation via template string (do not use with untrusted input)
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
private def format(sql, **kwargs)
|
37
|
+
sql % kwargs
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'lucid_sql/repository'
|
4
|
+
|
5
|
+
module LucidSQL
|
6
|
+
if defined?(::Sequel)
|
7
|
+
class SequelRepository < Repository
|
8
|
+
#
|
9
|
+
# @param sql [String] the raw SQL string
|
10
|
+
# @param *args [Array] bind parameters
|
11
|
+
# @param **kwargs [Hash] direct interpolation via template string (do not use with untrusted input)
|
12
|
+
#
|
13
|
+
# @return [Sequel::LiteralString, Sequel::SQL::PlaceholderLiteralString]
|
14
|
+
#
|
15
|
+
private def format(sql, *args, **kwargs)
|
16
|
+
Sequel.lit(sql % kwargs, *args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lucid_sql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelsey Judson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '12.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.52.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.52.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sequel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.10'
|
69
|
+
description:
|
70
|
+
email: kelsey@lucid.nz
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- README.md
|
76
|
+
- lib/lucid_sql.rb
|
77
|
+
- lib/lucid_sql/repository.rb
|
78
|
+
- lib/lucid_sql/sequel_repository.rb
|
79
|
+
- lib/lucid_sql/version.rb
|
80
|
+
homepage: https://github.com/lucidnz/gem-lucid_sql
|
81
|
+
licenses:
|
82
|
+
- ISC
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.7.3
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Read SQL statements from files
|
104
|
+
test_files: []
|