feat: update uuid

main
sudo pacman -Syu 2024-06-25 17:33:22 +07:00
parent c667d2a126
commit 807196cc5e
2 changed files with 74 additions and 40 deletions

View File

@ -112,15 +112,15 @@
syntax from MySQL, and PostgreSQL and so on. Every logic I can move to syntax from MySQL, and PostgreSQL and so on. Every logic I can move to
application layer from database layer, I will. application layer from database layer, I will.
</p> </p>
<p> <p>The ID must be sortable (because index) and unique.</p>
In the past and present, I use <strong>google/uuid</strong>, specificially <p>I have 3 choices:</p>
I use UUID v4. In the future I will look to use <ul>
<strong>segmentio/ksuid</strong> and <strong>oklog/ulid</strong> (trial <li><strong>google/uuid</strong>: use UUID v7 not v4.</li>
and error of course). Both are sortable, but <li>
<strong>google/uuid</strong> is not. The reason I'm afraid because the <strong>segmentio/ksuid</strong>: handle error if you don't want panic.
database is sensitive subject, and I need more testing and battle test </li>
proof to trust those libs. <li><strong>oklog/ulid</strong>: don't use yet.</li>
</p> </ul>
<div class="markdown-heading"> <div class="markdown-heading">
<h2 class="heading-element">What else?</h2> <h2 class="heading-element">What else?</h2>
<a <a
@ -135,6 +135,7 @@
I think about adding prefix to ID to identify which resource that ID I think about adding prefix to ID to identify which resource that ID
represents. represents.
</p> </p>
<p>For example: <code>user:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</code>.</p>
<div class="markdown-heading"> <div class="markdown-heading">
<h2 class="heading-element">Thanks</h2> <h2 class="heading-element">Thanks</h2>
<a <a
@ -147,41 +148,67 @@
</div> </div>
<ul> <ul>
<li> <li>
<a <p>
href="https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/" <a href="https://datatracker.ietf.org/doc/html/rfc9562" rel="nofollow"
rel="nofollow" >Universally Unique IDentifiers (UUIDs)</a
>UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED >
PRIMARY KEYS?</a </p>
>
</li> </li>
<li> <li>
<a href="https://brandur.org/nanoglyphs/026-ids" rel="nofollow" <p>
>Identity Crisis: Sequence v. UUID as Primary Key</a <a href="https://0pointer.net/blog/projects/ids.html" rel="nofollow"
> >On IDs</a
>
</p>
</li> </li>
<li> <li>
<a <p>
href="https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html" <a
rel="nofollow" href="https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/"
>Generating good unique ids in Go</a rel="nofollow"
> >UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED
PRIMARY KEYS?</a
>
</p>
</li> </li>
<li> <li>
<a <p>
href="https://encore.dev/blog/go-1.18-generic-identifiers" <a href="https://brandur.org/nanoglyphs/026-ids" rel="nofollow"
rel="nofollow" >Identity Crisis: Sequence v. UUID as Primary Key</a
>How we used Go 1.18 when designing our Identifiers</a >
> </p>
</li> </li>
<li> <li>
<a href="https://blog.daveallie.com/ulid-primary-keys" rel="nofollow" <p>
>ULIDs and Primary Keys</a <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>
<li> <li>
<a href="https://0pointer.net/blog/projects/ids.html" rel="nofollow" <p>
>On IDs</a <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>
<p>
<a href="https://blog.daveallie.com/ulid-primary-keys" rel="nofollow"
>ULIDs and Primary Keys</a
>
</p>
</li>
<li>
<p>
<a href="https://antonz.org/uuidv7/" rel="nofollow"
>UUIDv7 in 32 languages</a
>
</p>
</li> </li>
</ul> </ul>

View File

@ -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 MySQL, and PostgreSQL and so on. Every logic I can move to application layer
from database layer, I will. from database layer, I will.
In the past and present, I use **google/uuid**, specificially I use UUID v4. In The ID must be sortable (because index) and unique.
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 I have 3 choices:
afraid because the database is sensitive subject, and I need more testing and
battle test proof to trust those libs. - **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? ## What else?
I think about adding prefix to ID to identify which resource that ID represents. I think about adding prefix to ID to identify which resource that ID represents.
For example: `user:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX`.
## Thanks ## 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/) - [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) - [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) - [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) - [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) - [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/)