feat: define xorm.FromDialectAndDB #1812

Merged
lunny merged 2 commits from jumpeiMano/xorm:add-from-db into master 11 months ago

Hi! I use your greate library, xorm.

I'd like to use xorm.Engine with my own *sql.DB instances. Because I also want to use SessionResetter interface, so I want to call sql.OpenDB to create my own *sql.DB instance before creating *xorm.Engine instance.

So I define FromDialectAndDB function in package xorm.

Thanks!

Hi! I use your greate library, `xorm`. I'd like to use xorm.Engine with my own *sql.DB instances. Because I also want to use [SessionResetter](https://github.com/golang/go/blob/9499a2e108/src/database/sql/driver/driver.go#L291) interface, so I want to call [sql.OpenDB](https://github.com/golang/go/blob/9499a2e108/src/database/sql/sql.go#L730) to create my own *sql.DB instance before creating *xorm.Engine instance. So I define `FromDialectAndDB` function in package `xorm`. Thanks!
jumpeiMano added 1 commit 11 months ago
lunny reviewed 11 months ago
Dismissed
engine.go Outdated
// If you do not want to use your own dialect or db, please use NewEngine.
// For creating dialect, you can call dialects.OpenDialect. And, for creating db,
// you can call core.Open or core.FromDB.
func FromDialectAndDB(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error) {
Poster
Owner

How about rename it NewEngineWith.... to keep consistent with NewEngineWithParams.

How about rename it `NewEngineWith....` to keep consistent with `NewEngineWithParams`.
Poster

@lunny Thanks for your reviewng. I fixed it!
fa7f45555f

@lunny Thanks for your reviewng. I fixed it! https://gitea.com/xorm/xorm/commit/fa7f45555f1232c2c62e2701be1680b8e644764d
lunny marked this conversation as resolved
lunny added the
kind/feature
label 11 months ago
jumpeiMano added 1 commit 11 months ago
lunny approved these changes 11 months ago
Dismissed
lunny merged commit 17f28a1314 into master 11 months ago
The pull request has been merged as 17f28a1314.
Sign in to join this conversation.
Loading…
There is no content yet.