Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

xlgmokha/humble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Humble

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

Add this line to your application's Gemfile:

gem 'humble'

And then execute:

$ bundle

Or install it yourself as:

$ gem install humble

Usage

Let's say you have a class called Movie.

  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.

  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.

  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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages