Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gorm in the backend code #354

Open
frouioui opened this issue Jun 1, 2023 · 1 comment
Open

Use gorm in the backend code #354

frouioui opened this issue Jun 1, 2023 · 1 comment
Assignees
Labels
Component: Runner The core runner of the system go Pull requests that update Go code P3

Comments

@frouioui
Copy link
Member

frouioui commented Jun 1, 2023

No description provided.

@frouioui frouioui added Component: Runner The core runner of the system P3 go Pull requests that update Go code labels Jun 1, 2023
@frouioui frouioui self-assigned this Jun 1, 2023
@achintya-7
Copy link

achintya-7 commented Feb 21, 2024

Hi @frouioui

I am not sure if gorm is a requirement for the project but can I suggest this package - sqlc
It can generate idiomatic Go functions as per the queries from *.sql files along with proper structs and types.

A simple example can be like this
query

-- name: GetBubblesWithThreshold :many
SELECT * FROM bubbles_profile
WHERE profile_key = $1 AND staged_images >= $2;

usage of generated function

args := GetBubblesWithThresholdParams{
	ProfileKey:   profile.Key,
	StagedImages: int64(config.TrainingThreshold),
}

bubbles, err := store.GetBubblesWithThreshold(ctx, args)

It can also generate an interface of all the quries as per the *.sql files which can make testing easier.

PS, It does require migration file/files of the SQL database to have a reference for generating structs and assigning of types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Runner The core runner of the system go Pull requests that update Go code P3
Projects
No open projects
Status: Todo
Development

No branches or pull requests

2 participants