How do I use the activerecord gem with Redis?
I see all these examples with models and Redis but I keep getting a "not connected" error when I try to use them..
ActiveRecord does not know how to speak to Redis, only to SQL databases.
To use redis here is a list of gems you can use:
If you want to use redis directly (I think you should): redis-rb
If you really want an ORM: redis-objects
Related
My application used to query an Oracle database through a classical OCI connection string such as 'user/password#server/database'.
But the server architecture has changed so that connections should now go through LDAP for security reasons. The URL looks like this :
jdbc:oracle:thin:#ldap://intranet.oid-01.dama.ch:3063/EDWHPD,cn=OracleContext,dc=emea,dc=dama,dc=ch
I don't know how to handle this, and it raises several questions for me:
Would the old DBI gem be relevant here?
Should I use the Net-LDAP gem, and what would it bring to help establishing the connection to oracle?
Do you know a tutorial explaining how to handle this type of database access?
Thank you for your help!
It does not appear the ruby based sequel toolkit (currently at v4.32.0 I believe) supports the JSON datatype which mysql introduced with v5.7. Can somebody confirm that is true and suggests workarounds for migrations and queries? Also whether there are plans to introduce it.
Sequel doesn't currently support MySQL's JSON type.
There aren't any near-future plans to implement support for it, though something like a mysql_json extension should be fairly easy to support on the MySQL adapter. The mysql2 adapter would be trickier as it does all of its own typecasting.
I would like to use ActiveRecord in a project without Rails.
I would also like to specify the database connections in config/database.yml like Rails does.
There is already one answer how multiple database connections work with Rails.
ActiveRecord talk to two databases?
I was unsuccessful using this approach and I'm not sure why. I only get the error message "database configuration does not specify adapter".
Is there some kind of magic in Rails that reads the database.yml that is not in ActiveRecord?
I could read it myself but then I don't know how to feed it to ActiveRecord so that I can use establish_connection in each model.
I found out how it works. You just fill the ActiveRecord::Base.configurations hash and then it works.
http://apidock.com/rails/ActiveRecord/Base/configurations/class
I was making a web app to deploy using Heroku.com when I realized that the only database type they support is PostgreSQL. Up until now, my app (powered by the Ruby gem Sinatra) accessed the database via the .Sqlite method for the Sequel gem.
Here's my Ruby script from when I used Sequel to access the .db file via SQLite:
DB = Sequel.sqlite('mydatabase.db')
DB.create_table :mytable do
primary_key :id
String :column_name
end
I installed PostgreSQL after learning Heroku used only that. Here's the script via postgres (my username is literally 'postgress', though I obviously won't reveal my password in this question):
DB = Sequel.postgres('mydatabase.db',:user=>'postgres',:password=>'my_password_here',:host=>'localhost',:port=>5432,:max_connections=>10)
DB.create_table :mytable do
primary_key :id
String :column_name
end
However, when I run this code, I get the following error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:208:in 'initialize': PG::Error: FATAL: database "mydatabase.db" does not exist (Sequel::DatabaseConnectionError)
I've tried searching Google, StackOverflow, Sequel documents, and the Heroku help documents for any help, but I've found no fix to this problem.
Does anyone know what I am doing wrong?
The database mydatabase.db doesn't exist, as per the error message from Pg. Likely reasons:
You probably meant mydatabase without the SQLite-specific .db filename suffix
It's possible you created the db with different case, eg "Mydatabase.db";
You might be connecting to a different Pg server than you think you are
You never created the database. Unlke SQLite's default behaviour, Pg doesn't create databases when you try to connect to a database that doesn't exist yet.
If in doubt, connect to Pg with psql and run \l to list databases, or connect via PgAdmin-III.
The PostgreSQL documentation and tutorial are highly recommended, too. They're well written and will teach you a lot about SQL in general as well as Pg in particular.
BTW, the postgres user is a superuser. You should not be using it for your application; it's like running your server as root, ie a really bad idea. Create a new PostgreSQL user without superuser, createdb or createuser rights and use that for your application. You can either CREATE DATABASE somedb WITH OWNER myappuser - or preferably, create the database owned by a different user to your webapp user and then expicitly GRANT the webapp user the minimum required permissions. See user management and GRANT.
On heroku all you need to do is tell Sequel to connect to the content of the DATABASE_URL environment variable (which is a properly formed url that Sequel understands):
DB = Sequel.connect(ENV['DATABASE_URL'])
I know that for mysql em-mysql exists as an asynchronous interface driver to MySQL and that Active Record, with some modification, can make immediate use of. I believe Sequel has this capability already. I also understand that the pg gem exposes PostgreSQL's native async API.
My question: is there any Ruby ORM that natively interoperates with EventMachine when the backing database is PostgreSQL? If not, what needs to be done to retrofit Sequel to support async PostgreSQL? ActiveRecord?
This looks like it works with ActiveRecord:
https://github.com/mperham/em_postgresql