I'm developing an CRUD app. I'm reading an JSON from an api and I want to write this JSON in a database with "database/sql" and GORM in a spcific schema the struct:
type Veiculo struct {
gorm.Model
Codigo int `json:"vei_codigo"`
Placa string `json:"vei_placa"`
Nome string `json:"vei_nome"`
}
the endpoint function:
func CreateVeiculo(c *gin.Context) {
var veiculo model.Veiculo
//id := c.Params.ByName("id")
c.BindJSON(&veiculo)
c.JSON(200, veiculo)
psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+" password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
dbVeiculosGorm, err := gorm.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
defer dbVeiculosGorm.Close()
dbVeiculosGorm.AutoMigrate(&model.Veiculo{})
//t := time.Now()
//ts := t.Format("2006-01-02 15:04:05")
dbVeiculosGorm.Create(&model.Veiculo{Placa: veiculo.Placa, Nome: veiculo.Nome}
but the database is untouchable. There is multiple schemas. Do i have to set the specific schema?? What am i doing wrong?