Skip to content

Commit

Permalink
feat: update uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
haunt98 committed Jun 25, 2024
1 parent c667d2a commit 807196c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 40 deletions.
95 changes: 61 additions & 34 deletions docs/2022-07-12-uuid-or-else.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ <h2 class="heading-element">
syntax from MySQL, and PostgreSQL and so on. Every logic I can move to
application layer from database layer, I will.
</p>
<p>
In the past and present, I use <strong>google/uuid</strong>, specificially
I use UUID v4. In the future I will look to use
<strong>segmentio/ksuid</strong> and <strong>oklog/ulid</strong> (trial
and error of course). Both are sortable, but
<strong>google/uuid</strong> is not. The reason I'm afraid because the
database is sensitive subject, and I need more testing and battle test
proof to trust those libs.
</p>
<p>The ID must be sortable (because index) and unique.</p>
<p>I have 3 choices:</p>
<ul>
<li><strong>google/uuid</strong>: use UUID v7 not v4.</li>
<li>
<strong>segmentio/ksuid</strong>: handle error if you don't want panic.
</li>
<li><strong>oklog/ulid</strong>: don't use yet.</li>
</ul>
<div class="markdown-heading">
<h2 class="heading-element">What else?</h2>
<a
Expand All @@ -135,6 +135,7 @@ <h2 class="heading-element">What else?</h2>
I think about adding prefix to ID to identify which resource that ID
represents.
</p>
<p>For example: <code>user:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</code>.</p>
<div class="markdown-heading">
<h2 class="heading-element">Thanks</h2>
<a
Expand All @@ -147,41 +148,67 @@ <h2 class="heading-element">Thanks</h2>
</div>
<ul>
<li>
<a
href="https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/"
rel="nofollow"
>UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED
PRIMARY KEYS?</a
>
<p>
<a href="https://datatracker.ietf.org/doc/html/rfc9562" rel="nofollow"
>Universally Unique IDentifiers (UUIDs)</a
>
</p>
</li>
<li>
<p>
<a href="https://0pointer.net/blog/projects/ids.html" rel="nofollow"
>On IDs</a
>
</p>
</li>
<li>
<p>
<a
href="https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/"
rel="nofollow"
>UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED
PRIMARY KEYS?</a
>
</p>
</li>
<li>
<a href="https://brandur.org/nanoglyphs/026-ids" rel="nofollow"
>Identity Crisis: Sequence v. UUID as Primary Key</a
>
<p>
<a href="https://brandur.org/nanoglyphs/026-ids" rel="nofollow"
>Identity Crisis: Sequence v. UUID as Primary Key</a
>
</p>
</li>
<li>
<a
href="https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html"
rel="nofollow"
>Generating good unique ids in Go</a
>
<p>
<a
href="https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html"
rel="nofollow"
>Generating good unique ids in Go</a
>
</p>
</li>
<li>
<a
href="https://encore.dev/blog/go-1.18-generic-identifiers"
rel="nofollow"
>How we used Go 1.18 when designing our Identifiers</a
>
<p>
<a
href="https://encore.dev/blog/go-1.18-generic-identifiers"
rel="nofollow"
>How we used Go 1.18 when designing our Identifiers</a
>
</p>
</li>
<li>
<a href="https://blog.daveallie.com/ulid-primary-keys" rel="nofollow"
>ULIDs and Primary Keys</a
>
<p>
<a href="https://blog.daveallie.com/ulid-primary-keys" rel="nofollow"
>ULIDs and Primary Keys</a
>
</p>
</li>
<li>
<a href="https://0pointer.net/blog/projects/ids.html" rel="nofollow"
>On IDs</a
>
<p>
<a href="https://antonz.org/uuidv7/" rel="nofollow"
>UUIDv7 in 32 languages</a
>
</p>
</li>
</ul>

Expand Down
19 changes: 13 additions & 6 deletions posts/2022-07-12-uuid-or-else.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ don't want to write database specific SQL. SQLite has some different syntax from
MySQL, and PostgreSQL and so on. Every logic I can move to application layer
from database layer, I will.

In the past and present, I use **google/uuid**, specificially I use UUID v4. In
the future I will look to use **segmentio/ksuid** and **oklog/ulid** (trial and
error of course). Both are sortable, but **google/uuid** is not. The reason I'm
afraid because the database is sensitive subject, and I need more testing and
battle test proof to trust those libs.
The ID must be sortable (because index) and unique.

I have 3 choices:

- **google/uuid**: use UUID v7 not v4.
- **segmentio/ksuid**: handle error if you don't want panic.
- **oklog/ulid**: don't use yet.

## What else?

I think about adding prefix to ID to identify which resource that ID represents.

For example: `user:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX`.

## Thanks

- [Universally Unique IDentifiers (UUIDs)](https://datatracker.ietf.org/doc/html/rfc9562)
- [On IDs](https://0pointer.net/blog/projects/ids.html)

- [UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED PRIMARY KEYS?](https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/)
- [Identity Crisis: Sequence v. UUID as Primary Key](https://brandur.org/nanoglyphs/026-ids)
- [Generating good unique ids in Go](https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html)
- [How we used Go 1.18 when designing our Identifiers](https://encore.dev/blog/go-1.18-generic-identifiers)
- [ULIDs and Primary Keys](https://blog.daveallie.com/ulid-primary-keys)
- [On IDs](https://0pointer.net/blog/projects/ids.html)
- [UUIDv7 in 32 languages](https://antonz.org/uuidv7/)

0 comments on commit 807196c

Please sign in to comment.