Created
August 14, 2019 09:02
-
-
Save devkinoti/8a8e73484355bd954f58e181c2b37292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def self.import(file) | |
| conn = ActiveRecord::Base.connection | |
| rc = conn.raw_connection | |
| rc.exec("COPY callers (your_attributes) FROM STDIN WITH CSV") | |
| file = File.open("#{file.path}", 'r') | |
| while !file.eof? | |
| rc.put_copy_data(file.readline) | |
| end | |
| rc.put_copy_end | |
| while res = rc.get_result | |
| if e_message = res.error_message | |
| p e_message | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment