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
+30-10Lines changed: 30 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ UPID is based on [ULID](https://github.com/ulid/spec) but with some modification
11
11
The core idea is that a **meaningful prefix** is specified that is stored in a 128-bit UUID-shaped slot.
12
12
Thus a UPID is **human-readable** (like a Stripe ID), but still efficient to store, sort and index.
13
13
14
-
UPID allows a prefix of up to **4 characters** (will be right-padded if shorter than 4), includes a non-wrapping timestamp with about 300 millisecond precision, and 64 bits of entropy.
14
+
UPID allows a prefix of up to **4 characters** (will be right-padded if shorter than 4), includes a non-wrapping timestamp with about 250 millisecond precision, and 64 bits of entropy.
15
15
16
16
This is a UPID in Python:
17
17
```python
@@ -81,7 +81,7 @@ Key changes relative to ULID:
81
81
### Collision
82
82
Relative to ULID, the time precision is reduced from 48 to 40 bits (keeping the most significant bits, so oveflow still won't occur until 10889 AD), and the randomness reduced from 80 to 64 bits.
83
83
84
-
The timestamp precision at 40 bits is around 300 milliseconds. In order to have a 50% probability of collision with 64 bits of randomness, you would need to generate around **4 billion items per 100 millisecond window**.
84
+
The timestamp precision at 40 bits is around 250 milliseconds. In order to have a 50% probability of collision with 64 bits of randomness, you would need to generate around **4 billion items per 250 millisecond window**.
85
85
86
86
## Python implementation
87
87
This aims to be maximally simple to convey the core working of the spec.
@@ -105,11 +105,19 @@ upid("user")
105
105
```
106
106
107
107
#### Development
108
+
Code and tests are in the [py/](./py/) directory. Using [Rye](https://rye.astral.sh/) for development (installation instructions at the link).
109
+
108
110
```bash
111
+
# can be run from the repo root
109
112
rye sync
110
113
rye run all # or fmt/lint/check/test
111
114
```
112
115
116
+
If you just want to have a look around, pip should also work:
117
+
```bash
118
+
pip install -e .
119
+
```
120
+
113
121
## Rust implementation
114
122
The current Rust implementation is based on [dylanhart/ulid-rs](https://github.com/dylanhart/ulid-rs), but using the same lookup base32 lookup method as the Python implementation.
115
123
@@ -125,28 +133,32 @@ Upid::new("user");
125
133
```
126
134
127
135
#### Development
136
+
Code and tests are in the [upid_rs/](./upid_rs/) directory.
137
+
128
138
```bash
129
-
cargo check # or fmt/clippy/test/run
139
+
cd upid_rs
140
+
cargo check # or fmt/clippy/build/test/run
130
141
```
131
142
132
143
## Postgres extension
133
144
There is also a Postgres extension built on the Rust implementation, using [pgrx](https://github.com/pgcentralfoundation/pgrx) and based on the very similar extension [pksunkara/pgx_ulid](https://github.com/pksunkara/pgx_ulid).
134
145
135
146
#### Installation
136
-
You will need to install pgrx and follow its installation instructions.
147
+
You can try out the Docker image [carderne/postgres-upid:16](https://hub.docker.com/r/carderne/postgres-upid):
148
+
```bash
149
+
docker run -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 carderne/postgres-upid:16
150
+
```
151
+
152
+
If you want to install it into another Postgres, you'll install pgrx and follow its [installation instructions](https://github.com/pgcentralfoundation/pgrx/blob/develop/cargo-pgrx/README.md).
137
153
Something like this:
138
154
```bash
139
155
cargo install --locked cargo-pgrx
140
156
pgrx init
141
157
cd upid_pg
142
158
pgrx install
143
-
pgrx run
144
159
```
145
160
146
-
Alternatively, you can try out the Docker image `[carderne/postgres-upid:16](https://hub.docker.com/r/carderne/postgres-upid):
147
-
```bash
148
-
docker run -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 carderne/postgres-upid:16
149
-
```
161
+
Installable binaries will come soon.
150
162
151
163
#### Usage
152
164
```sql
@@ -162,6 +174,14 @@ SELECT * FROM users;
162
174
```
163
175
164
176
#### Development
177
+
Code and tests are in the [upid_pg/](./upid_pg/) directory.
178
+
165
179
```bash
166
-
cargo pgrx test
180
+
cd upid_pg
181
+
cargo check # or fmt/clippy
182
+
183
+
# must test/run/install with pgrx
184
+
# this will compile it into a Postgres installation
185
+
# and run the tests there, or drop you into a psql prompt
0 commit comments