go-gorm Questions

4

Solved

I have model like this in model.go type yourTableName struct { Name string `gorm:"type:varchar(50)" json:"name"` Email string `gorm:"type:varchar(50)" json:"e...
Earnest asked 24/12, 2020 at 4:51

2

In my database I have a users table, joined via a many-to-many table to schools. A school has many jobs. I'm trying to return all the schools and their jobs for a specific user. This is my code so ...
Rebus asked 11/9, 2018 at 6:53

3

I am trying to insert a time.Now() field into the database, but what keeps happening is the time is shifted forward to UTC. I understand the idea is to always to that then convert to local time whe...
Ketene asked 19/7, 2016 at 19:11

4

Solved

Is there a way to get the sql query log from https://github.com/jinzhu/gorm? e.g. in dev environment, it would be useful to be able to log to the console the mysql queries that have been called. ...
Ten asked 29/3, 2016 at 10:14

3

Solved

I'm trying to Preload data from a One to Many relationship, yet I always get an "ApiKeys: unsupported relations for schema Client" error. (The reason structs are pointers is because I'm u...
Racklin asked 26/3, 2021 at 3:4

4

I'm using PostgreSQL and GORM in my Go app. I thought that using the sql tab of sql:"not null" would do the trick of preventing a null entry, but when go initializes structs with a string type the...
Mcmullan asked 24/4, 2017 at 12:4

1

Solved

Say I have a table 'testing' with a column 'agents' of type jsonb that stores an array of agent names > SELECT * FROM testing; +--------------------------------------+---------------------+ | id...
Epicene asked 17/1 at 13:43

8

Solved

On updates gorm doesnt update boolean type to false. By default it updates to true, but when i try to update to false not changes. I dont see any errors also. What can be the issue ? type Attendee...
Faddist asked 18/6, 2019 at 16:27

4

Solved

Is it possible to get model's table name? I see that it's possible to get it from ModelStruct but I don't know how to do it correctly. I didn't find any initializations for this structure. user :=...
Rosalie asked 24/8, 2018 at 7:26

3

Solved

I have this custom type for users: type User struct { UserID uint64 `gorm:"primaryKey"` CreatedAt time.Time UpdatedAt time.Time LastLogin time.Time } When passing to gorm's db.Create...
Rhodolite asked 29/1, 2021 at 8:40

11

Solved

Gorm has a FirstOrCreate method and a FirstOrInit but how to check afterwards if the record was actually created? I like to create a record if it does not exists and if it exists I want to update s...
Maori asked 5/9, 2016 at 14:48

3

Solved

I'm working with complicated structure database, and after update we start using GORM so I need to transform this script using GORM. query := ` SELECT * FROM foo UNION ALL SELECT * FROM bar WHER...
Marquis asked 21/4, 2021 at 7:14

6

Solved

I've been trying to find a way to insert and retrieve geometric types using Golang, and specifically the library gorm. I'm also attempting to use the library orb that defines different types for ge...
Superincumbent asked 9/2, 2019 at 2:21

7

Solved

I am writing PostgreSQL table schema. type TestTable struct { ID int `gorm:"column:id;primaryKey;autoIncrement"` CarType string `gorm:"column:car_type"` } So how can i add ca...
Umbrageous asked 3/8, 2021 at 13:48

5

Solved

I am using Gorm in my Golang project. Exctly I have a Rest-API and I get a request make the process and return an object, so, for example I have a struct User like this: type User struct { gorm.M...
Zaffer asked 16/5, 2017 at 13:39

4

I am having a problem with this library because this function returns false even when the given input is not in the database, when in fact it should return true. type User struct { ID uint `gorm:...
Pub asked 28/8, 2018 at 21:1

6

Solved

I have those two models: User model: type User struct { DBBase Email string `gorm:"column:email" json:"email"` Password string `gorm:"column:password" json:"-"` } func (User) TableName() stri...
Jeffrey asked 26/10, 2018 at 18:10

2

Solved

I have a transaction table in gorm that looks like this: type Transaction struct { gorm.Model UserID string `gorm:"index"` TradeID int Trade Trade ExternalID string Amount float32 ...
Jaqitsch asked 10/3, 2021 at 11:26

8

I have the following model... type User struct { ID string `sql:"type:uuid;primary_key;default:uuid_generate_v4()"` FirstName string `form:"first_name" json:"first_name,omitempty"` LastName st...
Chak asked 7/4, 2016 at 20:26

5

This is primarily focused towards having setup() and teardown() methods for a test suite that I'm planning on writing that involves creation of a DB. I've figured out how to create a DB using GORM...
Ancillary asked 5/1, 2019 at 3:40

2

Solved

Original Question When using the Update method in GORM the new data does not get saved. i.e. I want to set a bool from true to false, but it stays true even after the Update method. In the descript...
Riki asked 13/10, 2020 at 7:27

6

I decided to use gorm as my ORM. I wanted to do a migration using golang-migrate/migrate because, it looks like, GORM does not have versioned migration files. And I rather, do migration using CLI, ...
Indiscriminate asked 24/10, 2020 at 4:50

3

Solved

I am trying to update some values using gorm library but bytes and ints with 0 value are not updated var treatment model.TreatmentDB err = json.Unmarshal(b, &treatment) if err != nil { http....
Activity asked 4/2, 2019 at 20:21

2

Solved

Answer: Use db.Exec("PRAGMA foreign_keys = ON") to enforce foreign key constraint checks. Thanks @outdead When I update my SQLite database using GORM, foreign key constraints aren't enfor...
Deneb asked 1/12, 2021 at 21:47

7

Solved

I want to check if a row exists in a database table or not. I first used this approach: type MyStruct struct { ID uint32 Key string Value string } var result MyStruct err := db. Where("i...
Marrymars asked 26/2, 2021 at 20:25

© 2022 - 2024 — McMap. All rights reserved.