You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's some C to get a timestamp in milliseconds, which is required to generate a UUID7.
Lua's os.time() gives timestamps in seconds, presumably for maximum portability.
Hopefully this is reasonably portable, but if not it's short enough to be reasonably replaced.
Maturity: this was a toy project for me to practice Lua.
It works and has good tests, including passing the TypeID suite.
It's probably not idiomatic Lua.
I've written up some notes on the implementation and alternatives in the announcement blog post.
Use
TypeID=require("typeid")
-- or in dev: TypeID = require("./typeid")t=TypeID.generate("comment")
-- t = {-- prefix = "comment",-- suffix = "01jvbhbbdje07rnyqkvstpvcge"-- }-- TypeID tables implement __tostringprint(t) -- "comment_01jvbhbbdje07rnyqkvstpvcge"-- You can extract a standard UUID stringt:uuid() -- "0196d715-adb2-700f-8afa-f3de756db20e"-- and round trip that back into a TypeIDTypeID.from_uuid_string("comment", "0196d715-adb2-700f-8afa-f3de756db20e")
-- parse and validate a TypeID from a stringTypeID.parse("comment_01jvbhbbdje07rnyqkvstpvcge")
-- finally, you can generate with a unix timestamp in ms:TypeID.generate("comment", 1) -- "comment_0000000001e8avt0nh7a68v2jc"
Build
# build and install
$ luarocks make
# build for development
$ luarocks make --no-install
The rockspec probably does not correctly depend on sys/time.h.
I don't understand why luarocks generated the version 0.1-1, what is the -1 for?
Is my version 0.1 or 0.1-1?
The TypeID spec says "Implementations SHOULD allow encoding/decoding of other UUID variants" but does not mandate validating them, so I don't.
Perhaps the spec should say implementations should not permit any old 128 bits.