for more information visit the package's GitHub page
Package contains the following modules:
Generates a new key between two keys.
If you want to insert new record between B and C,
|id|sort_key| |:--|:--| |A|1| |B|2| |C|3| |D|4|
This library gives you a new key 21
.
|id|sort_key| |:--|:--| |A|1| |B|2| |E|21| |C|3| |D|4|
This can be useful, when you use RDB and change the order without rearranging all of the rows.
import InsertableKey exposing (Key, after, before, between, init)
generateThreeKeys : Maybe ( Key, Key, Key )
generateThreeKeys =
let
left =
init
in
after left
|> Maybe.andThen
(\right ->
between left right
|> Maybe.map
(\center ->
( left, center, right )
)
)
0-9A-Za-z
(62 chars), but the last charactor must not be 0
.1
.between "1" "3" == Just "2"
between "1" "2" == Just "11"
between "1" "11" == Just "101"
after "1" == Just "2"
after "z" == Just "z1"
This works well at least for my use case, but there should be better algorithm to do this.
z
is z1
, and the key after zz
is zz1
. This means simply incrementing key until N
results in the key length N / 62
. So the length is 16
when we have 1000 rows and 160
when we have 10000. Considering UUID is 36 chars, N = 2000
would be a good limit.11
, 101
, 1001
, 10001
... 100000000001
. I think this should be fixed if a key is chosen which is placed near the center of two keys.If you have some information about this problem, please let me know. Forking and publishing your own is also welcome!
BSD-3-Clause