Moved to otr-activerecord
jhollinger / grape-activerecord Goto Github PK
View Code? Open in Web Editor NEWSimple ActiveRecord integration for Grape apps
License: MIT License
Simple ActiveRecord integration for Grape apps
License: MIT License
Moved to otr-activerecord
When I require the "grape/activerecord/rake" file the app wont start anymore. This is the error:
.../gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:3:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)
Rake tasks do actually work, so could use them by just only enabling the lines when I need migration tasks, but its nicer if I can always have the tasks available.
Note to self: Fix by using app.after_validation
, app.after
, and app.rescue_from :all
.
Our project uses ENVied to refer to database host, username, etc. in the config/database.yml
file, so we need to have loaded ENVied before loading active_record and connecting to the database. This project's README suggests putting such application loading in a rake task db:environment
. This would load fine if our database config was located somewhere else, but since it's in config/database.yml
your defaults.rb
file calls database_file=
before this environment task is executed, which fails because ENVied hasn't loaded yet.
It would be preferable if grape-activerecord didn't set the database file until the end of the database environment task, so that if any setup is required in order for activerecord to use the database file it can be performed there.
ActiveRecord config loader:
Grape::ActiveRecord.database_file = File.join(__dir__, '..', 'config', 'database.yml')
database.yml:
development:
adapter: postgresql
host: 192.168.7.16
encoding: unicode
username: postgres
password: secret
database: app_development
pool: 10
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
host: 192.168.7.16
encoding: unicode
username: postgres
password: secret
database: app_test
pool: 10
production:
adapter: postgresql
host: 192.168.7.16
encoding: unicode
username: postgres
password: secret
database: app_production
pool: 10
Then when I test it with:
ab -c 10 -n 1000 http://192.168.7.10/users
It opens exactly 20 connections to PostgreSQL:
tcp 0 139 192.168.7.16:postgresql 192.168.7.10:39666 ESTABLISHED
tcp 0 0 192.168.7.16:postgresql 192.168.7.10:39658 ESTABLISHED
tcp 0 0 192.168.7.16:postgresql 192.168.7.10:39664 ESTABLISHED
tcp 0 0 192.168.7.16:postgresql 192.168.7.10:39662 ESTABLISHED
...
The same if I make pool: 2
or pool: 70
.
Hi, Thanks for writing this gem. I've come across this issue:
Using grape-activerecord 0.0.8
Using activerecord 4.2.3
When I follow the README and include Grape::ActiveRecord::Extension
in my Grape API class I get the following error:
undefined method 'downcase' for 2:Fixnum
Ruby /home/vagrant/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rack-1.6.4/lib/rack/utils.rb: in [], line 501
Looking into that code there are just these two lines:
Grape::ActiveRecord.setup!
app.use ::ActiveRecord::ConnectionAdapters::ConnectionManagement
When I remove the include Grape::ActiveRecord::Extension
from the API class and replace it with just Grape::ActiveRecord.setup!
it works fine.
Following your README I have put in config.ru use ActiveRecord::ConnectionAdapters::ConnectionManagement
I played around with removing the use from config.ru since it seems redundant when including the mixin, but that didn't remove the error. any idea?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.