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

New custom ColumnType, why only StringColumnType is Open #149

Closed
chmuche opened this issue Sep 3, 2017 · 3 comments
Closed

New custom ColumnType, why only StringColumnType is Open #149

chmuche opened this issue Sep 3, 2017 · 3 comments

Comments

@chmuche
Copy link

chmuche commented Sep 3, 2017

Follow your advice inside the #148

I don't understand why StringColumnType is Open but not DateColumnType or the other.

My goal is to add validity constraint before the insert/update.

Like the Jsr303

For the Date I want to add before: LocalDate, after:LocalDate, defaultValue:LocalDate

And I don't want to copy past all the code inside DateColumnType

I think to exentends IColumnType and add a DateColumnType inside MyCustomDateColumnType

@Tapac
Copy link
Contributor

Tapac commented Sep 3, 2017

I think to exentends IColumnType and add a DateColumnType inside MyCustomDateColumnType

That's a right way! Try to use kotlin delegation (https://kotlinlang.org/docs/reference/delegation.html)

class ValidatedDateTime(val before: LocalDate, val after: LocalDate, val defaultValue: LocalDate,
                        private val timeColType: DateColumnType = DateColumnType(true)) : IColumnType by timeColType {
    override fun valueToDB(value: Any?): Any? {
        assert(value != null) // Your validation here
        return timeColType.valueToDB(value)
    }
}

@chmuche
Copy link
Author

chmuche commented Sep 3, 2017

Ok, it's exactly the code I write. But why StringColumnType is open ?
It's just to know you made this choice.
Any way thanks for the quick answer.

@Tapac
Copy link
Contributor

Tapac commented Sep 8, 2017

But why StringColumnType is open ?

StringColumnType has two inheritors in Exposed code, so it was easier to make it open instead of using delegates.

@Tapac Tapac closed this as completed Sep 8, 2017
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