Commit a65715c
Changed files (1)
README.md
@@ -1,6 +1,10 @@
# Humble
-TODO: Write a gem description
+I really miss working with NHibernate. The ruby world has many very
+popular orms such as ActiveRecord, DataMapper and DataMappify.
+
+This is my attempt at building a light weight ORM with heavy influences from NHibernate.
+It is a work in progress and not ready for production.
## Installation
@@ -18,7 +22,55 @@ Or install it yourself as:
## Usage
-TODO: Write usage instructions here
+Let's say you have a class called Movie.
+
+```ruby
+
+ class Movie
+ attr_reader :id, :name
+
+ def initialize(attributes)
+ @id = attributes[:id] || -1
+ @name = attributes[:name]
+ end
+ end
+
+```
+
+This is how you would define the mapping to the database.
+
+```ruby
+
+ class MovieMapping < Humble::DatabaseMapping
+ def run(map)
+ map.table :movies
+ map.type Movie
+ map.primary_key(:id, default: -1)
+ map.column :name
+ end
+ end
+
+```
+
+To connect to the database you need a session.
+
+```ruby
+
+ configuration = Humble::Configuration.new('sqlite://movies.db')
+ configuration.add(MovieMapping.new)
+ session_factory = configuration.build_session_factory
+
+ session = session_factory.create_session
+ session.begin_transaction do |session|
+ session.save(Movie.new(:name => 'Man on Fire')
+ end
+
+ all_movies = session.find_all(Movie)
+ all_movies.each do |movie|
+ session.delete(movie)
+ end
+
+```
## Contributing