https://github.com/begriffs/sinatra-sql
Easy PostgreSQL access with migrations in Sinatra
https://github.com/begriffs/sinatra-sql
Last synced: 5 months ago
JSON representation
Easy PostgreSQL access with migrations in Sinatra
- Host: GitHub
- URL: https://github.com/begriffs/sinatra-sql
- Owner: begriffs
- Created: 2012-06-27T21:45:44.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-08-02T03:25:10.000Z (over 13 years ago)
- Last Synced: 2025-05-29T04:43:45.481Z (10 months ago)
- Language: Ruby
- Homepage:
- Size: 116 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 `sql` function 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
1. clone this repo
1. `bundle`
1. copy `db/config.rb.example` to `db/config.rb`
1. edit it and provide database configuration parameters
1. `rake db:create`
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
1. `rake migration`
1. it creates db/_timestamp_.up.sql and db/_timestamp_.down.sql
1. edit these files to (un)do whatever you want
### Running a migration
Running `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.'
### Executing queries
In your application code use the `sql` function. For an example
look in `app.rb`.
## Contributing
This library would be more flexible as a gem. If anyone wants to
help, your pull requests are welcome.