db connect
This commit is contained in:
parent
6b367dbd7a
commit
754c6dd624
30
session.go
30
session.go
@ -10,6 +10,23 @@ var (
|
||||
ErrNotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
connection *mgo.Session
|
||||
}
|
||||
|
||||
func NewConnection(dial string) (*Connection, error) {
|
||||
connection, err := mgo.Dial(dial)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
connection.SetMode(mgo.Monotonic, true)
|
||||
return &Connection{connection: connection}, nil
|
||||
}
|
||||
|
||||
func (c *Connection) Close() {
|
||||
c.connection.Close()
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
session *mgo.Session
|
||||
}
|
||||
@ -18,17 +35,8 @@ func (s *Session) Close() {
|
||||
s.session.Close()
|
||||
}
|
||||
|
||||
func (s *Session) Copy() *Session {
|
||||
return &Session{session: s.session.Copy()}
|
||||
}
|
||||
|
||||
func NewSession(dial string) (*Session, error) {
|
||||
session, err := mgo.Dial(dial)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
session.SetMode(mgo.Monotonic, true)
|
||||
return &Session{session: session}, nil
|
||||
func (c *Connection) NewSession() (*Session, error) {
|
||||
return &Session{session: c.connection.Copy()}, nil
|
||||
}
|
||||
|
||||
type Database struct {
|
||||
|
Loading…
Reference in New Issue
Block a user