Postgres access in Sinatra without an ORM
This is a Sinatra application template that provides lightweight SQL-only analogues to Rails' database features.
- configure separate databases for each Rack environment
- maintain versioned migrations (in raw SQL)
- easy access to
sqlfunction in app code to run queries
This template is for competent Postgres users who don't want an object relational mapper getting between them and their sweet, sweet SQL.
How to use
- clone this repo
- edit it and provide database configuration parameters
The database is now ready, and at schema version 0. If you run the application at this point, it will simply output this schema number.
Creating a migration
- it creates db/timestamp.up.sql and db/timestamp.down.sql
- edit these files to (un)do whatever you want
Running a migration
rake db:migrate[version, environment] will execute the
necessary up/down migration sql files to end up at the version
specified. If none is specified, i.e.
rake db:migrate, it will
default to the newest. The environment defaults to 'development.'
In your application code use the
sql function. For an example
This library would be more flexible as a gem. If anyone wants to help, your pull requests are welcome.