yesql 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.rubocop.yml +20 -0
  4. data/Gemfile +9 -0
  5. data/Gemfile.lock +63 -0
  6. data/Rakefile +3 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/lib/yesql.rb +15 -17
  10. data/lib/yesql/bindings/extract.rb +17 -11
  11. data/lib/yesql/bindings/extractor.rb +18 -20
  12. data/lib/yesql/bindings/transformed.rb +7 -5
  13. data/lib/yesql/bindings/utils.rb +6 -7
  14. data/lib/yesql/common/adapter.rb +11 -4
  15. data/lib/yesql/config/configuration.rb +3 -1
  16. data/lib/yesql/errors/file_path_does_not_exist_error.rb +17 -22
  17. data/lib/yesql/errors/no_bindings_provided_error.rb +18 -17
  18. data/lib/yesql/errors/output_argument_error.rb +4 -13
  19. data/lib/yesql/params/output.rb +12 -4
  20. data/lib/yesql/query/performer.rb +8 -4
  21. data/lib/yesql/query/result.rb +11 -5
  22. data/lib/yesql/query/transform_result.rb +19 -8
  23. data/lib/yesql/statement.rb +16 -10
  24. data/lib/yesql/utils/read.rb +8 -11
  25. data/lib/yesql/version.rb +1 -1
  26. data/yesql.gemspec +28 -0
  27. metadata +9 -54
  28. data/lib/.rbnext/2.3/yesql/errors/file_path_does_not_exist_error.rb +0 -40
  29. data/lib/.rbnext/2.3/yesql/errors/no_bindings_provided_error.rb +0 -38
  30. data/lib/.rbnext/2.3/yesql/errors/output_argument_error.rb +0 -31
  31. data/lib/.rbnext/2.3/yesql/query/transform_result.rb +0 -48
  32. data/lib/.rbnext/2.7/yesql/bindings/extract.rb +0 -71
  33. data/lib/.rbnext/2.7/yesql/bindings/extractor.rb +0 -38
  34. data/lib/.rbnext/2.7/yesql/bindings/transformed.rb +0 -58
  35. data/lib/.rbnext/2.7/yesql/bindings/utils.rb +0 -16
  36. data/lib/.rbnext/2.7/yesql/errors/file_path_does_not_exist_error.rb +0 -43
  37. data/lib/.rbnext/2.7/yesql/errors/no_bindings_provided_error.rb +0 -41
  38. data/lib/.rbnext/2.7/yesql/query/transform_result.rb +0 -48
  39. data/lib/.rbnext/2.7/yesql/statement.rb +0 -44
  40. data/lib/.rbnext/2.7/yesql/utils/read.rb +0 -20
  41. data/lib/.rbnext/3.0/yesql/bindings/extract.rb +0 -71
  42. data/lib/.rbnext/3.0/yesql/bindings/transformed.rb +0 -58
  43. data/lib/.rbnext/3.0/yesql/common/adapter.rb +0 -18
  44. data/lib/.rbnext/3.0/yesql/config/configuration.rb +0 -32
  45. data/lib/.rbnext/3.0/yesql/errors/file_path_does_not_exist_error.rb +0 -43
  46. data/lib/.rbnext/3.0/yesql/errors/no_bindings_provided_error.rb +0 -41
  47. data/lib/.rbnext/3.0/yesql/params/output.rb +0 -26
  48. data/lib/.rbnext/3.0/yesql/query/performer.rb +0 -44
  49. data/lib/.rbnext/3.0/yesql/query/result.rb +0 -41
  50. data/lib/.rbnext/3.0/yesql/query/transform_result.rb +0 -48
  51. data/lib/.rbnext/3.0/yesql/statement.rb +0 -44
  52. data/lib/.rbnext/3.0/yesql/utils/read.rb +0 -20
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yesql"
4
- require "yesql/common/adapter"
5
- require "forwardable"
6
-
7
- module ::YeSQL
8
- module Query
9
- class TransformResult
10
- extend ::Forwardable
11
-
12
- include ::YeSQL::Common::Adapter
13
-
14
- def initialize(output:, result:)
15
- @output = output
16
- @result = result
17
- end
18
-
19
- def call
20
- if rails_5? && mysql?
21
- return columns if columns?
22
- return rows_values if rows?
23
- return array_of_symbol_hashes if hash?
24
- end
25
-
26
- return result.public_send(output.to_sym) if columns? || rows?
27
-
28
- to_a.map(&:symbolize_keys)
29
- end
30
-
31
- private
32
-
33
- attr_reader :output, :result
34
-
35
- def_delegators(:result, :fields, :rows, :to_a)
36
- def_delegators(:output, :columns?, :hash?, :rows?)
37
-
38
- def array_of_symbol_hashes
39
- to_a.tap { break hashed_rows(_1) if rails_5? }.map { _1&.symbolize_keys || _1 }
40
- end
41
-
42
- def columns ; fields || result.columns; end
43
- def rows_values ; to_a.map { _1.respond_to?(:values) ? _1.values : _1 }; end
44
- def hashed_rows(rows) ; rows.map { columns.zip(_1).to_h }; end
45
- def rails_5? ; ::ActiveRecord::VERSION::MAJOR == 5; end
46
- end
47
- end
48
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_record"
4
-
5
- require "forwardable"
6
-
7
- require "yesql/utils/read"
8
- require "yesql/bindings/extractor"
9
- require "yesql/common/adapter"
10
-
11
- module ::YeSQL
12
- class Statement
13
- extend ::Forwardable
14
-
15
- include ::YeSQL::Common::Adapter
16
- include ::YeSQL::Utils::Read
17
- # Give access to the quote method.
18
- include ::ActiveRecord::ConnectionAdapters::Quoting
19
-
20
- def initialize(bindings = {}, file_path)
21
- @bindings = bindings
22
- @file_path = file_path
23
- end
24
-
25
- def bound
26
- to_s.gsub(::YeSQL::BIND_REGEX) { extract_bind_values(extractor[_1[/(\w+)/].to_sym]) }
27
- end
28
-
29
- def to_s ; @to_s ||= statement(readable: true); end
30
- def view? ; to_s =~ /^create\s.*view\s/i; end
31
-
32
- private
33
-
34
- attr_reader :bindings, :file_path
35
-
36
- def extract_bind_values(match)
37
- return quote(match[:value]) if view?
38
-
39
- match[:bind][:vars]
40
- end
41
-
42
- def extractor ; @extractor ||= ::YeSQL::Bindings::Extractor.new(bindings: bindings).call; end
43
- end
44
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ::YeSQL
4
- module Utils
5
- module Read
6
- def statement(readable: false) ; read_file(found_file, readable); end
7
-
8
- private
9
-
10
- def read_file(file, readable)
11
- return File.readlines(file, chomp: true).join(" ") if readable == true
12
-
13
- File.read(file)
14
- end
15
-
16
- def found_file ; dir_sql_files.find { _1.include?("#{file_path}.sql") }; end
17
- def dir_sql_files ; Dir["./#{::YeSQL.config.path}/**/*.sql"]; end
18
- end
19
- end
20
- end