Hello,
I’m trying to switch from mongo to postgres in a restful api. The code is from Shiju Varghese’s book “Web Development with Go”, which is quite excellent. I was wondering if there are matching calls for mgo.session and mgo.collection in database/sql or pq.
This is the code for getting the mgo.session:
func GetSession() *mgo.Session { if session == nil { var err error session, err = mgo.DialWithInfo(&mgo.DialInfo{ Addrs: []string{AppConfig.MongoDBHost}, Username: AppConfig.DBUser, Password: AppConfig.DBPwd, Timeout: 60 * time.Second, }) if err != nil { log.Fatalf("[GetSession]: %s\n", err) } } return session }
This is the code for the collection:
func (c *Context) DbCollection(name string) *mgo.Collection { return c.MongoSession.DB(common.AppConfig.Database).C(name) }
I think mgo.session should be equivalent to sql.db, but I have no idea how to get the tables from pq or database/sql as in mgo.collection.
Thank you very much for your help,
James