Coder Social home page Coder Social logo

hanami-sequel's Introduction

Hanami::Sequel

This gem is designed to replace the hanami-model one in your Hanami project. It adds an equivalent set of database commands to the hanami executable, and generates Sequel models.

Please note that using this gem could be considered bad practice with regards to Hanami’s architectural goals, as it does not provide any help to separate the model into entities and repositories. On the other hand, it does nothing to prevent it either.

Installation

Follow the instructions for removing hanami-model: Use Your Own ORM

Add this line to your config/environment.rb:

require "hamani/sequel/model"

Add this line to your application’s Gemfile (adding the gem to the plugins group ensures that the hanami executable is correctly extended):

group :plugins do
  gem 'hanami-sequel', '~> 1.1.0'
end

And then execute:

$ bundle

Versioning

This gem’s version is based on the major and minor versions of Hanami. For hanami-X.Y.Z, use hanami-sequel-X.Y.P. This gem’s patch version (denoted as P) is independent from Hanami’s patch version (denoted as Z).

Configuration

As of now, the paths to migrations and models are hardcoded respectively to db/migrations/ and lib/#{project_name}/models/.

Usage

All the commands start with the sequel argument:

Commands:
  hanami sequel create
  hanami sequel drop
  hanami sequel install
  hanami sequel migrate [VERSION]
  hanami sequel migration NAME
  hanami sequel model NAME
  hanami sequel seed

Create a database table

$ hanami sequel model NAME

Where NAME is the name of the model. This creates a database migration, a Sequel model and a spec file. Additionally, a Sequel spec helper file will be created if none exists.

Create a database migration

$ hanami sequel migration NAME

Where NAME is an arbitrary name.

Create the database

$ hanami sequel create

This command will fail in the production environment.

Migrate the database

$ hanami sequel migrate [VERSION]

Where VERSION can be:

  • "up" (default value), to do all the migrations, i.e. hanami sequel migrate or hanami sequel migrate up.
  • "down", to undo all the migrations, i.e. hanami sequel migrate down.
  • a timestamp, representing the first part of the target migration file. E.g. hanami sequel migrate 20180201153930 to migrate to the database version as of 1st February 2018 at 15:39:30 (if a migration file starting with this value is found).

Seed the database

$ hanami sequel seed

This command will look up your models for Hanami:Sequel:Seed class methods used to import constants into your tables. If an error occurs, the whole seed operation will be rolled back.

Drop the database

$ hanami sequel drop

This command will fail in the production environment.

Install the database

$ hanami sequel install

This command drops, creates, migrates, then seeds your database. It will fail in the production environment.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Known issues / To-do list

  • hardcoded configuration values
  • no tests

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/malin-as/hanami-sequel.

hanami-sequel's People

Contributors

elbouillon avatar malin-as avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.