Giter Club home page Giter Club logo

Comments (9)

danhardman avatar danhardman commented on September 15, 2024 5

Typically, UUIDs are used as a client provided value to reference some unique record. So you'll typically receive it as a string. It makes sense to store it as such to avoid having to do any type conversion

from go.uuid.

danhardman avatar danhardman commented on September 15, 2024

I assume it's just to make it readable when storing it in a database, else you'd be storing it as a blob.

from go.uuid.

danilobuerger avatar danilobuerger commented on September 15, 2024

What if i want to store it as a 16 byte blob instead of a 36 byte string?

from go.uuid.

danilobuerger avatar danilobuerger commented on September 15, 2024

It doesn't really matter how it is received as this library stores it in a 16 byte array. So even if I did receive it as a string from a client, it would then be a 16 byte array after calling FromString.

Point is: I can scan it from either a 16 byte slice, a text byte slice or a string. When valuing it, I should have the same options. If it came from the database as a 16 byte slice, I would assume being able to put it back like that.

from go.uuid.

danhardman avatar danhardman commented on September 15, 2024

Fair point. I was worried manually querying blob data in a MySQL database for example would be fiddly but it seems MySQL will cast strings to binary in queries. Not sure about other databases though...

from go.uuid.

danilobuerger avatar danilobuerger commented on September 15, 2024

Postgres handles this fine as well. You can exec / query with either string or byte array. On the console, it displays the UUID type as a string.

from go.uuid.

satori avatar satori commented on September 15, 2024

@danilobuerger @danhardman See initial discussion in #5
I never tested since if lib/pq supports binary protocol.

from go.uuid.

danilobuerger avatar danilobuerger commented on September 15, 2024

@satori Thanks for the link. Support for binary protocol in lib/pq was added here: lib/pq#357. It is a bit annoying to always call Bytes(). Maybe there is a better solution while providing backward compatibility for people relying on it to be a string?

from go.uuid.

BourgeoisBear avatar BourgeoisBear commented on September 15, 2024

@danilobuerger What is the downside to just rolling your own struct composition and overriding Value()?

from go.uuid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.