mysql - Arel in SQLite and other databases -


i new in databases , ruby on rails applications.

i have question generating queries orm.

when database sqlite, , using code creating queries database, if change database still able use same code?

in addition, when using arel, because provides more ready methods more complex queries, before generating query call method .to_sql if want use same code database still able execute query? using instead of to_sql else?

in general, ruby on rails code portable between databases without doing more adjusting config/database.yml file (for connection details) , updating gemfile (to use correct database adapter gem).

database portability when not rely on specific, hardcoded uses of sql way invoke queries. instead use rails' associations, relations, , query tools wherever possible. specific sql creeps in on .where() clauses, thoughtful there , minimize/simply as practical (for instance, multiple simple scopes can chained may give better results trying larger more complex single scopes). use arel.matches when depending on "like" type clauses instead of hardcoding details in .where() calls because different databases (such postgresql) handle case-sensitivity differently.

your best defense against surprises upon switching databases robust set of automated unit (e.g., rspec, minitest) , integration tests (e.g., capybera). these important unable avoid use of specific sql coding (say optimization or odd/complex queries).

since sqlite simpler other robust engines mysql or postgres, you're safer anyway in operations depend on. you're vulnerable when using advanced or specific feature of database, you're more aware if you're doing that, can write protective tests warn upon switching database engines.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -