You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+58-32Lines changed: 58 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ This extension intends to add TypeIDs to the Postgres using [pgrx](https://githu
7
7
Here's an example of a TypeID of type user:
8
8
9
9
```
10
-
user_2x4y6z8a0b1c2d3e4f5g6h7j8k
11
-
└──┘ └────────────────────────┘
12
-
type uuid suffix (base32)
10
+
user_2x4y6z8a0b1c2d3e4f5g6h7j8k
11
+
└──┘ └────────────────────────┘
12
+
type uuid suffix (base32)
13
13
```
14
14
15
15
ID tag converts to `5d278df4-280b-0b04-d1b8-8f2c0d13c913` UUID holding a timestamp which allows to sort it.
@@ -39,53 +39,79 @@ FROM series;
39
39
40
40
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.
41
41
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)
| 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