These are chat archives for jinzhu/gorm

21st
May 2018
Rosa Imantoro
@rimantoro
May 21 2018 02:28
Hi,

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
go:
  build: ./app
  ports:
    - 8080:8080
  volumes:
    - ./app:/go/src/gorest_echo
  links:
    - mysql_server
mysql_server:
  image: mariadb:10.1
  environment:
    MYSQL_ROOT_PASSWORD: password
  ports:
    - 3306:3306
  restart: always
  volumes:
      - ./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 ?

Salamander
@salamander-mh
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
@rimantoro
May 21 2018 04:13
@salamander-mh
go_1            | ERROR: logging before flag.Parse: I0521 04:12:24.230159       1 client.go:54] 25
go_1            | echo: http: panic serving 172.17.0.1:38414: 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/github.com/rimantoro/gorest_echo/model.Database(0x7ea540)
go_1            |     /go/src/gorest_echo/vendor/github.com/rimantoro/gorest_echo/model/model.go:25 +0xb0
go_1            | gorest_echo/vendor/github.com/rimantoro/gorest_echo/client.GetTheList(0x1, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
go_1            |     /go/src/gorest_echo/vendor/github.com/rimantoro/gorest_echo/client/client_model.go:61 +0xcc
go_1            | gorest_echo/vendor/github.com/rimantoro/gorest_echo/client.GetList(0x8ea4c0, 0xc4202c2690, 0x0, 0x0)
go_1            |     /go/src/gorest_echo/vendor/github.com/rimantoro/gorest_echo/client/client.go:55 +0x138
go_1            | gorest_echo/vendor/github.com/labstack/echo.(*Echo).Add.func1(0x8ea4c0, 0xc4202c2690, 0x4, 0xc42021fd15)
go_1            |     /go/src/gorest_echo/vendor/github.com/labstack/echo/echo.go:482 +0x87
go_1            | gorest_echo/vendor/github.com/labstack/echo.(*Echo).ServeHTTP(0xc4200b8ea0, 0x8e6ac0, 0xc4202de000, 0xc4202cf800)
go_1            |     /go/src/gorest_echo/vendor/github.com/labstack/echo/echo.go:594 +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
Salamander
@salamander-mh
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 172.17.0.1:38414: failed to connect database
Rosa Imantoro
@rimantoro
May 21 2018 06:38
Thats why I’m confuse
on my model, I’m stating to connect to mysql 3306
Ben Burleson
@benburleson
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
@benburleson
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 :-(