9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/generators/kweerie/kweerie_generator.rb', line 9
def create_query_file
bind_statements = parameters.map.with_index(1) do |param, index|
" bind :#{param.underscore}, as: '$#{index}'"
end.join("\n")
template_content = " # frozen_string_literal: true\n\n class \#{class_name} < Kweerie::Base\n \#{bind_statements}\n end\n RUBY\n\n # Ensure the queries directory exists\n FileUtils.mkdir_p(\"app/queries\")\n\n # Create the Ruby file\n create_file \"\#{default_path}/\#{file_name}.rb\", template_content\n\n # Create the SQL file\n create_file \"\#{default_path}/\#{file_name}.sql\", <<~SQL\n -- Write your SQL query here\n -- Available parameters: \#{parameters.map { |p| \"$\#{parameters.index(p) + 1} (\#{p})\" }.join(\", \")}\n\n -- SELECT\n -- your columns here\n -- FROM\n -- your tables here\n -- WHERE\n -- your conditions here\n SQL\nend\n"
|