Created
November 28, 2020 07:07
-
-
Save hieuk09/11feb1ef50061ef74ce5c5168e4fc0d9 to your computer and use it in GitHub Desktop.
ROM auto_struct does not respect struct configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rom' | |
require 'rom-repository' | |
rom = ROM.container(:sql, 'sqlite::memory') do |conf| | |
conf.default.create_table(:users) do | |
primary_key :id | |
column :name, String, null: false | |
end | |
class Users < ROM::Relation[:sql] | |
schema(infer: true) | |
end | |
conf.register_relation(Users) | |
end | |
module Types | |
include Dry.Types() | |
UpcaseString = Types::String.constructor { |input| input.upcase } | |
end | |
module Entities | |
class User < ROM::Struct | |
attribute :name, Types::UpcaseString | |
end | |
end | |
class UserRepo < ROM::Repository[:users] | |
commands :create | |
struct_namespace Entities | |
end | |
repo = UserRepo.new(container: rom) | |
user_1 = repo.create(name: 'abc') | |
user_2 = repo.users.where(id: 1).map_to(Entities::User).first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment