Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialect/sql: add New method to pass in a river without opening a *sql… #2504

Merged
merged 1 commit into from Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions dialect/sql/driver.go
Expand Up @@ -20,18 +20,23 @@ type Driver struct {
dialect string
}

// NewDriver creates a new Driver with the given Conn and dialect.
func NewDriver(c Conn, d string) *Driver {
return &Driver{c, d}
}

// Open wraps the database/sql.Open method and returns a dialect.Driver that implements the an ent/dialect.Driver interface.
func Open(driver, source string) (*Driver, error) {
db, err := sql.Open(driver, source)
if err != nil {
return nil, err
}
return &Driver{Conn{db}, driver}, nil
return NewDriver(Conn{db}, driver), nil
}

// OpenDB wraps the given database/sql.DB method with a Driver.
func OpenDB(driver string, db *sql.DB) *Driver {
return &Driver{Conn{db}, driver}
return NewDriver(Conn{db}, driver)
}

// DB returns the underlying *sql.DB instance.
Expand Down