wesionaryTEAM

Visionary Development Team. We ❤︎ Technology!

Follow publication

Implementation of UUID and binary(16) in gorm v2.

Dipesh KC
wesionaryTEAM
Published in
4 min readNov 27, 2020

--

Pros of using UUID instead of AUTO_INCREMENT PRIMARY KEY?

Cons of using UUID:

Let's start our demonstration

go get -u gorm.io/gorm
go get -u gorm.io/driver/mysql
go get -u github.com/google/uuid

Problem

Implementing Customized Data Type

Model

Database

Adding New Post in Database

BeforeCreate Hook

Final Main Program

Table `posts`

Table `comments`

CONCLUSION

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response