tsenart / nap

A Go sql.DB wrapper for master-slave topologies
http://godoc.org/github.com/tsenart/pan
MIT License
190 stars 40 forks source link

Port to gorm #13

Open rgautam98 opened 5 years ago

rgautam98 commented 5 years ago

Can I use this with the gorm(https://github.com/jinzhu/gorm).

If yes, can you give any example code(noob here).

zsichen commented 4 years ago

Hi, I'm trying to use this on gorm too. And I made a wrapper on it try to act as a driver. but I got some error. image and here is my code

package driver

import (
    "database/sql"
    "database/sql/driver"
    "github.com/go-sql-driver/mysql"
    "github.com/tsenart/nap"
)

type MySQLSplitDriver struct {
    mysql.MySQLDriver
}

func (d MySQLSplitDriver) Open(dsn string) (driver.Conn, error) {
    return nap.Open("mysql", dsn)
}

func init() {
    sql.Register("mysqlsplit", &MySQLSplitDriver{})
}

I think this might be a decent way to use it. Could you make a fix?