Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code for basic use of models? #162

Open
jjb opened this issue Feb 1, 2021 · 0 comments
Open

Example code for basic use of models? #162

jjb opened this issue Feb 1, 2021 · 0 comments

Comments

@jjb
Copy link
Contributor

jjb commented Feb 1, 2021

Thanks for this great project!

I've started tinkering with it and I can't seem to come up with the basic code needed to use ActiveRecord models.

Running migrations, creating database and tables, and generating schema.rb all went smoothly. Then, this code fails:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: postredis_development
require 'active_record'

def db_configuration
  db_configuration_file = File.join(File.expand_path('..', __FILE__), '..', 'db', 'config.yml')
  YAML.load(File.read(db_configuration_file))
end

ActiveRecord::Base.establish_connection(db_configuration["development"])

require_relative '../models/my_model.rb'
MyModel.first
# pause...
# ActiveRecord::ConnectionTimeoutError (could not obtain a connection from the pool within 5.000 seconds (waited 5.001 seconds); all pooled connections were in use)

If discussion here comes up with some recommendations I'll make a PR for the readme.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant