Open chriskilding opened 10 years ago
The thing is, I don't have a JRuby env to test the gem, but I believe it could work with a JDBC adapter and some tweaks in the code. Beware that I use some methods of the pg raw interface, that's why there is a dependency. But If you want to do this and send me a PR I'll gladly merge it ;)
Not able to do a full PR for you at this time, but here's some code that Worked For Me:
require 'java'
require "jdbc/postgres"
...
# Ensure you are using absolute path for safety
path = File.expand_path [some path], __FILE__
# Load DB driver
Jdbc::Postgres.load_driver
# Load the JDBC underlying connection
connection = [some model].connection.jdbc_connection
# Invoke some Java to let us use the COPY command
# not allowed to do that normally by the JDBC driver.
copier = org.postgresql.copy.CopyManager.new(connection)
istream = java.io.FileInputStream.new path
copier.copyIn("COPY [pluralised lower case model name] FROM STDIN WITH (FORMAT CSV, HEADER TRUE, DELIMITER ',')", istream)
If you want to have a crack at integrating this into the gem, setting up a jruby env is trivial - rbenv install jruby-[version]
will do, the rvm equivalent is probably also a one-liner.
@themasterchef I am doing copier.copyIn("\copy order_transactions TO '/tmp/foo.csv' DELIMITER E'\t' CSV HEADER")
but getting following error:
Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near ""
JRuby support will require some major refactoring. The current code is too brittle to accept different database drivers.
The interface could also receive some love (I would drop the acts_as
pattern and pass the model as a dependency).
I see that the test cases are a valuable thing that could be shared between a common gem for MRI and JRuby.
Having said that I'll reopen the issue as a possible enhancement.
If you are reading this thread and would like to see this gem supporting jruby please add a 👍 reaction to this comment.
When I tried to use this gem on Jruby 1.7.10 I got the following error, basically it looks like this gem has a hard requirement on the MRI / cruby 'pg' gem at the moment. Could this be fixed to support running on Jruby?