0.0
No commit activity in last 3 years
No release in over 3 years
DataMapper plugin providing support for TwoWaySQL.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9.2
~> 1.3.2

Runtime

~> 0.6.0
 Project Readme

DataMapper::TwoWaySQL

DataMapper plugin providing support for TwoWaySQL.

Installation

Add this line to your application's Gemfile:

gem 'dm-twowaysql'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dm-twowaysql

Usage

class PersonGateway
  include DataMapper::TwoWaySQL

  # define twowaysql select
  twowaysql :select, :person_index_page, <<-EOS
    SELECT * FROM people
    /*BEGIN*/WHERE
      /*IF ctx[:name]*/ name = /*ctx[:name]*/'Bob' /*END*/
      /*IF ctx[:job]*/ job = /*ctx[:job]*/'CLERK' /*END*/
      /*IF ctx[:age]*/ AND age > /*ctx[:age]*/30 /*END*/
    /*END*/
    /*IF ctx[:order_by] */ ORDER BY /*$ctx[:order_by]*/id /*$ctx[:order]*/ASC /*END*/
  EOS

  # define twowaysql execute
  twowaysql :execute, :update_all_name, <<-EOS
    UPDATE people SET name = /*ctx[:name]*/'name'
  EOS
end

PersonGateway.template_select_person_index_page # => TwoWaySQL::Template instance
PersonGateway.template_execute_update_all_name  # => TwoWaySQL::Template instance

# merged = PersonGateway.template_select_person_index_page.merge({})
# ::DataMapper.repository(:default).adapter.select(merged.sql, *merged.bound_variables)
PersonGateway.select_person_index_page(:default, {})

# merged = PersonGateway.template_execute_update_all_name.merge({:name => 'jobs'})
# ::DataMapper.repository(:default).adapter.execute(merged.sql, *merged.bound_variables)
PersonGateway.execute_update_all_name(:default, {:name => 'jobs'})

Contributing

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