Conversation
421196a to
222675a
Compare
|
Only two functions fail the sqids.defaultBlocklist()
sqids.isBlockedId(id TEXT)All other immutable functions pass the tests. |
6e0b27e to
9acb313
Compare
|
@kryptus36 @4kimov any thing you guys want me to change, or fundamental deficits in this PR? |
|
Thanks @cereum I've just started looking into whether to adopt this library into one of my projects and noticed immutability was lacking, so appreciate this PR. Technically if SELECT sqids.encode(ARRAY[1], 'abc'); -- Returns 'aa'
INSERT INTO sqids.blocklist (str) VALUES ('aa'), ('bb');
SELECT sqids.encode(ARRAY[1], 'abc'); -- Returns 'cc'So pragmatically speaking I'd prefer to leave things like |
These are all fair. One thing that I can think of is having a "static blocklist" version of encode in the library. Like you said I think that the venn diagram of people who need the blocklist to be dynamic is small. |
When using the output of
squids.encode(...)in aGENERATEDcolumn, postgres was complaining that the functions needs to be immutable.From the postgres documentation:
TL;DR Functions marked as IMMUTABLE always return the same output for the same input and do not depend on any external state. Non-IMMUTABLE functions may depend on database state or have side effects.
Accordingly, I've marked the following functions as follows:
sqids.shufflesqids.checkAlphabetsqids.toIdsqids.toNumbersqids.encodeNumberssqids.decodesqids.encode(both versions)sqids.isBlockedIdsqids.defaultBlocklistThe tests included with the repo all pass locally on my machine with these changes.