This is a very basic setup of a Sinatra app, that already has a model example.
To get started run the following commands:
Install dependencies:
bundle install
Create database:
bundle exec rake db:create
Run migrations to update database schema:
bundle exec rake db:migrate
Whenever you need to update your database (add tables, add columns, etc), you should create a new migration file with the following command:
bundle exec rake db:create_migration NAME=migration_name
migration_name
should be replaced with the name you want to give to the migration file.
Note: This app assumes you have sqlite3.
To run the app we are using shotgun,
which means you can run just by typing shotgun
.
In order to interact with the database you can run
tux, which is an interactive shell for
Sinatra. Start it by typing tux
.
Once in the console, write:
Post.create title: "Some title"
exit