good morning!!!!

Skip to content
Snippets Groups Projects
Commit e87e430b authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Adding End and Begin statements. Closing #23.

parent 0edf73cc
Branches
Tags
No related merge requests found
...@@ -310,6 +310,16 @@ type Database interface { ...@@ -310,6 +310,16 @@ type Database interface {
Returns the name of the active database. Returns the name of the active database.
*/ */
Name() string Name() string
/*
Starts a transaction block.
*/
Begin() error
/*
Ends a transaction block.
*/
End() error
} }
// Collection methods. // Collection methods.
......
# gosexy/db/mongo # gosexy/db/mongo
Please read the full docs, acknowledgements and examples at [http://gosexy.org/db/wrappers/mongo](http://gosexy.org/db/wrappers/mongo). Please read the full docs, acknowledgements and examples at
[https://menteslibres.net/gosexy/db/wrappers/mongo][1].
[1]: https://menteslibres.net/gosexy/db/wrappers/mongo
...@@ -72,6 +72,24 @@ func (self *Source) Use(database string) error { ...@@ -72,6 +72,24 @@ func (self *Source) Use(database string) error {
return nil return nil
} }
/*
Starts a transaction block.
*/
func (self *Source) Begin() error {
// TODO:
// MongoDB does not supports something like BEGIN and END statements.
return nil
}
/*
Ends a transaction block.
*/
func (self *Source) End() error {
// TODO:
// MongoDB does not supports something like BEGIN and END statements.
return nil
}
// Returns a collection from the current database. // Returns a collection from the current database.
func (self *Source) Collection(name string) (db.Collection, error) { func (self *Source) Collection(name string) (db.Collection, error) {
var err error var err error
......
...@@ -237,6 +237,22 @@ func (self *Source) Use(database string) error { ...@@ -237,6 +237,22 @@ func (self *Source) Use(database string) error {
return err return err
} }
/*
Starts a transaction block.
*/
func (self *Source) Begin() error {
_, err := self.session.Exec(`BEGIN`)
return err
}
/*
Ends a transaction block.
*/
func (self *Source) End() error {
_, err := self.session.Exec(`END`)
return err
}
/* /*
Drops the currently active database. Drops the currently active database.
*/ */
......
...@@ -240,6 +240,22 @@ func (self *Source) Use(database string) error { ...@@ -240,6 +240,22 @@ func (self *Source) Use(database string) error {
return self.Open() return self.Open()
} }
/*
Starts a transaction block.
*/
func (self *Source) Begin() error {
_, err := self.session.Exec(`BEGIN`)
return err
}
/*
Ends a transaction block.
*/
func (self *Source) End() error {
_, err := self.session.Exec(`END`)
return err
}
/* /*
Drops the currently active database. Drops the currently active database.
*/ */
......
...@@ -223,6 +223,22 @@ func (self *Source) Use(database string) error { ...@@ -223,6 +223,22 @@ func (self *Source) Use(database string) error {
return err return err
} }
/*
Starts a transaction block.
*/
func (self *Source) Begin() error {
_, err := self.session.Exec(`BEGIN`)
return err
}
/*
Ends a transaction block.
*/
func (self *Source) End() error {
_, err := self.session.Exec(`END`)
return err
}
/* /*
Drops the currently active database. Drops the currently active database.
*/ */
......
...@@ -797,10 +797,7 @@ func BenchmarkAppendDbItem_Transaction(b *testing.B) { ...@@ -797,10 +797,7 @@ func BenchmarkAppendDbItem_Transaction(b *testing.B) {
people := sess.ExistentCollection("people") people := sess.ExistentCollection("people")
people.Truncate() people.Truncate()
driver := sess.Driver().(*sql.DB) err = sess.Begin()
b.ResetTimer()
_, err = driver.Exec(`BEGIN`)
if err != nil { if err != nil {
b.Fatalf(err.Error()) b.Fatalf(err.Error())
} }
...@@ -812,7 +809,7 @@ func BenchmarkAppendDbItem_Transaction(b *testing.B) { ...@@ -812,7 +809,7 @@ func BenchmarkAppendDbItem_Transaction(b *testing.B) {
} }
} }
_, err = driver.Exec(`END`) err = sess.End()
if err != nil { if err != nil {
b.Fatalf(err.Error()) b.Fatalf(err.Error())
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment