stairwell 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/lib/stairwell/query.rb +21 -1
- data/lib/stairwell/version.rb +1 -1
- data/lib/stairwell.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a4932425e6273ba11f06755995cc39d7045566808bd60870e5ed3ae866bc1a
|
4
|
+
data.tar.gz: 5694267cbbc05428eb8161c244d7d9ead34c21ee6999156a3046c08a736e524d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdcb61bf3e077028063dc94ecdef023aaccc709fd326cdce4354af181be15c84fbd805b492a324bd6d2117a84c6981b481835cf5ebb879ae84fda9ae2077cbca
|
7
|
+
data.tar.gz: cbb08179152c8bb7205c2d469afe0794e8505757bd65b248e53e7d6f6639fd42fa87a0523bd42993a64e97c47363d702bb90d48f72540ed63468624a49a5b4f4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,22 @@ They types of the binds are validated too.
|
|
83
83
|
The names binds in your sql are also validated.
|
84
84
|
All types are quoted using ActiveRecord quoting, which will be different depending on your database type (Mysql, postgres etc.)
|
85
85
|
|
86
|
+
## SQL files
|
87
|
+
Support for sql files is being trialed. If you would like to reference raw sql file instead of quoting the sql in the ruby file, you can. You just have to place the file adjacent to the ruby file and name them the same eq: ruby file is `users_count.rb` the file would need to be in the same directory and named `users_count.sql`. You also need to set the path in your config:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
# in ruby project:
|
91
|
+
Stairwell.configure do |config|
|
92
|
+
config.path = './app/queries/'
|
93
|
+
end
|
94
|
+
|
95
|
+
# in Rails:
|
96
|
+
Stairwell.configure do |config|
|
97
|
+
config.path = "#{Rails.root}/app/queries"
|
98
|
+
end
|
99
|
+
|
100
|
+
```
|
101
|
+
|
86
102
|
## Supported Types
|
87
103
|
|
88
104
|
| Type | Values Accepted | Info |
|
data/lib/stairwell/query.rb
CHANGED
@@ -9,6 +9,7 @@ module Stairwell
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def sql(**args)
|
12
|
+
set_sql_string_from_file
|
12
13
|
raise InvalidBindCount, 'Incorrect amount of args passed' if args.keys.sort != all_validations.keys.sort
|
13
14
|
|
14
15
|
@type_hash = args.each_with_object({}) do |(name, value), hash|
|
@@ -18,7 +19,7 @@ module Stairwell
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def query(string)
|
21
|
-
@sql_string
|
22
|
+
@sql_string ||= string.squish
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
@@ -28,6 +29,25 @@ module Stairwell
|
|
28
29
|
def transformer
|
29
30
|
BindTransformer.new(sql_string, type_hash)
|
30
31
|
end
|
32
|
+
|
33
|
+
def set_sql_string_from_file
|
34
|
+
return unless Stairwell.configuration.path && File.exist?(associated_sql_file)
|
35
|
+
|
36
|
+
file = File.read(associated_sql_file)
|
37
|
+
@sql_string = file&.squish
|
38
|
+
end
|
39
|
+
|
40
|
+
def associated_sql_file
|
41
|
+
"#{Stairwell.configuration.path}#{camelized_class}.sql"
|
42
|
+
end
|
43
|
+
|
44
|
+
def camelized_class
|
45
|
+
self.to_s.gsub(/::/, '/')
|
46
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
47
|
+
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
|
48
|
+
.tr("-", "_")
|
49
|
+
.downcase
|
50
|
+
end
|
31
51
|
end
|
32
52
|
end
|
33
53
|
end
|
data/lib/stairwell/version.rb
CHANGED
data/lib/stairwell.rb
CHANGED
@@ -20,6 +20,16 @@ module Stairwell
|
|
20
20
|
table_name: 'Stairwell::Types::TableNameType'
|
21
21
|
}.freeze
|
22
22
|
|
23
|
+
class << self
|
24
|
+
def configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure
|
29
|
+
yield configuration
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
23
33
|
# for development and testing
|
24
34
|
unless defined?(Rails)
|
25
35
|
::ActiveRecord::Base.establish_connection(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stairwell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tobyond
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|