-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mark functions as immutable #3
base: main
Are you sure you want to change the base?
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 aGENERATED
column, 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.shuffle
sqids.checkAlphabet
sqids.toId
sqids.toNumber
sqids.encodeNumbers
sqids.decode
sqids.encode
(both versions)sqids.isBlockedId
sqids.defaultBlocklist
The tests included with the repo all pass locally on my machine with these changes.