Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
iCyberon committed Apr 9, 2017
1 parent 98d0311 commit 8c3029f
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,53 @@ Then in a psql session issue:
CREATE extension pg_hashids;


Update
============

Install as usual.

make; sudo make install

Then in a psql session issue:

ALTER EXTENSION pg_hashids UPDATE;

or

DROP EXTENSION pg_hashids;
CREATE EXTENSION pg_hashids;

Check

SELECT default_version, installed_version FROM pg_available_extensions WHERE name = 'pg_hashids';


Usage
============
#### Encoding
Returns a hash using the default `alphabet` and empty `salt`.

SELECT hash_encode(1001); -- Result: jNl
SELECT id_encode(1001); -- Result: jNl

Returns a hash using the default `alphabet` and supplied `salt`.

SELECT hash_encode(1234567, 'This is my salt'); -- Result: Pdzxp
SELECT id_encode(1234567, 'This is my salt'); -- Result: Pdzxp

Returns a hash using the default `alphabet`, `salt` and minimum hash length.

SELECT hash_encode(1234567, 'This is my salt', 10); -- Result: PlRPdzxpR7
SELECT id_encode(1234567, 'This is my salt', 10); -- Result: PlRPdzxpR7


Returns a hash using the supplied `alphabet`, `salt` and minimum hash length.

SELECT id_encode(1234567, 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890'); -- Result: 3GJ956J9B9

#### Decoding
You can also decode previouslt generated hashes. Just use the same `salt`, otherwise you'll get wrong results.

SELECT hash_decode('PlRPdzxpR7', 'This is my salt', 10);
SELECT id_decode('PlRPdzxpR7', 'This is my salt', 10); -- Result: 1234567

Using a custom alphabet

SELECT id_decode('3GJ956J9B9', 'This is my salt', 10, 'abcdefghijABCDxFGHIJ1234567890'); -- Result: 1234567

0 comments on commit 8c3029f

Please sign in to comment.