Quick Start » Connecting to existing database
This article assumes:
- You have a database called
my_db
- There's a table called
users
withname
column - You have the
rom
androm-sql
gems installed
To connect to your database and define a repository for users
table, simply do:
require "rom"
rom = ROM.container(:sql, 'postgres://localhost/my_db', username: 'user', password: 'secret') do |config|
config.relation(:users) do
schema(infer: true)
auto_struct true
end
end
users = rom.relations[:users]
users.changeset(:create, name: "Jane").commit
jane = users.where(name: "Jane").one