Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable valuer interface #155

Open
oliy opened this issue Sep 29, 2021 · 1 comment
Open

Configurable valuer interface #155

oliy opened this issue Sep 29, 2021 · 1 comment

Comments

@oliy
Copy link

oliy commented Sep 29, 2021

In my application, I actually don't want sql.Valuer to be expanding my values, since I have a struct that expands to a JSON object in the DB. When I run validations, this means that it's validating against the JSON string and not the actual object. I'd like to be able to turn off this translation. Even better would be a way to pass in the interface or function that is able to convert specific validation objects.

oliy added a commit to oliy/ozzo-validation that referenced this issue Sep 29, 2021
@Thearas
Copy link

Thearas commented Dec 18, 2021

Hi @oliy, I met the same problem as you.
Currently, the Indirect() works on all the type who implements driver.Valuer. This doesn't make much sense, I mean sometimes, the output of driver.Valuer.Value() is what we write directly to DB, but not for validation, right?

e.g.

type MySice []MyStruct

func (s MySice) Value() (driver.Value, error) {
	return json.Marshal(s)
}

type Foo struct {
    MySice
}

// This will serialize `MySice` into JSON and get error on `validation.Length(1, 3)`.
validation.ValidateStruct(foo, validation.Field(&foo.MySice, validation.Length(1, 3)))

Would you like to give us some advice? @qiangxue

Thearas added a commit to Thearas/ozzo-validation that referenced this issue Dec 19, 2021
Thearas added a commit to Thearas/ozzo-validation that referenced this issue Dec 20, 2021
Thearas added a commit to Thearas/ozzo-validation that referenced this issue Dec 20, 2021
Thearas added a commit to Thearas/ozzo-validation that referenced this issue Dec 20, 2021
oliy added a commit to oliy/ozzo-validation that referenced this issue Jan 20, 2022
swithek pushed a commit to jellydator/validation that referenced this issue Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants