add set db to dialect

This commit is contained in:
Lunny Xiao 2014-04-18 18:39:59 +08:00
parent 9d0a49a52c
commit ea82aa0fbf
2 changed files with 10 additions and 4 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.db

View File

@ -24,8 +24,9 @@ type Uri struct {
// a dialect is a driver's wrapper
type Dialect interface {
Init(*Uri, string, string) error
Init(*DB, *Uri, string, string) error
URI() *Uri
DB() *DB
DBType() DbType
SqlType(*Column) string
@ -64,16 +65,20 @@ func OpenDialect(dialect Dialect) (*DB, error) {
}
type Base struct {
db *DB
dialect Dialect
driverName string
dataSourceName string
*Uri
}
func (b *Base) Init(dialect Dialect, uri *Uri, drivername, dataSourceName string) error {
b.dialect = dialect
func (b *Base) DB() *DB {
return b.db
}
func (b *Base) Init(db *DB, dialect Dialect, uri *Uri, drivername, dataSourceName string) error {
b.db, b.dialect, b.Uri = db, dialect, uri
b.driverName, b.dataSourceName = drivername, dataSourceName
b.Uri = uri
return nil
}