go-gorm

Persisting custom set data type using GORM golang

谁说胖子不能爱 提交于 2020-05-31 04:59:07
问题 I have created a custom Set Data type in go, which i am using to define one to many relationships. For example in my Schema, i have the following struct definition type Doctor struct { firstName string lastName string capabilities commons.Set } Here capabilities is a set of strings which have the following values chat, audio, video , with this setup i am trying to persist the above struct into MySQL using the GORM library, but when i do this i get the following error panic: invalid sql type

Inserting and selecting PostGIS Geometry with Gorm

早过忘川 提交于 2020-05-25 17:12:11
问题 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 geometries, and provides encoding/decoding between different formats. Orb has Scan() and Value() methods already implemented for each type. This allows go's Insert() and Scan() functions to work with types other than primitives. Orb expects however to be using geometry represented in the well-known

Golang Gorm: Is it possible to delete a record via a many2many relationship?

核能气质少年 提交于 2020-05-12 19:53:51
问题 I have a many2many structure similar to GORM's example: // User has and belongs to many languages, use `user_languages` as join table type User struct { gorm.Model Languages []Language `gorm:"many2many:user_languages;"` } type Language struct { gorm.Model Name string } db.Model(&user).Related(&languages) Let's say I create a user and it has two associated languages. I fetch a user record from the database and remove one language from the user's Languages array. I then save the user with gorm

Golang Gorm: Is it possible to delete a record via a many2many relationship?

南楼画角 提交于 2020-05-12 19:53:30
问题 I have a many2many structure similar to GORM's example: // User has and belongs to many languages, use `user_languages` as join table type User struct { gorm.Model Languages []Language `gorm:"many2many:user_languages;"` } type Language struct { gorm.Model Name string } db.Model(&user).Related(&languages) Let's say I create a user and it has two associated languages. I fetch a user record from the database and remove one language from the user's Languages array. I then save the user with gorm

Golang Gorm one-to-many with has-one

此生再无相见时 提交于 2020-05-10 04:11:49
问题 I'm trying to learn Go and Gorm by building a little prototype order management app. The database is MySQL. With simple queries Gorm has been stellar. However, when trying to obtain a result set involving a combination one-to-many with a has-one relationship Gorm seems to fall short. No doubt, it is my lack of understanding that is actually falling short. I can't seem to find any online examples of what I am trying to accomplish. Any help would be greatly appreciated. Go Structs // Order type

Gorm always return structs with nil values

强颜欢笑 提交于 2020-03-17 03:03:32
问题 I'm building a Go web API with Gorm as the ORM for Postgresql databases in Amazon RDS. Problem is Gorm always gives back a slice of structs which values are all nil, although the database is already populated with data. The number of structs in the slice are proper depending on the LIMIT I gave. I've also tried to directly query the SQL using database/sql builtin package, manually insert the variable inside rows.Next() loop and it works with no problem. I've tried this with 3 different tables

Gorm always return structs with nil values

喜你入骨 提交于 2020-03-17 03:02:04
问题 I'm building a Go web API with Gorm as the ORM for Postgresql databases in Amazon RDS. Problem is Gorm always gives back a slice of structs which values are all nil, although the database is already populated with data. The number of structs in the slice are proper depending on the LIMIT I gave. I've also tried to directly query the SQL using database/sql builtin package, manually insert the variable inside rows.Next() loop and it works with no problem. I've tried this with 3 different tables

Issue while creating primary key from gorm model

谁说我不能喝 提交于 2020-01-30 12:09:42
问题 While creating primary key from gorm model it return with error “duplicate column name: “id”” my model looks like type User struct { gorm.Model Id string gorm:"primary_key;" FirstName string LastName string } any idea what is the issue with above model 回答1: Gorm uses ID as the primary key by default. It is part of the gorm.Model you are embedding. When embedding the gorm.Model , you should leave ID out as gorm already includes it. The alternative is to remove the embedded gorm.Model and

How to query any table of RDS using Golang SDK

不羁的心 提交于 2020-01-16 10:16:10
问题 I am writing an AWS lambda to query 10 different tables from RDS(SQL Server) using Golang SDK. What I have learned so far is we have to create a similar struct for the table to query it. But as I want to query 10 tables, So I don't want to create the struct for every table, even the table schema may get changed someday. Lately, I want to create a CSV file per table as the backup with the queried data and upload it to S3. So is it possible to directly import the CSV file into a lambda, so that

go-gorm how to express many2many with additional columns

岁酱吖の 提交于 2020-01-14 13:32:18
问题 I want to express the following tables in GORM: CREATE TABLE indexes ( id INTEGER PRIMARY KEY, name VARCHAR ) CREATE TABLE services ( id INTEGER PRIMARY KEY, name VARCHAR ) CREATE TABLE index_service ( index_id INTEGER REFERENCES indexes(id), service_id INTEGER REFERENCES services(id), write_active INTEGER, PRIMARY KEY (index_id, service_id) ) After reading through documentations and questions on stack overflow. I still cannot find an answer on how to express the additional column write