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
Copy file name to clipboardexpand all lines: lib/once.ex
+84-45
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,14 @@
1
1
defmoduleOncedo
2
2
@format_docs"""
3
-
- `:encoded` a url64-encoded string of 11 characters, for example `"AAjhfZyAAAE"`
3
+
- `:url64` a url64-encoded string of 11 characters, for example `"AAjhfZyAAAE"`
4
+
- `:hex` a hex-encoded string of 16 characters, for example `"E010831058218A39"`
4
5
- `:raw` a bitstring of 64 bits, for example `<<0, 8, 225, 125, 156, 128, 0, 2>>`
5
6
- `:signed` a signed 64-bits integer, like `-12345`, between -(2^63) and 2^63-1
6
7
- `:unsigned` an unsigned 64-bits integer, like `67890`, between 0 and 2^64-1
7
8
"""
8
9
@options_docs"""
9
10
- `:no_noncense` name of the NoNoncense instance used to generate new IDs (default `Once`)
10
-
- `:ex_format` what an ID looks like in Elixir, one of `t:format/0` (default `:encoded`)
11
+
- `:ex_format` what an ID looks like in Elixir, one of `t:format/0` (default `:url64`)
11
12
- `:db_format` what an ID looks like in your database, one of `t:format/0` (default `:signed`)
12
13
- `:encrypt?` enable for encrypted nonces (default `false`)
13
14
- `:get_key` a zero-arity getter for the 192-bits encryption key, required if encryption is enabled
@@ -54,8 +55,9 @@ defmodule Once do
54
55
<<255, 255, 255, 255, 255, 255, 255, 255>>
55
56
"__________8"
56
57
18_446_744_073_709_551_615
58
+
"FFFFFFFFFFFFFFFF"
57
59
58
-
If you use the defaults `:encoded` as the Elixir format and `:signed` in your database, you could see `"AAAAAACYloA"` in Elixir and `10_000_000` in your database. The reasoning behind these defaults is that the encoded format is readable, short, and JSON safe by default, while the signed format means you can use a standard bigint column type.
60
+
If you use the defaults `:url64` as the Elixir format and `:signed` in your database, you could see `"AAAAAACYloA"` in Elixir and `10_000_000` in your database. The reasoning behind these defaults is that the encoded format is readable, short, and JSON safe by default, while the signed format means you can use a standard bigint column type.
59
61
60
62
The negative integers will not cause problems with Postgres and MySQL, they both happily swallow them. Also, negative integers will only start to appear after ~70 years of usage.
0 commit comments