Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
33 views

how to preload models that are not directly related

i have models like this type TreatmentFormOutput struct { ID uint OutputID uint Output Output TreatmentFormID uint Indicators []OutputIndicator ...
zexceed12300's user avatar
0 votes
0 answers
167 views

When I updated gorm version to v1.25.12, run dbresolver plugin (v1.5.2) failed

My code as follows gormDb, err = gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", viper.GetString("mysql.username"), viper....
SuperGodK's user avatar
1 vote
0 answers
42 views

gorm: migrate from string to pq.StringArray doesn't work

I have now: type tableA struct { fieldA string } and I want to change from a single text to an array of text: type tableA struct { fieldA pq.StringArray `gorm:"type:text[]"` } but ...
Raul Cejas's user avatar
0 votes
0 answers
19 views

How to dynamically route traffic to different databases?

dsn := "user:pass@tcp(127.0.0.1:3306)/testDB?charset=utf8mb4&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) if err != nil { panic("...
user27121282's user avatar
0 votes
1 answer
27 views

GORM is not returning correct time.Time value for as Datetime type mysql column

Database is created by db.AutoMigrate(&models.User{}) User is in package: models type User struct { Username string `json:"username" gorm:"primaryKey; not null; ...
Aadarsh Naik's user avatar
1 vote
0 answers
42 views

GORM - How to use a custom interface?

package models import ( "gorm.io/gorm" ) type GormQueryBuilder interface { FindQueryBuilder(db *gorm.DB) *gorm.DB } type BaseInterface interface { Get(GormQueryBuilder, *gorm....
ZackMelan's user avatar
1 vote
2 answers
43 views

Go GORM NOT IN query list of ids

I'm trying to run a SELECT * WHERE ID NOT IN (?) query in GORM and it does not seem to work. The argument for the ? parameter comes from the application and is not a database subquery which would be ...
Sam's user avatar
  • 946
0 votes
0 answers
30 views

GORM Soft Delete - Also set UpdatedAt to match DeletedAt

We are using GORM soft delete behavior and we also want the UpdatedAt field set to match the DeletedAt field on soft delete, but it doesn't seem to do that. Is there a way to configure it to do so, or,...
Myles McDonnell's user avatar
1 vote
1 answer
42 views

How can identifiers like roles and tables be used dynamically in GORM with Raw SQL?

I am working on a Go project using GORM and PostgreSQL, and I need to dynamically use identifiers such as roles and tables in my SQL queries. However, I am encountering an issue with parameterized ...
Aaron Newton's user avatar
  • 2,204
0 votes
0 answers
39 views

Why is GORM migration inferring the wrong data types for a many to many relationship?

I have the following structs generated by Gorm Gen: type UserBase struct { ID int32 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` Name string `...
LaserJesus's user avatar
  • 8,500
0 votes
0 answers
78 views

How do you generate Gorm tables with relations?

I'm trying to achieve this Add functional tests to my Go project The tests should bring up an actual MySQL database (by connecting to a docker container already up and running from the docker ...
LaserJesus's user avatar
  • 8,500
1 vote
1 answer
41 views

How do I omit fields completely when selecting in GORM?

I have my GORM Schemas shown below. Two tables i.e Items and Users. Every item is has a user who created the item. type Item struct { ID uuid.UUID `gorm:"type:uuid;default:...
Worldwide's user avatar
0 votes
1 answer
61 views

Question about error raw query string using gorm

I generate raw query like that UPDATE public.openedu_user_tokens AS t SET update_at = c.update_at, delete_at = c.delete_at, user_id = c.user_id, org_id = c.org_id, email = c.email, ...
Anoencs's user avatar
1 vote
2 answers
86 views

Golang gorm runtime error: invalid memory address appears after a long idle time when using same gorm.db connection

After some hours of running without problems I get the following runtime error: [ERROR] runtime error: invalid memory address or nil pointer dereference goroutine 37 [running]: runtime/debug.Stack() ...
John MacStoian's user avatar
1 vote
1 answer
110 views

Why GORM automigrate will try to drop a non-exist index

I have a type as type Customer struct { gorm.Model CorpId string `gorm:"column:corpid"` Name string `gorm:"column:Name"` Age int } And I use GORM to do the ...
peter liu's user avatar
2 votes
0 answers
69 views

GORM adding "AND column.id = 1", why?

Im having an issue with GORM on my GIN project. Please help me if possible. My issue is: var class models.Classrom old_classID = "algorithm" DB.Model(&models.Classrom{}).Where("...
Law's user avatar
  • 21
1 vote
1 answer
50 views

How to config query timeout default for all query?

I am working with GORM in my Go application and I need to set a default query timeout for all queries. Currently, I have individual queries where I set the timeout explicitly, But I want to avoid ...
Hậu Chử's user avatar
0 votes
0 answers
12 views

Workbench not opening on the Desktop

I have installed Mysql on my system using the normal documentation procedures and instructions. I have also downloaded the Mysql workbench also by following instruction from Msql documentation website....
Tade77's user avatar
  • 1
0 votes
0 answers
46 views

How to Write Unit Tests for GORM Repository Method with gomock?

I am trying to write unit tests for a GORM repository method using gomock to mock database interactions. However, I'm running into issues with nil pointer dereference errors. Below are the relevant ...
Cava's user avatar
  • 5,612
0 votes
1 answer
66 views

How to create a generic array in GO?

I have a function that needs to receive a GORM model as a parameter, and depending on the model I receive as a parameter, I need to create an Array(Slice) based on the type of the struct(gorm model) I ...
Gustavo Piucco's user avatar
1 vote
1 answer
71 views

GORM Help w/ Postgres: unsupported data type [closed]

I'm trying to read through the CVE List to put all the entries into a central database. When I try to create an entry to this databse, I get an error: 2024/07/02 14:03:13 /x/db.go:68 unsupported data ...
Aidan Gatenbee's user avatar
-1 votes
1 answer
56 views

Cannot use exported method that belongs to the package in Golang

I've got a package named services. This is the structure of the package: services/ third_party/ discogs.go discogsAPIStructs.go artist_srv.go auth_srv.go record_srv.go ...
MrCujo's user avatar
  • 1,271
-4 votes
1 answer
42 views

How to use subquery into field on gorm query

I have a query like this: select a.id, ( select max(b.last_update_login) from login_history b where b.user_id = a.id ) last_update_login from user a How do I convert this into a ...
Jeffy Dwitra's user avatar
1 vote
0 answers
59 views

Golang GORM Recursive Structure Migration (MySQL)

I'm trying to create a recursive table structure, but I have not had any luck. Here's a simple example of what I'm trying to achieve: package models import ( "gorm.io/gorm" ) type ...
LUKER's user avatar
  • 514
-2 votes
1 answer
376 views

dial tcp 192.168.48.2:3306: connect: connection refused

My connection to the DB keeps getting refused i tried to make sure all the ports were correct and parameters were matched up but i still keep getting this error this is my docker compose file ...
Whoisshaggy's user avatar
0 votes
0 answers
44 views

GORM many2many Association Replace not working as expected

I have a GO application using GIN and GORM. I want to create a Roles + Capabilities database. A role can have multiple capabilities and a capability can be in multiple roles. I created the following ...
Bilal Javed's user avatar
1 vote
0 answers
101 views

How to deploy a SQLite Database with a GO application

I have an application structured more or less like the following : app api database db.go main.go data database data.db ui I would like to connect as a ...
LCaraway's user avatar
  • 1,337
1 vote
0 answers
52 views

Select Data from Two Tables without a Join (Cartesian Product) in Gorm

I'm trying to select data from two SQL tables without a join. Essentially, I need a Cartesian Product of the two tables. The SQL statement I expect to use is: SELECT * FROM table1, table2 WHERE table1....
Shalom Peles's user avatar
  • 2,563
1 vote
0 answers
47 views

Run `go-mssqldb` and GORM at the same time

I have the legacy code that written with RAW query that already contains 700+ unique queries. The system is keep growing, but I feel writing RAW query everytime through database/sql are killing our ...
Firmansyah Yanuar's user avatar
2 votes
0 answers
100 views

Use dynamic table name in Join with Gorm to add WITH(NOLOCK)

I'm using gorm in my golang project to connect a SQL Server database and everything works fine. Now I would like to dynamically set the table name in my Joins() calls, like I can do with the main (...
Simone Serra's user avatar
1 vote
1 answer
34 views

mysql data cannot be queried using go gorm

I use gorm to count qps of mysql, but the query data is always empty. The program did not report any errors, and I could have used similar code to get my own test table data. My code type mysqlQueires ...
Celica Chen's user avatar
1 vote
0 answers
34 views

Generic function to upsert objects using gorm in Go for mssql?

I'm attempting to create a generic function in Go for upserting objects in a Microsoft SQL Azure database using gorm, but am not too familiar with the details in the documentation for gorm and wanted ...
Darren's user avatar
  • 1,133
2 votes
1 answer
75 views

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

I have got this error . when I try to query define a valid foreign key for relations or implement the Valuer/Scanner interface This is my model struct. type SkuDetails struct { SkuID string ...
Ezilys's user avatar
  • 21
2 votes
1 answer
159 views

GORM enum type for postgres

I use GORM to work with PostgreSQL. For example I have a such struct with custom enum type: type MonitoringDatabase struct { Name string `gorm:"primaryKey"` DBType ...
Cvitoybamp's user avatar
1 vote
0 answers
92 views

Restore and update soft deleted record Go Gorm

We are creating a translation app with a golang and gorm backend This is our POSTGRES database table: DataBase Table screenshot This is our Go Struct: type TermLocale struct { models.Model ...
PatAfixer's user avatar
0 votes
0 answers
45 views

gorm define a valid foreign key for relations

I have following tables in postgresql: CREATE TABLE IF NOT EXISTS "offices" ( "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "full_name" ...
Zeinab Abbasimazar's user avatar
1 vote
1 answer
38 views

Gorm append in association mode fails my validation checks even when both the objects exist

I am using the GORM ORM library for Golang to model the above relation. Here is the model code for the same: package models import ( "errors" "fmt" "regexp" ...
Vineet Kalghatgi's user avatar
1 vote
0 answers
60 views

Optional relations in database model in GORM

Using a custom DbAuthoring model I add fields createdBy to my database models. This works fine (I have to populate them manually fetching the user ID out of the JWT claim though). Of course, the IDs ...
Paul Wellner Bou's user avatar
1 vote
2 answers
51 views

how to use gorm to make a raw query to DB and get fields from different tables in result?

I have the following (note that in the query I expect to get fields from different tables. Maybe there is some kind of peculiarity in this): type Result struct { ID string `gorm:"...
Andrew Krylov's user avatar
1 vote
0 answers
69 views

Failed Catching Error Record Not Found with GORM

I tried to select a record with the code below. err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("description = ?", item.Description).First(&exist).Error ...
kartikasw's user avatar
1 vote
0 answers
23 views

How can I delete associated models in Gorm?

I'm facing a problem with deleting ModelA along with its associated ModelB instances using Gorm's soft delete methods. Here's a simplified version of my code: type ModelA struct { gorm.Model ...
BeginTP's user avatar
  • 55
1 vote
1 answer
143 views

Testing with gorm and sqlmock: could not match query with expected regexp

I am working on a project using GORM and I am trying to write tests using SQLMock. Below is the code snippet defining my custom types and a database model using GORM: // ActionType action type type ...
AmirReza's user avatar
  • 345
1 vote
1 answer
74 views

Traversing many-to-many relationship in condition using gorm

I use a postgres database and naming strategy schema.NamingStrategy{ NoLowerCase: true, SingularTable: true, } and have a database model like this: type Project struct { gorm.Model ...
UTF-8's user avatar
  • 625
0 votes
1 answer
162 views

Failed to initialize database, got error dial tcp 192.168.16.2:3306: connect: connection refused

Got [error] failed to initialize database, got error dial tcp 192.168.16.2:3306: connect: connection refused when run docker compose up -d docker-compose.yml version: "3" services: app: ...
Huong Minh's user avatar
1 vote
0 answers
62 views

MySQL Cloud - Golang (Random invalid transaction; invalid transaction; invalid transaction Error)

I don't know what the culprit is in this issue, the first time I run this REST API it works fine then I run it the 2nd time and I get this error "Invalid Transaction, Invalid Transaction, ...&...
Mabel Oza's user avatar
  • 697
1 vote
0 answers
48 views

Fetch Previous State In Gorm V2 Callback

I am trying to query for the previous state of the row in a callback. I've registered the callback as such: callback.Update().Before("gorm:save_before_associations").Replace("...
Ben Sun's user avatar
  • 23
2 votes
1 answer
87 views

Upsert Postgres JSONB column using GORM

There is a table in Postgres Id Code Data (jsonb) 1 xc1 {"name": "xx", "instance":"test_instance", "system": "test_system"} 2 cc3 {"...
Anni Benni's user avatar
1 vote
1 answer
38 views

GORM creating/inserting a model with a foreign key field returns an error (cannot convert)

here are two models I have and postgres migrations for these two models (every separate migration and struct is in its separate file): type BaseModel struct { ID uint64 `gorm:"...
Dmitrii Timoshenko's user avatar
1 vote
1 answer
58 views

GORM many to many with addition field as primary key in join table

Is it possible to add an additional field to the composite primary key created on the join table of a "many to many" relationship? The reason is for allowing multiple identical records (that ...
Imperyal's user avatar
1 vote
1 answer
79 views

GORM fails to query boolean json field in MySQL

NOTE: I have only tested this issue with MySQL. When querying a property inside a json field with a bool argument, the query returns 0 rows. However, if you embed the bool into the where clause itself,...
andersryanc's user avatar

1
2 3 4 5
40