gofr-dev / gofr

An opinionated GoLang framework for accelerated microservice development. Built in support for databases and observability.
https://gofr.dev
Apache License 2.0
3.6k stars 236 forks source link

Support uuid in AddRestHandler #1187

Closed aryanmehrotra closed 1 week ago

aryanmehrotra commented 1 week ago

When a struct has fields of type int, string, bool those are supported for operations, we need to support uuid type as well.

coolwednesday commented 1 week ago

@aryanmehrotra, The uuid.UUID type can be used, but to ensure compatibility with the database, the id field should be defined as a CHAR(36) or VARCHAR(36) data type while creating table schema in database, rather than an INT, since UUIDs are stored as 36-character strings. Here is an example :

Defined type :

type User struct {
    Id         uuid.UUID `json:"id"`           // CHAR(36) or VARCHAR(36) in SQL
    Name       string    `json:"name"`          // VARCHAR(n) or TEXT in SQL
    Age        int       `json:"age"`           // INT in SQL
}

SQL Table Schema :

CREATE TABLE users (
    id CHAR(36) PRIMARY KEY,
    name VARCHAR(255),
    age INT
);

This issue can now be considered resolved.