Class: CsvImportAnalyzer::SqlQueryBuilder
- Inherits:
-
Object
- Object
- CsvImportAnalyzer::SqlQueryBuilder
- Defined in:
- lib/csv-import-analyzer/sql_query_builder.rb
Instance Attribute Summary collapse
-
#create_query ⇒ Object
Returns the value of attribute create_query.
-
#csv_column_datatypes ⇒ Object
Returns the value of attribute csv_column_datatypes.
-
#import_query ⇒ Object
Returns the value of attribute import_query.
-
#min_max_bounds ⇒ Object
Returns the value of attribute min_max_bounds.
-
#nullable ⇒ Object
Returns the value of attribute nullable.
-
#sql_helper_options ⇒ Object
Returns the value of attribute sql_helper_options.
Instance Method Summary collapse
- #databases ⇒ Object
- #delimiter ⇒ Object
- #filename ⇒ Object
-
#generate_query ⇒ Object
Goes through each of the columns datatypes and prepares SQL statements for 1.
-
#initialize(args) ⇒ SqlQueryBuilder
constructor
Since Building SQL is dependent on multiple things, decided to go with an arguments hash that gets passed when creating an object for the class.
- #mysql_helper ⇒ Object
- #options ⇒ Object
- #pg_helper ⇒ Object
- #tablename ⇒ Object
Constructor Details
#initialize(args) ⇒ SqlQueryBuilder
Since Building SQL is dependent on multiple things, decided to go with an arguments hash that gets passed when creating an object for the class
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 13 def initialize(args) @options = args @create_query = {} @import_query = {} @csv_column_datatypes = args[:csv_column_datatypes] @nullable = args[:nullable] @sql_helper_options = {:tablename => tablename, :filename => @options[:filename], :delimiter => @options[:delimiter]} @mysql_helper.extend(CsvImportAnalyzer::MysqlQueryHelper) @pg_helper.extend(CsvImportAnalyzer::PgQueryHelper) end |
Instance Attribute Details
#create_query ⇒ Object
Returns the value of attribute create_query.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def create_query @create_query end |
#csv_column_datatypes ⇒ Object
Returns the value of attribute csv_column_datatypes.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def csv_column_datatypes @csv_column_datatypes end |
#import_query ⇒ Object
Returns the value of attribute import_query.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def import_query @import_query end |
#min_max_bounds ⇒ Object
Returns the value of attribute min_max_bounds.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def min_max_bounds @min_max_bounds end |
#nullable ⇒ Object
Returns the value of attribute nullable.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def nullable @nullable end |
#sql_helper_options ⇒ Object
Returns the value of attribute sql_helper_options.
7 8 9 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 7 def @sql_helper_options end |
Instance Method Details
#databases ⇒ Object
28 29 30 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 28 def databases [:database] end |
#delimiter ⇒ Object
45 46 47 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 45 def delimiter [:delimiter] end |
#filename ⇒ Object
32 33 34 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 32 def filename return [:filename] end |
#generate_query ⇒ Object
Goes through each of the columns datatypes and prepares SQL statements for
1. Importing CSV files to database
2. Create table schema for the files
Makes a function call to return the metadata analysis of the file
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 63 def generate_query databases.each do |db| create_query[db] = ["create table #{tablename} ("] end csv_column_datatypes.each do |header, datatype| append_to_query = build_query_for_datatype(header, datatype) append_to_query.each do |key, value| create_query[key].push(value) end end prepare_sql_statements prepare_import_csv end |
#mysql_helper ⇒ Object
49 50 51 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 49 def mysql_helper @mysql_helper end |
#options ⇒ Object
24 25 26 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 24 def @options end |
#pg_helper ⇒ Object
53 54 55 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 53 def pg_helper @pg_helper end |
#tablename ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/csv-import-analyzer/sql_query_builder.rb', line 36 def tablename # May be optimize this, not run all three operations everytime filename method is called ?? # May be creating filename as instance variable and using a double pipe will relive it from running everytime doesn't it?? tablename = File.basename([:filename]) tablename.gsub!(" ", "_") tablename.downcase! return tablename end |