db2_query 0.3.6 → 0.3.8

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: 3e06666a1eee58811d081a1d8da67e2d3e814d91ef15a0c12bb5b306ee130aed
4
- data.tar.gz: fa7ebb35a4e9019f9619416ed4c97fa410e663d3eb58b9320314002e759c501e
3
+ metadata.gz: 9eabc77ee406196782e5a07a95a7e821d169ec98b865443c7c7450f337d09d5e
4
+ data.tar.gz: 84089fa859c9777a38d3b8698b4789993b5769fcc13d6ba093202d68cd9f6456
5
5
  SHA512:
6
- metadata.gz: b538e762bf70e00782cc09eb56151c0db034dd13e7b757e8261c27e0e2caafbcd7da70b21a310d8881fe2072e3fd9d56fa072c3499fcd14ab7db97dbac24a2ce
7
- data.tar.gz: c507ee06457bd6d84e6232ee5bb900cad7dc26249281fab2bb80e04382ea1f5aafd03a6fe182c056ac997176e33b8236bf587207638c1901ddaef694b53bc7a7
6
+ metadata.gz: e83b1e40ff7e6e949657aadbdedebdbd106f8ddb6f5143fee15b94b655b4c7306a80025d5884c81b3d0a1092ac058241c2c9cd0092318dec131a863567b7b5d8
7
+ data.tar.gz: 6d1c87212f770d85f5657744b7ddbca5d6b09e3ff903b227651f6b33915a586bbf5ce7ac00924923bae13a024434b219dae606a65deaebe4ff857e5d84f8153d
@@ -1,4 +1,9 @@
1
1
  module Db2Query
2
2
  class Railtie < ::Rails::Railtie
3
+ rake_tasks do
4
+ load "tasks/init.rake"
5
+ load "tasks/database.rake"
6
+ load "tasks/initializer.rake"
7
+ end
3
8
  end
4
9
  end
@@ -12,7 +12,7 @@ module Db2Query
12
12
  end
13
13
 
14
14
  class DatabaseTask < Tasks
15
- source_root File.expand_path("../tasks/templates", __FILE__)
15
+ source_root File.expand_path("../../tasks/templates", __FILE__)
16
16
 
17
17
  def create_database_config_file
18
18
  template "database.rb", File.join("config/db2query.yml")
@@ -20,7 +20,7 @@ module Db2Query
20
20
  end
21
21
 
22
22
  class InitializerTask < Tasks
23
- source_root File.expand_path("../tasks/templates", __FILE__)
23
+ source_root File.expand_path("../../tasks/templates", __FILE__)
24
24
 
25
25
  def create_initializer_file
26
26
  template "initializer.rb", File.join("config/initializers/db2query.rb")
@@ -1,3 +1,3 @@
1
1
  module Db2Query
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.8"
3
3
  end
data/lib/db2_query.rb CHANGED
@@ -3,6 +3,7 @@ require "db2_query/railtie"
3
3
  require "connection_pool"
4
4
  require "odbc_utf8"
5
5
  require "db2_query/error"
6
+ require "db2_query/tasks"
6
7
 
7
8
  module Db2Query
8
9
  # Your code goes here...
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Stubs out a new query. Pass the query name, either
3
+ CamelCased or under_scored, and an optional list of its methods as arguments.
4
+
5
+ To create a query within a module, just use namespace pattern as the other rails generators do.
6
+
7
+ To create query class methods, you can use 3 options:
8
+ 1. Plain SQL methods --defines
9
+ 2. Query Methods with SQL string, --queries
10
+ 3. Query Methods with lambda, --lambdas
11
+
12
+ Example:
13
+ $ rails g query NameSpace::Name --queries query_1 --defines query_2 --lambdas query_3
14
+ create app/queries/name_space/name_query.rb
15
+ create test/queries/name_space/name_query_test.rb
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "fileutils"
5
+
6
+ module Rails
7
+ module Generators
8
+ class QueryGenerator < Rails::Generators::NamedBase
9
+ source_root File.expand_path("../templates", __FILE__)
10
+
11
+ class_option :skip_unit_test, type: :boolean, default: false, desc: "Skip unit test file creation"
12
+ class_option :defines, type: :array, default: [], desc: "Plain query method options"
13
+ class_option :queries, type: :array, default: [], desc: "Query method SQL options"
14
+ class_option :lambdas, type: :array, default: [], desc: "Query method with callable args"
15
+
16
+ def create_query_file
17
+ template "query.rb", File.join("app/queries", class_path, "#{file_name}_query.rb")
18
+ end
19
+
20
+ def create_query_definitions_file
21
+ template "query_definitions.rb", File.join("app/queries/definitions", class_path, "#{file_name}_query_definitions.rb")
22
+ end
23
+
24
+ def create_query_test_file
25
+ unless options[:skip_unit_test]
26
+ template "unit_test.rb", File.join("test/queries", class_path, "#{file_name}_query_test.rb")
27
+ end
28
+ end
29
+
30
+ private
31
+ def assign_names!(name)
32
+ super(name)
33
+ @method_options = options.slice("defines", "queries", "lambdas")
34
+ @query_methods = @method_options.map { |key, val| val }.flatten
35
+ end
36
+
37
+ def query_class_name
38
+ "#{file_name.camelize}Query"
39
+ end
40
+
41
+ def namespaced_query?
42
+ !class_path.empty?
43
+ end
44
+
45
+ def namespaced_names
46
+ class_path
47
+ end
48
+
49
+ def namespaced_content(content)
50
+ namespaced_names.reverse_each do |namespace_name|
51
+ content = "module #{namespace_name.camelize}\n#{indent(content)}\nend"
52
+ end
53
+ content
54
+ end
55
+
56
+ def module_namespacing(&block)
57
+ content = capture(&block)
58
+ content = namespaced_content(content) if namespaced_query?
59
+ concat(content)
60
+ end
61
+
62
+ def module_definitions_namespacing(&block)
63
+ content = capture(&block)
64
+ content = namespaced_content(content) if namespaced_query?
65
+ definitions_namespace_content = "module Definitions\n#{indent(content)}\nend"
66
+ concat(definitions_namespace_content)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= query_class_name %> < <%= "Db2Query::Base" -%>
5
+ <% if @query_methods.empty? %>
6
+ <%= indent("query :to_do, <<-SQL\n") %>
7
+ <%= indent("SQL\n") %>
8
+ <%= indent("def to_do_sql\n") %>
9
+ <%= indent("end") %>
10
+ <% end -%>
11
+ <% @method_options.each do |key, val| -%>
12
+ <% val.each_with_index do |option, index| -%>
13
+ <% case key when 'defines' -%>
14
+ <%= indent("def #{option}_sql\n") %>
15
+ <%= indent("end") %>
16
+ <% when 'queries' %>
17
+ <%= indent("query :#{option}, <<-SQL\n") %>
18
+ <%= indent("SQL") %>
19
+ <% when 'lambdas' %>
20
+ <%= indent("query :#{option}, -> args {\n") %>
21
+ <%= indent("}") %>
22
+ <% end -%>
23
+ <% end -%>
24
+ <% end -%>
25
+ <%= 'end' -%>
26
+ <% end %>
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% module_definitions_namespacing do -%>
4
+ class <%= query_class_name %>Definitions < <%= "Db2Query::Definitions" %>
5
+ <% if @query_methods.empty? %>
6
+ <%= indent("def describe\n") -%>
7
+ <%= indent("") %>
8
+ <%= indent("end") %>
9
+ <% else %>
10
+ <%= indent("def describe") -%>
11
+ <% @query_methods.each do |method| %>
12
+ <%= indent("query_definition :#{method} do |c|\n") %>
13
+ <%= indent("end") %>
14
+ <% end -%>
15
+ <%= indent("end") %>
16
+ <% end %>
17
+ <%= 'end' -%>
18
+ <% end %>
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= query_class_name %>Test < ActiveSupport::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ <%= 'end' -%>
9
+ <% end %>
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "db2_query/tasks"
4
+
5
+ namespace :db2query do
6
+ desc "Create Database configuration file"
7
+ task :database do
8
+ Db2Query::DatabaseTask.generate_file
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :db2query do
4
+ desc "Create Initializer and Database configuration file"
5
+ task :init do
6
+ Rake::Task["db2query:database"].invoke
7
+ Rake::Task["db2query:initializer"].invoke
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "db2_query/tasks"
4
+
5
+ namespace :db2query do
6
+ desc "Create Initializer file"
7
+ task :initializer do
8
+ Db2Query::InitializerTask.generate_file
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ development:
4
+ dsn: TODO
5
+ idle: 5
6
+ pool: 5
7
+ timeout: 5
8
+
9
+ test:
10
+ dsn: TODO
11
+ idle: 5
12
+ pool: 5
13
+ timeout: 5
14
+
15
+ production:
16
+ dsn: TODO
17
+ idle: 5
18
+ pool: 5
19
+ timeout: 5
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "db2_query"
4
+
5
+ Db2Query::Base.initiation do |base|
6
+ base.set_field_types
7
+ base.establish_connection
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db2_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yohanes Lumentut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-04 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -125,7 +125,16 @@ files:
125
125
  - lib/db2_query/type/timestamp.rb
126
126
  - lib/db2_query/type/value.rb
127
127
  - lib/db2_query/version.rb
128
- - lib/tasks/db2_query_tasks.rake
128
+ - lib/generators/query/USAGE
129
+ - lib/generators/query/query_generator.rb
130
+ - lib/generators/query/templates/query.rb.tt
131
+ - lib/generators/query/templates/query_definitions.rb.tt
132
+ - lib/generators/query/templates/unit_test.rb.tt
133
+ - lib/tasks/database.rake
134
+ - lib/tasks/init.rake
135
+ - lib/tasks/initializer.rake
136
+ - lib/tasks/templates/database.rb.tt
137
+ - lib/tasks/templates/initializer.rb.tt
129
138
  homepage: https://github.com/yohaneslumentut/db2_query
130
139
  licenses:
131
140
  - MIT
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :db2_query do
3
- # # Task goes here
4
- # end