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

[Proposal] type sizes in diesel schema #1713

Closed
trsh opened this Issue May 22, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@trsh

trsh commented May 22, 2018

In my application (REST, GraphQL, etc.) I want field restrictions being closely tighten up with DB field restrictions. For example, if a DB field is Varchar(100), then my application should also push restriction of 100 symbols for a input, that will be stored in this field.

Right now I have to control this manually. If I change DB field size restriction via migrations, I have to remember also to change restrictions in my application.

Solution. let the generated Schema include also sizes:

table! {
    constants (id) {
        id -> Varchar(20),
        created_at -> Timestamp,
        updated_at -> Nullable<Timestamp>,
        .....
    }
}

And let this size be accessible via .dsl::id.size() (orsmth like that).

@sgrif

This comment has been minimized.

Member

sgrif commented May 22, 2018

Thanks, but this isn't something I want to have Diesel care about or try to enforce right now. This is no different than other forms of constraints. You can just as easily have an arbitrary check constraint that we have no way of handling. Additionally, we have no way to try and enforce this at compile time. There's no type that represents a fixed length string in Rust.

@sgrif sgrif closed this May 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment