dylang / shortid

Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
https://www.npmjs.org/package/shortid
Other
5.74k stars 258 forks source link

Use short ID for SQL table names. #152

Closed ashoksahoo closed 4 years ago

ashoksahoo commented 4 years ago

I want something which satisfies this for generating a temporary table name, for a specific ETL operation id. I can replace the dash with a dollar and keep generating until it satisfies the Rule-1 and also maybe a check for rule 5.

Can we get a config where we can set these kinds of rules?

Standard SQL identifiers adhere to a set of rules and must:

  • Begin with an an ASCII single-byte alphabetic character or underscore character, or a UTF-8 multibyte character two to four bytes long.
  • Subsequent characters can be ASCII single-byte alphanumeric characters, underscores, or dollar signs, or UTF-8 multibyte characters two to four bytes long.
  • Be between 1 and 127 bytes in length, not including quotes for delimited identifiers.
  • Contain no quotation marks and no spaces.
  • Not be a reserved SQL key word.
ai commented 4 years ago

Don’t use shortid. It has an architecture problem and does not maintain anymore. Switch to Nano ID.

For table names, switch alphabet to alphabetic character (A…Z) or underscore character. I recommend to add some prefix to avoid using reserved SQL key word.