Skip to content

Instantly share code, notes, and snippets.

@lkfken
Last active July 25, 2016 01:18
Show Gist options
  • Save lkfken/a18e388a9c007a71e082cac328dab3b6 to your computer and use it in GitHub Desktop.
Save lkfken/a18e388a9c007a71e082cac328dab3b6 to your computer and use it in GitHub Desktop.
Convert CSV to Sqlite records.
require 'sequel'
require 'csv'
csv_records = CSV.read('records.csv')
DB = Sequel.connect('jdbc:sqlite::memory:')
DB.create_table(:records) do
Integer :id, :primary_key => true
String :member_id, :null => false
String :lob, :null => false
String :region, :null => false
Date :region_eff, :null => false #Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
String :pcp, :null => false
Date :pcp_eff, :null => false #Sequel.string_to_date('2010-09-10') # Date.civil(2010, 09, 10)
end
DB[:records].import([:member_id, :lob, :region, :region_eff, :pcp, :pcp_eff], csv_records)
p DB[:records].all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment