banner



Gorm Create Database if Not Exists

Paul I'm Paul, the bridge sends all matrix messages through a single bot

Paul so you got a gorm.DB struct

Jacob E. Shore

@DewofyourYouth

Oh, go it

Paul what was the function call you used to get it?

Jacob E. Shore

@DewofyourYouth

db.First

Paul you should pass db.First a pointer to the result

Paul and not look at the return value

Jacob E. Shore

@DewofyourYouth

this is what I did
first := db.First(&cktl, 1) fmt.Printf("%#v\n", *first)

Paul fmt.Printf("%v\n", cktl)

Paul first is not the result

Paul look at the quick start guide

Jacob E. Shore

@DewofyourYouth

ok, will look again, thanks

Dr. Doofenshmirtz

@noelukwa_twitter

                                                      type                    User                    struct                    {                      ID                      int                      `gorm:"AUTO_INCREMENT,primary_key"`                      Name                      string                      Age                      string                      Followers                      []User                      Following                      []User                      }                                                

But it doesnt show in my db

Please how do i model a has many relationship.. i've tried this but it doesnt work

Alessandro Sechi

@AlessandroSechi

Hello, is it possible to handle with gorm nested many to many relationships

Hi, can anyone please share a good doc link for querying postgres db tables using gorm??

Anyone have a good solution for left joins using the model?

I really dislike the thought of mixing sql into my server when it's built on gorm

I've tried many2many but it doesn't seem to be doing what I need it to

beforeUpdate hook does'nt seem to work can some one please help

When using : db, err := gorm.Open("mysql", "root:password1@(localhost:3308)/testdb?charset=utf8mb4&parseTime=True")
to create connection, if the "testdb" doesn't exist it throws me an error, is it possible for GORM to auto create DB if it doesn't exist upon connection?

Hey folks. I'm looking for some way to generate primary keys for join tables. I found db.Callback().Create().Before("gorm:create"), which allowed me to set missing ID's with a custom value for my models. Just need to do the same thing for join tables now... Any tips? Is it possible without assigning a custom JoinTableHandler for every association field?

(I'm phasing out an old DB solution in favor of Gorm, and I need to mimic its conventions for now)

Hello everyone, I'm not sure how to use jsonb properly with gorm ! (I don't want to use the postgres.Jsonb type in my models to stick with native types). I've explained this in details in a SO post https://stackoverflow.com/questions/60092840/string-to-jsonb-with-gorm-and-postgres. If someone knows how I can manage to do what I want it'd be great ! If you don't an upvote on the question would also be appreciated :) Thank you !

gokul

@gokulganesan_gitlab

Hi, I am new to using GORM and this might be a very dumb question sorry for that.

I tried to create a database using db.Exec method in there if the database is hardcoded like db.Exec("CREATE DATABASE mydb") it is working fine but when I try to use a placeholder like db.Exec("CREATE DATABASE ?", "mydb") it is failing with a sql syntax error. Can anyone help me with this please?

Paul I was going to guess that create database isn't allowed in prepared statements, but it seems it should be

Paul look at the sql server log?

gokul

@gokulganesan_gitlab

I am using postgres

Paul well, look at the postgres log

gokul

@gokulganesan_gitlab

db.Exec("CREATE DATABASE ?", "mydb") executes CREATE DATABASE $1 this statement in postgres.

when I try to change the Exec statement with $1 db.Exec("CREATE DATABASE $1", "mydb") I am getting the same error

Hello, are fk in auto migration are supported ?
like : db.AutoMigrate(Event{}).AddForeignKey("user_id", "users(id)", "RESTRICT", "RESTRICT")

Hi all, anyone have any idea whether transactions in gorm will roll back if there has been an update since the beginning of the transaction?

Paul that depends on isolation level

When I have a hierarchical model like this:

                                                type                  A                  struct                  {                    gorm.Model                    Name                    string                    Bs                    []B                    }                                                  type                  B                  struct                  {                    gorm.Model                    Name                    string                    Cs                    []C                    }                                                  type                  C                  struct                  {                    gorm.Model                    Name                    string                    }                                          

Do I need to define the relationships explicitly?

I tried this

                          db.AutoMigrate(&A{}, &B{}, &C{})      a := A{                              Name:              "Foo",                              Bs:              []B{             {                              Name:              "Test",                              Cs:              []C{                     {                              Name:              "foo",                     },                 },             },         },     }              db.Create(&namespace)              db.Save(&namespace)          

but that only creates a row on the root level.

The tables for B and C are there - but they stay empty.

Hi, I am using GORM on a POC project, where i have a custom Set{interface{}} implemented, and i am using this data structure as attributes in one of the entities. However the issue which i am facing is gorm complains saying
invalid sql type Set(interface{}) for mysql
should i make set implement some of the other interfaces to get it working ? Suggestions welcome. Thanks

Does gorm support INSERT IGNORE?

Hey everybody. Can I talk about the v2 of gorm here? I have some question

Gorm Create Database if Not Exists

Source: https://gitter.im/jinzhu/gorm?at=5e321d316f9d3d34980123ca

0 Response to "Gorm Create Database if Not Exists"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel