Marcel J.B
Marcel J.B

Reputation: 1

Cannot write to mySQL db or read from it in my buffalo application

Currently i have the problem, that my buffalo application cannot write to my MySQL db or read from it. But in the logs no errors occurring.

My database.yml file

development:
  dialect: "mysql"
  database: "test_buff"
  host: "localhost"
  port: "3306"
  user: "root"
  password: "password"

worker.go

I created this model with POP.

type Worker struct {
ID        uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
Name      string    `json:"name" db:"name"`
Age       int   `json:"age" db:"age"`
Plz       string    `json:"plz" db:"plz"`

}

models.go (auto generated)

// DB is a connection to your database to be used
// throughout your application.
var DB *pop.Connection

func init() {
    var err error
    env := envy.Get("GO_ENV", "development")
    DB, err = pop.Connect(env)
    if err != nil {
        log.Fatal(err)
    }
    pop.Debug = env == "development"
}

home.go

a := models.Worker{}
tx, ok := c.Value("tx").(*pop.Connection)
if !ok {
    //
}
tx.All(&a)

If i use another mySql driver(not the buffalo) than it works. So it might be a problem with the buffalo framework

Code with the other driver

db, err := sql.Open("mysql", "root:password@/test_buff")

Upvotes: 0

Views: 263

Answers (0)

Related Questions