Skip to content

Commit d14260c

Browse files
committed
chore: update readme docs
1 parent e8c18a7 commit d14260c

File tree

1 file changed

+58
-32
lines changed

1 file changed

+58
-32
lines changed

Readme.md

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ This extension intends to add TypeIDs to the Postgres using [pgrx](https://githu
77
Here's an example of a TypeID of type user:
88

99
```
10-
user_2x4y6z8a0b1c2d3e4f5g6h7j8k
11-
└──┘ └────────────────────────┘
12-
type uuid suffix (base32)
10+
user_2x4y6z8a0b1c2d3e4f5g6h7j8k
11+
└──┘ └────────────────────────┘
12+
type uuid suffix (base32)
1313
```
1414

1515
ID tag converts to `5d278df4-280b-0b04-d1b8-8f2c0d13c913` UUID holding a timestamp which allows to sort it.
@@ -39,53 +39,79 @@ FROM series;
3939

4040
Obviously it adds some overhead because of decoding/ encoding base52 (because the data is stored as UUID) so keep that in mind. But upon testing I don't think the performance implications are very noticable, inserting the 100k records took me around 800ms.
4141

42-
### Installation
43-
Installation should be performed from source.
42+
### Installation/ upgrade
43+
44+
There are multiple ways to use Postgres with TypeID extension:
45+
46+
1) Using pre-built postgres image with TypeID:
47+
48+
```bash
49+
docker pull ghcr.io/blitss/typeid-pg:latest
50+
```
51+
52+
You can see how it's built [here](https://github.com/blitss/typeid-postgres/blob/main/Dockerfile)
53+
54+
2) By using install script and downloading pre-built extension (must have Postgres installed and `pg_config` exposed in path)
55+
56+
```bash
57+
curl -sSL https://github.com/blitss/typeid-postgres/blob/main/install.sh | sudo bash
58+
```
59+
60+
Or you can specify the pg_config directly:
61+
62+
```bash
63+
curl -sSL https://github.com/blitss/typeid-postgres/blob/main/install.sh | sudo bash -s -- /usr/pgsql-16/bin/pg_config
64+
```
65+
66+
You can upgrade the same way and then run `ALTER EXTENSION typeid UPDATE;` in your Postgres database to run migration scripts.
67+
68+
3) By building extension manually
4469

4570
Prerequisites:
46-
* Postgres 11.x-16.x installed (probably from your package manager), including the "-server" package
71+
* Postgres 13.x-17.x installed (probably from your package manager), including the "-server" package
4772

4873
* The Rust toolchain
4974

5075
* A 64bit Intel Architecture
5176

5277
Windows is not supported due to pgrx limitations.
5378

54-
Run these commands (replace pg12 with your pg version and `which pg_config` part with your pg path if necessary):
79+
Run these commands (replace pg13 with your pg version and `which pg_config` part with your pg path if necessary):
5580

5681
```bash
5782
git clone https://github.com/blitss/typeid-postgres-extension.git
5883
cd typeid-postgres-extension
5984
cargo install cargo-pgx
6085

61-
cargo pgx init --pg12=`which pg_config`
62-
cargo pgx install --release
86+
cargo pgx init --pg13=`which pg_config`
87+
cargo pgx install --release --sudo
6388
```
6489

6590
After that use `CREATE EXTENSION typeid` to initialize an extension.
6691

6792
### Exposed functions
6893

69-
```
70-
Schema | Name | Result data type | Argument data types | Type | Volatility | Parallel | Owner | Security | Access privileges | Langu
71-
age | Internal name | Description
72-
--------+------------------+------------------+---------------------+------+------------+----------+-----------+----------+-------------------+------
73-
----+--------------------------+-------------
74-
public | typeid_cmp | integer | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c
75-
| typeid_cmp_wrapper |
76-
public | typeid_eq | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c
77-
| typeid_eq_wrapper |
78-
public | typeid_ge | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c
79-
| typeid_ge_wrapper |
80-
public | typeid_generate | typeid | prefix text | func | volatile | unsafe | codespace | invoker | | c
81-
| typeid_generate_wrapper |
82-
public | typeid_gt | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c
83-
| typeid_gt_wrapper |
84-
public | typeid_in | typeid | input cstring | func | immutable | safe | codespace | invoker | | c | typeid_in_wrapper |
85-
public | typeid_le | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_le_wrapper |
86-
public | typeid_lt | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_lt_wrapper |
87-
public | typeid_ne | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_ne_wrapper |
88-
public | typeid_out | cstring | input typeid | func | immutable | safe | codespace | invoker | | c | typeid_out_wrapper |
89-
public | typeid_uuid_generate_v7 | uuid | | func | volatile | unsafe | codespace | invoker | | c | uuid_generate_v7_wrapper |
90-
(11 rows)
91-
```
94+
| Function | Return Type | Arguments | Description |
95+
|---|---|---|---|
96+
| `typeid_generate(prefix TEXT)` | `typeid` | `prefix TEXT` | Generate a new TypeID using the supplied prefix. The `prefix` must be lowercase ASCII letters, 1–63 chars. |
97+
| `typeid_generate_nil()` | `typeid` | | Generate a new TypeID with an empty prefix. Equivalent to `typeid_generate('')`. |
98+
| `typeid_is_valid(input TEXT)` | `BOOLEAN` | `input TEXT` | Check if a TypeID string is valid without parsing it. |
99+
| `typeid_prefix(typeid)` | `TEXT` | `typeid typeid` | Extract the prefix part from a TypeID. |
100+
| `typeid_to_uuid(typeid)` | `UUID` | `typeid typeid` | Convert a TypeID to a UUID. |
101+
| `uuid_to_typeid(prefix TEXT, uuid UUID)` | `typeid` | `prefix TEXT`, `uuid UUID` | Convert a UUID to a TypeID with a given prefix. |
102+
| `typeid_uuid_generate_v7()` | `UUID` | | Generate a UUID v7. |
103+
| `typeid_has_prefix(typeid, prefix TEXT)` | `BOOLEAN` | `typeid typeid`, `prefix TEXT` | Check if a TypeID has a specific prefix. |
104+
| `typeid_is_nil_prefix(typeid)` | `BOOLEAN` | `typeid typeid` | Check if a TypeID has a nil prefix. |
105+
| `typeid_generate_batch(prefix TEXT, count INTEGER)` | `SETOF typeid` | `prefix TEXT`, `count INTEGER` | Generate a batch of TypeIDs. |
106+
107+
### Exposed Aggregates
108+
109+
| Aggregate | Return Type | Arguments | Description |
110+
|---|---|---|---|
111+
| `min(typeid)` | `typeid` | `typeid` | Returns the minimum TypeID in a group. |
112+
| `max(typeid)` | `typeid` | `typeid` | Returns the maximum TypeID in a group. |
113+
114+
### Exposed Operators
115+
116+
This extension also creates a set of operators (`<`, `<=`, `=`, `>=`, `>`, `<>`) for comparing TypeIDs, and a `@>` operator for checking if a `typeid` has a certain prefix (e.g., `id @> 'user'`).
117+
It also creates a `btree` operator class for indexing TypeIDs.

0 commit comments

Comments
 (0)