module Interro::Validations
Overview
Validate inputs to your queries before saving the values to the database.
Since QueryBuilder
includes Validations
, it allows you to reference
Result
and Failure
by their shorthand names.
struct UserQuery < Interro::QueryBuilder(User)
def create(*, name : String, email : String, team : Team, role : User::Role)
Result(User).new
.validate_presence(name: name, email: email)
.validate_uniqueness("email") { where(email: email).any? }
.valid do
insert(
name: name,
email: email,
team_id: team.id,
role: role.value,
)
end
end
end