Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
vinod023
@vinod023
I sent time.Now() to db
please help me friends.
Hongsen Liu
@hongsenliu
Is there any way to set deleted_at to NULL in an update statement?
Hongsen Liu
@hongsenliu
nvm, I got it, using beforeupdate callback
andreaneri
@andreaneri
hello
is supported Oracle ?
Turing Zhu
@Turing-Chu
hello, how can I add table comment and column comment in declaring modules ?
Like the picture:
image.png
then it can show here:
image.png
image.png
Turing Zhu
@Turing-Chu
comment on columns can use like as follows:
image.png
Amos Kyler
@amoskyler
Hey all - I'm having some trouble with running db.Create()on models with many2many relationships within parallel goroutines. I'm getting a huge number of deadlocks on inserts into the jointable.
I'm not really sure how to approach debugging the thing. The queries which deadlock each other look like this INSERT INTO `infoid_property` (`infoid`,`propertyid`) SELECT ?,? FROM DUAL WHERE NOT EXISTS (SELECT * FROM `infoid_property` WHERE `infoid` = ? AND `propertyid` = ?)
Muhammad Habib
@habibsatti_twitter
@habibsatti_twitter
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
}
vinod023
@vinod023
Hi, I need to pass the query parameters into DB.Raw(). Is there any possible? question link : https://stackoverflow.com/questions/56745827/how-can-i-add-query-parameters-dymanically-using-gorm
@vinod023
vinod023
@vinod023
Hi @jinzhu thank you for responding. I seen already sql builder. but I need to pass query parameters based on input. If they send two parameters from front end side I need add in query level. if they sent 6 and i need add in query level. so these process can done dynamically. How can Add parameters dynamically? please show above link once. My query has text[].
vinod023
@vinod023
Hi @jinzhu Can I add parameters like :
var resp = map[string]interface{}{"username": User.UserName, "nickname": User.NickName}
if err := DB.Raw(query, resp).Scan(&Users).Error; err != nil {
return nil, err
}
is it ok?
Muhammad Habib
@habibsatti_twitter
Hi all
i am usign gorm to connect with cockroachdb , any one guide me how connection pooling works in gorm. i want to know if every time we hit a router or access a page a new db connection open or gorm save the old connection and use that connection for subsequent request ?
rgingoyon
@reilg_gitlab
Hi - is there a way to update an object without updating the children objects? eg. User has []Email, but when I call User.Save(), it also calls Email.Save()
maoyuan121
@maoyuan121
@reilg_gitlab If you only want to update changed Fields, you could use Update, Updates。 Save will include all fields when perform the Updating SQL, even it is not changed。
Osman Bineev
@algebraic-brain

Hi!

If I already have a Card in database and I want to create (insert) Event that hase-one-card, how to do this? Please example

type Card struct {
    gorm.Model
    ...
}

type Event struct {
    gorm.Model
    Card Card `gorm:foreign_key:CardID`
    ...
}
Osman Bineev
@algebraic-brain
I mean I know a valid CardID already
vinod023
@vinod023
I used gorilla-mux in my application. In front end side we used angular js. POST and GET method working fine. When PUT and DELETE are not working. It is showing error in browser like Access to XMLHttpRequest at 'http://localhost:8000/v1/cons?consid=38' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
func CommonMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r http.Request) {
w.Header().Add("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "
")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Access-Control-Request-Headers, Access-Control-Request-Method, Connection, Host, Origin, User-Agent, Referer, Cache-Control, X-header")
next.ServeHTTP(w, r)
})
}
Vibhav Pant
@vibhavp
How would I select a single column into a variable that is not a slice?
Vibhav Pant
@vibhavp
specifically, I cannot Scan time.Time objects
Yaroslav Molochko
@onorua

Hello, I have a structs

type User struct {
   Name string
   Groups []*Group
}

type Group struct {
   Name string
   Users []*User
}

I'm doing something like:

db.Preload("Groups").Find(&users)

and I expect that my structure will be populated with the data from Database, and Groups will be populated also. Instead, it generated following SQL:

SELECT * FROM `users`  WHERE `users`.`deleted_at` IS NULL

am I missing something?

Yaroslav Molochko
@onorua

I did:

Preload("Groups").Find(1&users).Related("Groups")

and in MySQL it doesn't work, in SqlLite3 - works well..

it looks like a bug to me
Amarjeet Anand
@amarjeetanandsingh
perzUsers := []User{}
if fetchErr := db.Table("uid_user_master").Select([]string{"UserId", "PrimaryEmailId"}).Where("UserId IN (?)", rbUserIds).Find(&perzUsers); fetchErr != nil {
    fmt.Printf("Error: %+v", fetchErr)
    return nil
}
type User struct {
    RideUserID string `json:"_key" gorm:"-"`
    RbUserID   int64  `json:"RbUserID" gorm:"column:UserId"`
    PEmail     string `json:"PEmail" gorm:"column:PrimaryEmailId"`
    PEmailHash string `json:"PEmailHash" gorm:"-"`
}
Whats wrong with the code?? It prints err as:-
Error: &{RWMutex:{w:{state:0 sema:0} writerSem:0 readerSem:0 readerCount:0 readerWait:0} Value:0xc0002860a0 Error:<nil> RowsAffected:5 db:0xc0002480c0 blockGlobalUpdate:false logMode:0 logger:{LogWriter:0xc0001a1ea0} search:0xc000034840 values:{mu:{state:0 sema:0} read:{v:<nil>} dirty:map[] misses:0} parent:0xc0003ff930 callbacks:<nil> dialect:0xc0002861a0 singularTable:false}
cakoc
@cakoc_gitlab
Hello. I would kindly like to ask how to handle connection pooling in GORM. Does anybody know some Doc/Tut how to request GORM compatible connection or maybe even manage the pool? I have found http://gorm.io/docs/generic_interface.html#Connection-Pool but still strugle how to require new Connection, or free it back to the pool.
Muhammad Habib
@habibsatti_twitter
Hi All, which go package is good for generating uuid with GORM, currently i am using github.com/satori/go.uuid
any suggestion ?
Adonis Najimi
@adoken_gitlab
Hello all!
I'm wondering if there is a way to do a "cascade" soft delete in Gorm?
If not, what's the best way to implement it?
If someone could help me, it would be very nice!
TianDaGe
@TianDaGe
hello everyone
I have just post my issue. please help me...
I am sticking this issue for over 2 days. :(
package main

import (
    "fmt"

    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
)

// File represents file
type File struct {
    Csurrogat int `gorm:"primary_key"`
    Name      string
    Positions []Position `gorm:"foreignkey:cfilesur;association_foreignkey:csurrogat"`
}

// Position represents position
type Position struct {
    Csurrogat int `gorm:"primary_key"`
    Cfilesur  int `sql:"type:integer REFERENCES files(csurrogat)"`
    Name      string
}

func main() {
    var err error
    var db *gorm.DB

    db, err = gorm.Open("sqlite3", "sample.db")
    if err != nil {
        panic("failed to connect sqlite database")
    }
    defer db.Close()

    // Migrate the schema
    db.AutoMigrate(&File{})
    db.AutoMigrate(&Position{})

    db.Create(&File{Csurrogat: 1, Name: "sample"})
    db.Create(&Position{Csurrogat: 1, Cfilesur: 1, Name: "file1"})
    db.Create(&Position{Csurrogat: 2, Cfilesur: 1, Name: "file2"})
    db.Create(&Position{Csurrogat: 3, Cfilesur: 1, Name: "file3"})

    files := []*File{}
    if err := db.Find(&files).Error; err != nil {
        panic(err)
    }

    for _, file := range files {
        db.Model(&file).Related(&file.Positions)
        fmt.Println(file.Positions)
    }

    fmt.Println(files[0])
}
[]
&{1 sample []}
If i use FileID instead of Cfilesur, it is working fine.
TianDaGe
@TianDaGe