Hello @amirouche
Your understanding of this library is a replacement for tuple.pack
and tuple.unpack
is correct. The combination of these methods is called encoder. There are key encoder and value encoder for the foundationdb
library. The msgpack described in the readme serve the purpose of the value encoder in which you can replace with any other value encoder. (Side note: msgpack-lite
encoding by default is not lexicographically sorted.) My library is best used as key encoder.
By default, the key is ordered in following order;
asc - null
asc - false
asc - true
asc - NaN
asc - number
asc - string
asc - array
asc - object
asc - undefined
desc - undefined
desc - object
desc - array
desc - string
desc - number
desc - NaN
desc - true
desc - false
desc - null
and you can change the collation order by changing the CustomCode
prefix value as shown below;
import {
BooleanCollator,
ComplexCollator,
NumberCollator,
StringCollator
} from "@couchplus/collator";
const CustomCode = { /** Custom order **/ };
const collator = new ComplexCollator(CustomCode);
collator.register(new BooleanCollator(CustomCode));
collator.register(new NumberCollator(CustomCode));
collator.register(new StringCollator(CustomCode));
For CustomCode
configuration, please refers to https://github.com/couchplus/collator/blob/master/source/DefaultCode.ts
The library does not currently supports Uint8Array
as key but I do have plan to support spatial data as part of the key type in the future. Though as a workaround, maybe you can use my library at certain key space and use the default binary encoding at the key space where you requires spatial index
Yes, currently my library have it’s own byte encoding.
As for the explanation for mixed order data, given I want use a list/array as key, the catch is, I want to order the first element of the array in ascending order but I want to order the second element in descending order, I can do that as follow;
transaction.set([collator.order.asc(first), collator.order.desc(second)], value);
The resulting order inside the database will be as follows;
["abc", 5]
["abc", 4]
["abc", 3]
["abc", 2]
["abc", 1]
["def", 10]
["def", 9]
["def", 8]
["def", 7]
["def", 6]
note: the above is lexicographically sorted. means, you will get the benefit of range scan while ordering element in an array in mixed order.
Thank you for your attention at my library, feel free to ask me anything.