Start refactoring
This commit is contained in:
30
data/datasource/pgsql/pgsql.go
Normal file
30
data/datasource/pgsql/pgsql.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package pgsql
|
||||
|
||||
import (
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"opensavecloudserver/data/datasource"
|
||||
)
|
||||
|
||||
type (
|
||||
DatabaseDatasource struct {
|
||||
conn *gorm.DB
|
||||
}
|
||||
)
|
||||
|
||||
func NewDatabaseDatasource() datasource.Datasource {
|
||||
return new(DatabaseDatasource)
|
||||
}
|
||||
|
||||
func (dd *DatabaseDatasource) Connect(dsn string) error {
|
||||
conn, err := gorm.Open(postgres.Open(dsn))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dd.conn = conn
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dd *DatabaseDatasource) DB() *gorm.DB {
|
||||
return dd.conn
|
||||
}
|
||||
Reference in New Issue
Block a user