dwyl / abase

:house: A (solid) Base for your Web Application.
9 stars 0 forks source link

Unique Column values #54

Open jrans opened 7 years ago

jrans commented 7 years ago

Some properties need to be unique in database like username and email. Provide ability to set those fields in config and initialise table with those constraints on the columns

nelsonic commented 7 years ago

@jrans we won't know the field needs to be unique (during validation) until the DB replies with the constraint, so this is for table creation, right? also, have you decided on using individual as the key? https://github.com/dwyl/abase/pull/55#discussion_r81135409 why not unique ? (would be good to have this decision documented somewhere...) understood that Joi already has a unique() method for Array: https://github.com/hapijs/joi/blob/v9.0.4/API.md#arrayuniquecomparator but does it apply to string or numeric values?

jrans commented 7 years ago

@nelsonic agreed unique is much nicer than individual and also realise only for array. Was just being super safe I guess if in future we handled arrays (what would unique constraint even mean then?)

Also more importantly adopting an attitude that you never add clashing methods is a good one to stop any nasty bugs occurring with joi-creation but I can imagine our handling of methods will get slightly more sophisticated by then.

Since we are not handling arrays right now (error if try to configure with one) we can safely use unique, I will change. But good we talked about this!