Questions tagged [go-gorm]

GORM is an ORM library for the programming language Go, developed by jinzhu.

Filter by
Sorted by
Tagged with
1 vote
0 answers
16 views

Gorm field User: define a valid foreign key for relations or implement the Valuer/Scanner interface

This is my first time using Gorm, and when I run my server, this error keeps popping out. [error] invalid field found for struct github.com/Dokito555/mp3-player-backend/internal/models.Music's field ...
Koya's user avatar
  • 51
0 votes
0 answers
13 views

Using gorm for loading a pg_dump sql dump on (Fiber) app start

I've recently re-written a db api in Fiber using gorm as the ORM (which I a very happy with. 😍). At app spin up, I have a number of static tables that provide non-changing values of lookups (...
Daryl's user avatar
  • 23
0 votes
0 answers
35 views

GORM Association Append worked on MySQL but gives an error on SQLite

Because of various reasons, I have to change my database to SQLite after I finished creating my server. As I was testing out my server after switching to SQLite, an Association().Append() is now ...
rminaj's user avatar
  • 397
1 vote
1 answer
26 views

Gorm: failed to configure TLS (sslmode is invalid)

I'm trying to learn how to use gorm but faced with the small and silly problem. When I try to connect to my database, program throws me this error: [error] failed to initialize database, got error ...
Cross's user avatar
  • 559
1 vote
2 answers
72 views

How to write generic CRUD controller for all entities in golang?

I am creating a Go server using GoFiber to return data from MySQL database. I am using GORM library to save and fetch data from the db. I have 8 entities in total. I have defined model for these ...
Anmol Garg's user avatar
1 vote
1 answer
26 views

gorm query does not return contents of the table referenced by a foreign key

I have two entities defined as this: type Person struct { Id string `json:"id" gorm:"primaryKey;autoIncrement:true"` Firstname string `json:"firstname" ...
ZZZ's user avatar
  • 789
1 vote
1 answer
45 views

GORM: Define multiple columns with same foreign key

I am creating a Golang MySQL project where I am using GORM. I have a table called accounts with fields ID uint `json:"id" gorm:"primary_key;auto_increment;not_null"`...
Anmol Garg's user avatar
1 vote
0 answers
38 views

Join 2 or more tables in GORM

I am not getting the desired result by multiple table join using GORM. Example: type User struct { ID uint Name string Roles []Role `gorm:"many2many:user_roles;"` } ...
dinu0101's user avatar
  • 481
1 vote
0 answers
23 views

gorm v1 foreignKey Self model association

About gorm v1 I have some questions about the definition of the autocorrelation correlation model. I hope everyone can help me out type Player struct { ID int gorm:"primary_key" // id ...
Hubert's user avatar
  • 11
1 vote
1 answer
39 views

GORM: How to link one to one?

I'm trying to load queue items from my database. I've created an API endpoint but I can't get the data for the queue item to preload. Instead the entire "data" object is full of empty values....
Josh Hallow's user avatar
1 vote
0 answers
38 views

Go Gorm Gin Json

I have a structure that contains another structure. This structures represent the tables in my DB. I define connections between them through Gorm tags. As the result, when I pass this structure as ...
Nikita's user avatar
  • 11
1 vote
1 answer
25 views

Sorting Data With Foreign Key With Gorm using Go

I have no idea and stuck being here... So I need to sorting my data based on foreign key. I've been trying a few code (see that below) but didn't work at all. This is my structure data: type User ...
Joe Wilson's user avatar
1 vote
1 answer
24 views

gorm: can't preload field Repository for main.Application

When hitting this endpoint I get the following error, followed by a process exit: 2023/11/16 20:13:38 can't preload field Repository for main.Application exit status 1 I'm trying to preload ...
Josh Hallow's user avatar
0 votes
0 answers
43 views

Project with different modules but main module in root

I want to create a library in Go, a utility library for Gorm. The thing is that to create tests, I need also a driver (like postgresql, or mysql), but I don't want those drivers to be included in the ...
Manuelarte's user avatar
  • 1,688
1 vote
1 answer
30 views

Optional Extra Info in golang Model

I implemented three models for the backend in golang Category, product and document Models are defined as follows type Category struct { ID uint Title string Products []*Product } type Product ...
Iman pakseresht's user avatar
1 vote
0 answers
51 views

How can I befriend Gorm and Sqlx?

I have a medium codebase based on GORM, but I also want to use Sqlx. If you want to ask why I chose sqlx in cooperation with gorm the answer is: easy to debug and no reflections. But at this moment I ...
Manticore's user avatar
  • 153
1 vote
0 answers
26 views

Make gorm add value if exists and ignore it if no value on insert to db

I am writing an API using go and gorm . I have a column in my db - call_id , that is a foreign key.But it is nullable(meaning it accepts null as a value). I have a struct that am using to create a ...
siderra's user avatar
  • 141
0 votes
1 answer
41 views

Required_If Combination Issue in github.com/go-playground/validator/v10 package

Package version eg. v9, v10: Package Version: v10 Issue, Question or Enhancement: When I trying to run the below code. i get this error this is wired Output Validation error: Key: 'Application....
Mohanraj M's user avatar
1 vote
0 answers
34 views

how to change the primary key field of a table in Gorm?

my table primary key is u_id, but in Gorm's conventions is id, even though I have reclaim them in struct. type Users struct { gorm.Model UId uint `gorm:"column:u_id;...
Lynx's user avatar
  • 11
1 vote
0 answers
53 views

How Can I Set Up Prometheus And Gorm in Golang?

I'm trying to connect GORM and Prometheus. When I look up the gorm docs, they gave just configs but I couldn't find instructions. I set up exactly they told but can't execute that. dsn := fmt.Sprintf(...
icsarisakal's user avatar
2 votes
0 answers
35 views

Gorm problem with Pluck and Scan columns into different variables/structs with Pluck?

I have got the following table after grouping a little over my main table col1 |count| ------+-----+ test1 |12123| test2 | 1323| test3 | 4223| test4 | 1031| I now want to get this ...
Branchverse's user avatar
  • 1,265
1 vote
1 answer
66 views

golang GORM and Gin Unable to create object with association

I'm using GORM for the ORM with my Golang API to communicate with my DB. But for the creation with of an an entity with association on the database it's failed with the code (DB.Create(&data)) : ...
Lucas Chtroude's user avatar
1 vote
0 answers
40 views

How does the type interface work with GORM?

I have an interface type named Invoice : type Invoice interface { GetTransactions() ([]Transaction, error) } type DebitInvoice struct { gorm.Model ClientID uint `json:"client_id&...
kamil's user avatar
  • 11
2 votes
1 answer
69 views

GORM golang SQL query to do a case-insensitive search is not working

I want to do a case-insensitive search in Golang. I am using this library. I have tried the following but its not working. someId = "abc" model := abcModel{Id: someId} result := p.db.Where(&...
ray an's user avatar
  • 1,164
1 vote
1 answer
205 views

extended protocol limited to 65535 parameters - Golang Gorm

I am using Gorm library in golang to deal with database (postgres operations). I am doing the below-mentioned query to get some details. query = query.Where("id in ?", ids).Find(&dest) ...
Akhilesh mahajan's user avatar
1 vote
0 answers
47 views

Golang GORM: how to select multiply models from single query with Preaload

I have a set of models and I want to get them in one request, but I get a mapping error: Result's field Model1: define a valid foreign key for relations or implement the Valuer/Scanner interface. type ...
Gosha null's user avatar
0 votes
0 answers
14 views

Response time for queries increased badly when doing a duration test and dropping traffic from 20 TPS to 0.01 TPS

I have a Go App that runs in kubernetes with an Aurora postgress DB, we use Gorm to connect to the DB.I have noticed that if I do say 5 TPS and above, DB response time is very good in the order of ...
Luis Serrano's user avatar
0 votes
1 answer
35 views

Get records associated through M2M with a null ID or isn't equal to a specific one

I have a table, let's just call TableA, that has a relationship with an account table, let's call TableB. Now, TableA is kind of a notification that I track who already read it using a m2m field with ...
rminaj's user avatar
  • 397
1 vote
0 answers
61 views

how to exclude from group condition

I know how to create grouping condition but what make me frustrated is trying to put condition outside existing grouping condition i am doing this with gorm: func Abc(db *gorm.DB) *gorm.DB { return ...
Bens's user avatar
  • 866
0 votes
0 answers
24 views

Gorm postgress DB database display error: bigint type for the user id

Based on the schema below, when I try to implement the function, it displays an error as it's not a bigint type for the user id, but the user id in the user struct generated by gqlgen is a string. My ...
melkamu's user avatar
2 votes
1 answer
83 views

GORM: two foreign keys to one table

I want to create three tables: Users, Events, Pairs. In the Pair-table there will be three columns: eventId, user1, user2. So user1, user2 will both reference Users table by id. I know how to this in ...
Gevorg's user avatar
  • 23
1 vote
0 answers
29 views

GORM Gloang Models Hooks Inheritance Issue [duplicate]

I have a base model that then I go and expand onto all my other models. In my base model I have a BeforeCreate hook which assigns a custom ID for objects. Then I added another model which also has a ...
rak1n's user avatar
  • 747
2 votes
1 answer
50 views

How do I store an array of values using GORM + Postgres?

I have tried using the docs here describing Many-to-Many relationships, but when I exactly copy their example, I get an error. Here is a slimmed-down version of the code (which requires Postgres to be ...
frizzkitten's user avatar
0 votes
2 answers
73 views

Golang + GORM Fetch foreign key with raw query

I have question regarding fetching foreign key in GORM. I am using golang and POSTGRES for my database. AFAIK, Preload(clause.Associations) will fetch the foreign key from our database. If we are ...
Rahadian Ardya's user avatar
1 vote
0 answers
30 views

Unable to construct many to many relationship in gorm

i'm trying to construct user and friend table with a many to many relationship in gorm but unfortunely pop up the error ERROR: column "id" referenced in foreign key constraint does not exist ...
asd asd's user avatar
  • 11
3 votes
3 answers
127 views

gorm m2m custom connection table, foreign key constraint setting is invalid

I try to migrate mysql's sql to gorm sql: CREATE TABLE IF NOT EXISTS `admin` ( `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS `...
januw a's user avatar
  • 2,018
1 vote
0 answers
39 views

GoLang: Preload not working properly, incorrectly adding WHERE (1 <> 1) to my queries?

I have my user struct type User struct { ID uuid.UUID `gorm:"type:uuid;primary_key;"` ... Roles []*Role `gorm:"many2many:user_roles_map"...
Cole Charc's user avatar
1 vote
1 answer
51 views

Build a go application that uses GORM, In a github workflow

I have a simple Go app that uses GORM (The boilerplate code from their site). I'm trying to go build it in a workflow in github, which runs on windows-latest. The built-in GCC compiler throws the ...
Yair Levi's user avatar
1 vote
0 answers
39 views

GORM model with custom datatype

I am trying to initialize my database and create the tables for the models I declared. I have a model called Analytics with has a set of properties with a custom data type (structs I created). When I ...
BitQueen's user avatar
  • 685
1 vote
0 answers
19 views

Gorm won't return relation inside relation

I have this code var found_shipment []models.ShippingLine db.Preload("PortLoading").Preload("PortDischarge"). Preload("Vendor").Preload("PortLoading.Regency&...
Danendra's user avatar
  • 175
0 votes
0 answers
37 views

failed to initialize database, got error dial tcp 127.0.0.1:3306: connect: connection refused panic: An error occured [duplicate]

When I run my code using go run . it runs and the database tables get created successfully, but when I use docker run mybackend:multistage , I get this error: failed to initialize database, got error ...
Joel Swakise TheDancer's user avatar
1 vote
0 answers
34 views

GORM can not add or update child row

I don't know where I went wrong here, I try to add 2 hasMany relations to my ticker struct but it always fails on updating the rows with the message "can not add or update child row, foreign ...
BitQueen's user avatar
  • 685
0 votes
0 answers
65 views

Getting an error while using a string array in go struct

I have couple of struct types in my application and some of them have struct arrays as attribute like : type A struct { ... B String_Array `json:"item" gorm:"type:text"` ... } ...
hatirlatici's user avatar
  • 1,626
1 vote
2 answers
60 views

db.Model(&Usertable).Create(data): How to pass the correct tablename?

I am trying to insert a row into a table defined as a model. Below is the relevant code snippets: Package Structure: gorm |- server |- insertRow.go |- pkg |- models |- mytable.go |- ...
Ravindra Rao's user avatar
1 vote
0 answers
36 views

Pagination data from Find method GORM

I want to implement pagination using limits and offsets in my GORM app. Ive been coding in node or java in the past where the major ORMS all had some utilities to retrieve pagination data along side ...
BitQueen's user avatar
  • 685
0 votes
0 answers
87 views

Golang GORM console logs SLOW SQL - search of performance issue

I am building a small app using Golang and GORM and it is working fine so far (I am new to Golang). The only thing that bothers me, which I do not know if thats something to worry about is that my ...
BitQueen's user avatar
  • 685
1 vote
0 answers
78 views

How do we set cursor batch size of posgresql in gorm in golang

I have very large table and where I am doing a select * operation in gorm. To improve the performance I would like to set the batch size of the cursor (memory is not a constraint here so I can set it ...
Ashwin Sreekumar's user avatar
2 votes
1 answer
114 views

Cannot connect to postgres docker container from golang's docker container

I'm trying to connect to the docker container's postgresdb database from Golang Fibers container. When I run my postgres continer and run go project locally it could connect to the postgres's ...
Fahad Md Kamal's user avatar
1 vote
0 answers
38 views

Golang GORM one-to-many primary key on custom primary key (string) in parent struct error

I have to structs I want to connect via a one to many relation but it fails with the error "invalid field found for struct mygithub/repo field Analytics, need to define a valid foreign key for ...
BitQueen's user avatar
  • 685
1 vote
1 answer
32 views

How to concatenate two columns from different tables in select

I have two different tables. table1.price table2.domain I need that in the select I can concatenate this value so that when querying the API it brings me as follows R$ 13.97 - test.com err = m....
luankobs's user avatar

1
2 3 4 5
38