Reputation: 1813
I've tried many random shots in the dark, such as:
config.gateways[:default] = [:sql, database_url, encoding: 'UTF8']
And all variations on UTF8, e.g., utf8, utf-8, unicode, Unicode.
SHOW server_encoding
. SHOW client_encoding
;But when I give ROM non-ASCII, UTF-8 characters to insert, the characters are replaced with '�' somewhere along the way to PostgreSQL.
What is the correct way to setup ROM and use it with UTF-8 characters?
Upvotes: 1
Views: 976
Reputation: 101
Hmm we pass connection options straight to Sequel, then if you specify during connection configuration option like encoding: utf-8 it will work
ROM::Configuration.new(:sql, "postgres://...", { encoding: utf-8 })
require 'rom'
require 'rom-sql'
DATABASE_URL = ENV.fetch('DATABASE_URL', 'postgres://localhost/rom')
setup = ROM::Configuration.new(:sql, DATABASE_URL, encoding: 'unicode')
rom = ROM.container(setup)
conn = setup.default.connection
conn.drop_table?(:users)
conn.create_table :users do
String :name
end
class Users < ROM::Relation[:sql]
end
setup.register_relation(:users)
rom.relations.users.insert(:name => "Pöter")
p rom.relations.users.to_a
Upvotes: 3