rom-rb

rom-rb related notes.

commands

delete

lib/persistence/repositories/users.rb:

module Persistence::Repositories
  class Users < Base[:users]
    commands :create, update: :by_pk, delete: :by_pk
    relations :google_adwords_configs

    ...
  end
end

all custom delete methods below are defined inside repository. probably this is a wrong way - create a separate command for each case with a single entry point (#execute(tuple)). see https://github.com/icelab/berg/tree/master/lib/persistence/commands for examples.

delete by id

use generated delete method in repository:

users_repo.delete(user_id)

delete all

call delete on relation:

module Persistence::Repositories
  class Users < Base[:users]
    def delete_all
      users.delete
    end
  end
end

delete with condition

get required relation view before calling delete:

module Persistence::Repositories
  class Users < Base[:users]
    def delete_by_email email
      users.by_email(email).delete
    end
  end
end