go-xorm / xorm

Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
BSD 3-Clause "New" or "Revised" License
6.67k stars 754 forks source link

Using raw db connection for creating object #721

Open snktagarwal opened 7 years ago

snktagarwal commented 7 years ago

Hi Xorm team,

Firstly thanks for writing this awesome ORM tool! Golang is still in its initial stages so its good to see some mature code out there!

I am using Google's Cloud offering and they have a CloudSql proxy (which talks mysql internally). Although since your constructor does not take an actual db object (and say that it's SQL) I cannot use xorm unless I deconstruct either yours or cloudsql proxy code.

This is how I currently instantiate an object in my code:

config.Addr = instanceName config.User = dbUser config.Passwd = dbPass config.DBName = dbName db, err = cloudsqldialer.DialCfg(&config)

The code for cloudsql is here: github.com/GoogleCloudPlatform/cloudsql-proxy

Any help appreciated

lunny commented 7 years ago

I think maybe you can copy mysql dialect and change something to do that. XORM needs to know the SQL syntax which you are using, MySQL or Postgres. So a raw DB is not enough. But if XORM know the raw DB and the it's MySQL syntax it will work. But it also has some work to do.