Skip to content

Instantly share code, notes, and snippets.

@tdolsen
Last active April 1, 2023 03:06
Show Gist options
  • Save tdolsen/cac959ae70e91c841ae8d24ec4129360 to your computer and use it in GitHub Desktop.
Save tdolsen/cac959ae70e91c841ae8d24ec4129360 to your computer and use it in GitHub Desktop.
EdgeDB custom scalars

EdgeDB custom scalars

A small collection of custom scalars for EdgeDB, ensuring valid values going into the database.

scalar type bcrypt_hash_str extending str {
annotation description := "A valid bcrypt hash string.";
constraint regexp(r"^\$2[ayb]?\$[0-9]{2}\$.{53}$");
}
scalar type email_str extending str {
annotation description := "Valid email address according to the W3C specification for input[type=email].";
constraint regexp(r"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$");
}
scalar type locale_str extending str {
annotation description := "Locale identifier string, formatted as xx_YY. (xx = country, YY = dialect)";
constraint regexp(r"^[a-z]{2}_[A-Z]{2}$");
}
scalar type phone_number_str extending str {
annotation description := "String representing a phone number, formatted according to E.164.";
constraint regexp(r"^\+?[1-9]\d{1,14}$");
}
scalar type trimmed_str extending str {
annotation description := "A string with no leading or trailing whitespace.";
constraint expression on ( __subject__ = str_trim(__subject__) );
}
scalar type uuid_str extending str {
annotation description := "A valid UUID string.";
constraint regexp(r"^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment