Chapter 3. Tutorial

Table of Contents

Create a configuration file
Create a table, and corresponding domain class
Create, update, and delete Users
Create a new user and save it to the database
Retrieve a user and change some values
Delete the user
Add methods to the User class
Record an association between Users and Messages
Query Users

Create a configuration file

Configurations in Lafcadio are set in-Ruby, as opposed to an external file with YAML or XML. If you want to swap out different configurations, it's easy enough to do so by requiring different Ruby files.

For this tutorial we'll create a single Ruby file called tutorial_setup.rb. Here's what it should look like to start:

require     'rubygems'
require_gem 'lafcadio'

  'dbuser' => 'test',
  'dbpassword' => 'password',
  'dbname' => 'test',
  'dbhost' => 'localhost'

Of course, if you're not using Rubygems you should just replace the first two lines with "require 'lafcadio'".

You can test this configuration with:

% ruby -e "require 'tutorial_setup'; Lafcadio::ObjectStore.get_object_store"