https://lakefs.io/ logo
Docs
Join the conversationJoin Slack
Channels
announcements
blockers_for_windward
career-opportunities
celebrations
cuddle-corner
data-discussion
data-events
dev
events
general
help
iceberg-integration
lakefs-for-beginners
lakefs-hubspot-cloud-registration-email-automation
lakefs-releases
lakefs-suggestions
lakefs-twitter
linen-dev
memes-and-banter
new-channel
new-channel
say-hello
stackoverflow
test
Powered by Linen
stackoverflow
  • r

    rss

    01/21/2023, 3:17 AM
    How to input source and target database parameters in IBM Data Replication 11.4.0.4? Though IBM states it supports Oracle, there is no clear cut documentation on how to provide the input parameters like the TNS names inside either the IIDR configuration tool or the Management Console.

    IIDR Configuration not allowing Oracle Parameters▾

    Management Console not allowing Oracle either▾

  • r

    rss

    01/21/2023, 3:17 AM
    Schema Registry URL for IIDR CDC Kafka subscription I have created a cluster Amazon MSK. Also, created an EC2 instance and installed Kafka on it to create a topic in Amazon MSK. I am able to produce/consume messages on the topic using Kafka scripts. I have also installed the IIDR Replication agent on an EC2 instance. The plan is to migrate DB2 table data into the Amazon MSK topic. In the IDR Management console, I am able to add the IIDR replication server as the target. Now when creating the subscription, it is asking for ZooKeeper URL and...
  • r

    rss

    01/27/2023, 2:47 PM
    sql: converting argument $1 type: unsupported type gorm.DB, a struct Have this: orm.DB.Table("users", orm.DB.Model(&[]models.User{})).Find(&users) Got this: sql: converting argument $1 type: unsupported type gorm.DB, a struct
  • r

    rss

    01/27/2023, 2:47 PM
    How to perform count and select in a single query? So in a blog application I am building, I have two tables: // Post model type Post struct { Id int
    json:"id" gorm:"primaryKey"
    OwnerId int `json:"owner_id" // foreign key to User model Title string
    json:"title"
    Body string
    json:"body"
    Likes []Like
    json:"likes"
    } // Like model type Like struct { PostId int
    json:"post_id"
    // foreign key to Post model LikerId int
    json:"liker_id"
    // foreign key to User model } I want to run a query which gets...
  • r

    rss

    01/27/2023, 2:47 PM
    Create Query 'has one' relationship in reverse direction GORM I am currently trying to create a new record using GORM and these two models has a one to one relationship with each other. Model1 has 'has one' relationship with Model2. I was thinking if it is possible to create query Model2 instead of Model1 in this case. Here is an example from the docs:

    https://i.stack.imgur.com/dqk7T.png▾

    So in the docs context, is it possible to create query from the CreditCard struct as I want to persist the 'has one' relationship.
  • r

    rss

    01/27/2023, 2:47 PM
    Not able to create Time data type column using gorm in go lang

    libraries▾

    Here is my struct▾

    Here is how I connect with database▾

    Here is How I do auto migrate ▾

    <a href="https://i.stack.imgur.com/PGxA7.png" rel="nofollow noreferrer">Here is my database...
  • r

    rss

    01/27/2023, 2:47 PM
    Gorm preload gives ambiguous column error I have following structs type Employee struct { EmployeeID int64
    gorm:"primary_key;column:employee_id"
    EmployeeCode string
    gorm:"column:employee_code"
    FirstName string
    gorm:"column:first_name"
    LastName string
    gorm:"column:last_name"
    DesignationID int64
    gorm:"column:designation_id;"
    Designation *Designation
    gorm:"foreignkey:DesignationID"
    } type Designation struct { DesignationID int64...
  • r

    rss

    01/27/2023, 2:47 PM
    GORM &lt;nil&gt; (\u003cnil\u003e) while Update database if res = db.Save(&msg); res.Error != nil { log.Error(err) return } I have simple code which is update column in database, but sometimes it gives me \u003cnil\u003e () instead of nil. Any reason or any experience who have ?
  • r

    rss

    01/27/2023, 2:47 PM
    '.Model' not working with '.Where' in GORM Model model := dbconn.Model(&database.Template{}).Where(?=ANY(tags), tagstring).Find(&templates) This GORM query does not work I'm using POSTGRES btw. The struct im working with here is: type Template struct { ID uint
    json:"template_id"
    Name string
    json:"template_name"
    FlowUI string
    json:"flowUI"
    Tags pq.StringArray
    gorm:"type:varchar(255)[]" json:"tags"
    } But if I instead do model := dbconn.Where(?=ANY(tags), tagstring).Find(&templates)...
  • r

    rss

    01/27/2023, 2:47 PM
    Unable to save the data in two different table in golang using gorm

    https://i.stack.imgur.com/bR3kd.jpg▾

    This is my code I'm not sure what went wrong the value which is in the user is getting updated in the user table properly but the address struct value is not storing the data in the address table I want to save two users and address table with one struct association please kindly help me out. Please Help me out db.Table(models.TABLE_USER).AutoMigrate(&models.User{})...
  • r

    rss

    01/27/2023, 2:47 PM
    GORM - uniqueIndex with soft delete I'm using Gorm's unique index to enforce a certain ordering of elements type Element struct { gorm.Model ID int
    gorm:"primary_key"
    Index int
    gorm:"uniqueIndex:unique_order"
    ParentID int
    gorm:"uniqueIndex:unique_order"
    } The problem I'm running into is when I create and delete multiple elements I start to get an error like ERROR: duplicate key value violates unique constraint "unique_order" (SQLSTATE 23505) This is happening...
  • r

    rss

    01/27/2023, 2:47 PM
    Inserting Array of Time in Postgres via Gorm While trying to insert into postgres db via gorm It is unable to convert time.Time information into timestamptz. The error message shown is: unable to encode time.Date(2023, time.January, 8, 1, 34, 22, 4178000, time.Local) into binary format for _timestamptz (OID 1185): cannot find encode plan I created the struct as follows: type Instance struct { UpdatedAt time.Time
    gorm:"index"
    InstanceId string
    gorm:"primaryKey"
    InstanceName string InstanceType string...
  • r

    rss

    01/27/2023, 2:47 PM
    GORM thread-safe connection I have simple code on golang which is executed while receive request and update a value on database. res := db.Where(ExampleStructforDB{Id: Id}).FirstOrCreate(&ls) if res.Error != nil { log.Error(res.Error) return res.Error } ls.count += 1 err = Db.Save(&ls).Error if err != nil { log.Error(err) return err } Sometimes I see that there is a race condition.Time-to-time some of the requests gets same value from database for updating.But in fact that, every...
  • r

    rss

    01/27/2023, 2:47 PM
    GORM and PostgreSQL: search_path is used only when doing the first request I'm currently working on an api gateway that forwards requests to an grpc client. The routes use a middleware. Within that middleware the Validate function from the dialed grpc client is used. The function is in the last code snippet at the end. The gateway is based on a gin router, which, as far as I understand handles each request in a separat go routine. I can send as many requests simultaneously to either to endpoint /protected/1 or to endpoint /protected/2 and they get handled...
  • r

    rss

    01/27/2023, 2:47 PM
    GORM v2 Many to Many does not create new record in join table Two structs Thread & Interest have a many to many relationship with each other. According to the documentation this is how both structs looks like: type Thread struct { ID uuid.UUID
    gorm:"primaryKey" json:"threadId"
    Title string
    gorm:"not null" json:"title"
    Body string
    gorm:"not null" json:"body"
    CreatedAt time.Time UpdatedAt time.Time // Foreign keys UserID uuid.UUID
    json:"userId"
    // Has many association Comments []Comment...
  • r

    rss

    01/27/2023, 2:47 PM
    Is it possible to change the database type of an enum in gorm (using postgres)? I wonder if its possible to change the datatype of an enum in gorm when it has the same underlying type? So say this is my current model type A type typeA int32 const ( field1 typeA = 0 field2 typeA = 1 field3 typeA = 2 ) type typeB int32 const ( field1 typeB = 0 field2 typeB = 1 field3 typeB = 2 ) And I have my gorm model like this type MyModel struct { gorm.Model SomeField typeA } I wonder if I...
  • r

    rss

    01/27/2023, 2:47 PM
    Rewrite query with union in subquery by using gorm I am trying to write sql query by using gorm. Here the query SELECT * FROM ( SELECT unnest(tags) as tag_name FROM models union all SELECT unnest(system_tags) from models left join projects on projects.id = models.project_id WHERE (projects.is_public = true )) as tD WHERE LOWER( tD.tag_name ) LIKE '%12%' ORDER BY tag_name I tried to create subquery. But cant figure out how to add union. As I understand select does not work this way. Is using Raw() my only option? selectStr...
  • r

    rss

    01/27/2023, 2:47 PM
    Insert into multiple tables on one transaction using GORM I'm trying to store information in 3 tables in a single transaction using GORM. I need to create just one row on Table1 and Table2 and multiple records on Table3 type Table1 struct { Id uuid.UUID
    gorm:"type:uuid;primary_key;default:uuid_generate_v4()"
    } type Table2 struct { Id uuid.UUID
    gorm:"type:uuid;primary_key;default:uuid_generate_v4()"
    Table2ID uuid.UUID
    gorm:"type:uuid;default:uuid_generate_v4()"
    Table2 Table2 } type Table3 struct...
  • r

    rss

    01/27/2023, 2:47 PM
    Go Gin Gorm how can you combine both has many and belongs to? I have two structs Thread and User. User currently has a 'has many' relationship with Thread. The two structs are: type Thread struct { ID uuid.UUID
    gorm:"primaryKey" json:"threadId"
    Title string
    gorm:"not null" json:"title"
    Body string
    gorm:"not null" json:"body"
    CreatedAt time.Time
    json:"createdAt"
    UpdatedAt time.Time
    json:"updatedAt"
    // Foreign keys UserID uuid.UUID
    json:"userId"
    // Has many association Comments...
  • r

    rss

    01/27/2023, 2:47 PM
    How do I get Failed results when using GORM batch creation? I am trying to create records using the Gorm CreateInBatches method. I do not want to fail the complete batch operation if there is any conflict so I am using the gorm clause to ignore conflicts, but I am unable to get failed records with this approach. Is there a way to get the failed records when using batching with ignore clause in Gorm? code: gormDbClient.Clauses(clause.OnConflict{DoNothing: true}).CreateInBatches(users, 500)
  • r

    rss

    01/27/2023, 2:47 PM
    Gorm delete with clauses sqlmock test I have a Gorm delete with the returning result: expirationDate := time.Now().UTC().Add(-(48 * time.hour)) var deletedUsers Users res := gormDB.WithContext(ctx). Table("my_users"). Clauses(clause.Returning{Columns: []clause.Column{{Name: "email"}}}). Where("created_at < ?", expirationDate). Delete(&deletedUsers) Now the test with clauses always fails. e.g. : sqlMock.ExpectExec(
    DELETE
    ) .WithArgs(expirationDate) .WillReturnResult(sqlmock.NewResult(1, 1)) Receiving...
  • r

    rss

    01/27/2023, 2:47 PM
    How to view the SQL query being run while using go gorm? [duplicate] I am working on crud api using go-gorm. I want to log the exact query which is being executed on the database when I run the code(like in hibernate). For example when db.Create(&user) is executed . It should log INSERT INTO
    users
    (
    name
    ,
    age
    ,
    created_at
    ) VALUES ("jinzhu", 18, "2020-07-04 11:05:21.775") What configuration should I do to achieve this ?
  • r

    rss

    01/27/2023, 2:47 PM
    How to create association only if it doesn't exist? (GORM) I am looping through an array of strings to create an document with that property ONLY if it doesn't exist: (dbi: my GORM database instance) var postTags []models.Tag for _, tagSlug := range tagsArray { tag := models.Tag{ Slug: tagSlug, } err = dbi.Where("slug = ?", tagSlug).FirstOrCreate(&tag).Error if err != nil { return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{ "error": "Internal Server Error", }) }...
  • r

    rss

    01/27/2023, 2:47 PM
    Problem writing a unit test using gorm and sql-mock this is my funckion using package testing, gorm and sql-mock: func Test_Create(t *testing.T) { db, mock, err := sqlmock.New() if err != nil { t.Errorf("Failed to open mock sql db, got error: %v", err) } if db == nil { t.Error("db is null") } if mock == nil { t.Error("mock is null") } defer db.Close() pDb, err := gorm.Open(postgres.New(postgres.Config{ PreferSimpleProtocol: false, DriverName: "postgres",...
  • r

    rss

    01/27/2023, 2:47 PM
    gorm queries apparently running twice when using in a fiber app hello i am studying gofiber, i am using GORM and github.com/morkid/paginate, i got something odd , i think, the query to fetch my data is running twice, is that correct? this is the code func GetAllPost(c *fiber.Ctx) error { var posts []models.Post model := initializers.DB.Find(&posts) return c.JSON(fiber.Map{ "data": pg.With(model).Request(c.Request()).Response(&[]models.Post{}), }) } this is the response { "data": { "items": [ {...
  • r

    rss

    01/27/2023, 2:47 PM
    how to remove some elements from the response in golang I am studying gofiber, I am using GORM and github.com/morkid/paginate, I want to remove the child element from the response. this is the response { "data": { "items": [ { "ID": 1, "CreatedAt": "2023-01-22T02:33:12.604+08:00", "UpdatedAt": "2023-01-22T02:33:12.604+08:00", "DeletedAt": null, "email": "ilham@mail.com", "username": "", "names": "",...
  • r

    rss

    01/27/2023, 2:47 PM
    Single Table Inheritance in Go using gorm I want to achive Single Table Inheritance in Go using gorm library, but i can't find a way to do it or any documentation related to it. Do anyone have already done that or knows about it? I tried gorm:"discriminator" and gorm:"discriminator:value" but it's not working.
  • r

    rss

    01/27/2023, 2:47 PM
    GORM scanrows vs scan in a raw query I found out I got different results using ScanRows or Scan. if I use: err=models.DB.ScanRows(nodes, &node) I get empty values in some fields. If I replace the structure node for all the attributes: err = nodes.Scan(&node.NodoId, &node.NodoIdPadre, &node.TipoNodo, &node.SubFormulaId, &node.FuncionId, &node.TipoTerminoId, &node.TerminoId,&node.FuncionDesc, &node.CodFormula, &node.TipoTerminoDesc, &node.DescTipoNodo, &node.OperadorId, &node.Operador ) It does not have any NULL...
  • r

    rss

    01/27/2023, 2:47 PM
    Using Gorm model with custom sequence I have a seq 'user_tfa_info_seq' which I want to use in 'user_tfa_info' table in Gorm Model. I used the following structure, but it does not work. type UserTfaInfo struct{ ID uint
    gorm:"primary_key;type:bigint(20) not null" sql:"nextval('user_tfa_info_seq')"
    }
  • r

    rss

    01/27/2023, 2:47 PM
    How to create a new instance of a struct that is read from file I know this may seem like bad design (and I wish I didn't need to do this), but I need to read a struct that is generated automatically at run time and create a new instance of it. The struct that I create I only need limited metadata of so that it can be passed to the Gorm Gen FieldRelateModel method (from here) where 'relModel' is the new instance I am hoping...
Powered by Linen
Title
r

rss

01/27/2023, 2:47 PM
How to create a new instance of a struct that is read from file I know this may seem like bad design (and I wish I didn't need to do this), but I need to read a struct that is generated automatically at run time and create a new instance of it. The struct that I create I only need limited metadata of so that it can be passed to the Gorm Gen FieldRelateModel method (from here) where 'relModel' is the new instance I am hoping...
View count: 1