Class: CsvToSqlite::SQL::CreateTable
- Inherits:
-
Object
- Object
- CsvToSqlite::SQL::CreateTable
- Defined in:
- lib/sql/create_table.rb
Instance Method Summary collapse
- #columns ⇒ Object
- #create_statement ⇒ Object
-
#initialize(name:, csv_table:, connection:) ⇒ CreateTable
constructor
A new instance of CreateTable.
- #run ⇒ Object
- #sql ⇒ Object
Constructor Details
#initialize(name:, csv_table:, connection:) ⇒ CreateTable
Returns a new instance of CreateTable.
8 9 10 11 12 |
# File 'lib/sql/create_table.rb', line 8 def initialize name:, csv_table:, connection: @connection = connection @name = name @csv_table = csv_table end |
Instance Method Details
#columns ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/sql/create_table.rb', line 28 def columns @column_generator = CsvToSqlite::SQL::Column.new(csv_table: @csv_table) columns_sql = @csv_table.headers.map do |column| @column_generator.sql_for column end columns_sql.join.chop end |
#create_statement ⇒ Object
24 25 26 |
# File 'lib/sql/create_table.rb', line 24 def create_statement "CREATE TABLE IF NOT EXISTS #{@name}" end |
#run ⇒ Object
14 15 16 17 18 |
# File 'lib/sql/create_table.rb', line 14 def run puts "========== Creating table #{@name} ==========" @connection.execute sql puts "==================================================" end |
#sql ⇒ Object
20 21 22 |
# File 'lib/sql/create_table.rb', line 20 def sql "#{create_statement} ( #{columns} );" end |