Hey! I’m trying to experiment with Rom-rb and have dry-system
+ rom-rb
application.
I have users
repository:
# frozen_string_literal: true
require 'persistence/repositories/root'
require 'persistence/entities/user'
module Persistence
module Repositories
class Users < Root[:users]
struct_namespace Persistence::Entities
end
end
end
and the parent repository is:
# frozen_string_literal: true
module Persistence
module Repositories
class Root < ROM::Repository::Root
include Import['persistence.container']
end
end
end
For some reason, when I’m trying to enable timestamps in :create
command in Users
repository — it’s working. But specifying it the same way in Root repository only creates :create
command, but timestamps are not working.
The code which is working:
module Persistence
module Repositories
class Users < Root[:users]
struct_namespace Persistence::Entities
commands :create, use: :timestamps, plugins_options: {
timestamps: {
timestamps: %i[created_at updated_at]
}
}
end
end
end
The code which is not working:
# frozen_string_literal: true
module Persistence
module Repositories
class Root < ROM::Repository::Root
include Import['persistence.container']
commands :create, use: :timestamps, plugins_options: {
timestamps: {
timestamps: %i[created_at updated_at]
}
}
end
end
end
And, given documentation is suggesting the use changeset
s instead of commands: What is the best way to achieve timestamps now?
It looks weird, defining create method in each repository with:
def create(params)
users_repo.users.changeset(:create, params).map(:add_timestamps).commit
end