These are chat archives for jinzhu/gorm

May 2018
Rosa Imantoro
May 21 2018 02:28

Is there any issue when using gorm on Docker ?

I have this line of code for create new connection

db, err := gorm.Open("mysql", “root:password@tcp(mysql_server:3306)/gorest?charset=utf8&parseTime=True&loc=Local")
    if err != nil {
        panic("failed to connect database")
and this is my docker compose
  build: ./app
    - 8080:8080
    - ./app:/go/src/gorest_echo
    - mysql_server
  image: mariadb:10.1
    - 3306:3306
  restart: always
      - ./data/mysql:/var/lib/mysql
      - ./mysql-custom.cnf:/etc/mysql/conf.d/mysql-custom.cnf

its always return error with failed to connect db error.

Is there something I missed in my code ?

May 21 2018 03:33
@rimantoro view the err details
it has nothing to do with docker. it's just a simple problem
Rosa Imantoro
May 21 2018 04:13
go_1            | ERROR: logging before flag.Parse: I0521 04:12:24.230159       1 client.go:54] 25
go_1            | echo: http: panic serving failed to connect database
go_1            | goroutine 6 [running]:
go_1            | net/http.(*conn).serve.func1(0xc4202bd2c0)
go_1            |     /usr/local/go/src/net/http/server.go:1726 +0xd0
go_1            | panic(0x7f29a0, 0x8e1560)
go_1            |     /usr/local/go/src/runtime/panic.go:502 +0x229
go_1            | gorest_echo/vendor/
go_1            |     /go/src/gorest_echo/vendor/ +0xb0
go_1            | gorest_echo/vendor/, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
go_1            |     /go/src/gorest_echo/vendor/ +0xcc
go_1            | gorest_echo/vendor/, 0xc4202c2690, 0x0, 0x0)
go_1            |     /go/src/gorest_echo/vendor/ +0x138
go_1            | gorest_echo/vendor/*Echo).Add.func1(0x8ea4c0, 0xc4202c2690, 0x4, 0xc42021fd15)
go_1            |     /go/src/gorest_echo/vendor/ +0x87
go_1            | gorest_echo/vendor/*Echo).ServeHTTP(0xc4200b8ea0, 0x8e6ac0, 0xc4202de000, 0xc4202cf800)
go_1            |     /go/src/gorest_echo/vendor/ +0x250
go_1            | net/http.serverHandler.ServeHTTP(0xc420099040, 0x8e6ac0, 0xc4202de000, 0xc4202cf800)
go_1            |     /usr/local/go/src/net/http/server.go:2694 +0xbc
go_1            | net/http.(*conn).serve(0xc4202bd2c0, 0x8e6e40, 0xc4202cde40)
go_1            |     /usr/local/go/src/net/http/server.go:1830 +0x651
go_1            | created by net/http.(*Server).Serve
go_1            |     /usr/local/go/src/net/http/server.go:2795 +0x27b
May 21 2018 05:31
@rimantoro your db port is 38414? but your code shows you want to use 3306
Look at this line.
echo: http: panic serving failed to connect database
Rosa Imantoro
May 21 2018 06:38
Thats why I’m confuse
on my model, I’m stating to connect to mysql 3306
Ben Burleson
May 21 2018 22:51
I have a set of dynamically generated tables with table names that can contain parentheses. I’m using db.Table(table) to set the table name and some plain SQL queries to get data. Using the gorm Debug functionality, it looks like the table name is wrapped in ticks, but MySQL is complaining about the parentheses Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1)xlsx' Where the table name is factor_1768_24522017 (1)xlsx
Anybody know any tricks to allow this?
It seems like the debug output shows ticks around the table name, but maybe it’s not actually using those when sending the query to mysql??
Ben Burleson
May 21 2018 23:19
fwiw, I figured out if I wrap the table name in back ticks if the table name has ( in it, then the queries behave as expected. But if i ALWAYS wrap the table name with back ticks, queries against table names without ( error :-(