microsoft / microsoft/go

[BEST PRACTICE] To use with unique identifier

Open
#1,143 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Go
Stars
431
Forks
44
Avg merge
21h 18m
Merged PRs (30d)
30

Description

Hello, guys. Thanks for this project be public.
I have a question about best case to uses with mssql.uniqueidentifier.
This is a small example of my struct and crud operations. I use bun to connect to database


type SomeStruct struct {
	ID         int                    `bun:"id"`
	ExternalId mssql.UniqueIdentifier `bun:"externalid"`
	IdPost     int                    `bun:"id_post"`
	IdAvatar   int                    `bun:"id_avatar"`
}

func (someStruct *SomeStruct) MarshalJSON() ([]byte, error) {
	type Alias SomeStruct
	return json.Marshal(&struct {
		ID string `json:"id"`
		*Alias
	}{
		ID:    someStruct.ExternalId.String(),
		Alias: (*Alias)(someStruct),
	})
}

I need use externalId as string everywhere at my project. And i need to cast mssql uniqueidentifier to string like i do at MarshalJson func. Is there a best practice to handle this without uses conversion everytime? I am thinking about change the unique identifier column to string. But i will lost much funcionalities of unique identifier be managed by sql server.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file, test, or entry point is named; start by reviewing the Go struct, MarshalJSON method, and mssql.UniqueIdentifier usage shown in the issue. A useful outcome would require an agreed approach for exposing the identifier as a string while retaining the SQL Server uniqueidentifier column, with documentation or tests demonstrating it.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
database
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.