good morning!!!!

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

Removing custom tx (duplicated functionality).

parent be92d139
No related branches found
No related tags found
No related merge requests found
...@@ -34,9 +34,9 @@ type Database interface { ...@@ -34,9 +34,9 @@ type Database interface {
type BaseDatabase struct { type BaseDatabase struct {
partial PartialDatabase partial PartialDatabase
sess *sqlx.DB sess *sqlx.DB
tx *sqltx.Tx
connURL db.ConnectionURL connURL db.ConnectionURL
tx *sqltx.Tx
schema *schema.DatabaseSchema schema *schema.DatabaseSchema
cachedStatements *cache.Cache cachedStatements *cache.Cache
collections map[string]db.Collection collections map[string]db.Collection
...@@ -250,6 +250,9 @@ func (d *BaseDatabase) Builder() db.QueryBuilder { ...@@ -250,6 +250,9 @@ func (d *BaseDatabase) Builder() db.QueryBuilder {
// Driver returns the underlying *sqlx.DB instance. // Driver returns the underlying *sqlx.DB instance.
func (d *BaseDatabase) Driver() interface{} { func (d *BaseDatabase) Driver() interface{} {
if d.tx != nil {
return d.tx.Tx
}
return d.sess return d.sess
} }
......
...@@ -23,8 +23,14 @@ package sqltx ...@@ -23,8 +23,14 @@ package sqltx
import ( import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"upper.io/db"
) )
type Database struct {
db.Database
*Tx
}
type Tx struct { type Tx struct {
*sqlx.Tx *sqlx.Tx
done bool done bool
......
...@@ -30,6 +30,7 @@ import ( ...@@ -30,6 +30,7 @@ import (
"upper.io/builder/sqlgen" "upper.io/builder/sqlgen"
"upper.io/db" "upper.io/db"
"upper.io/db/internal/sqladapter" "upper.io/db/internal/sqladapter"
"upper.io/db/internal/sqlutil/tx"
) )
type database struct { type database struct {
...@@ -174,7 +175,7 @@ func (d *database) Transaction() (db.Tx, error) { ...@@ -174,7 +175,7 @@ func (d *database) Transaction() (db.Tx, error) {
clone.BindTx(sqlTx) clone.BindTx(sqlTx)
return &tx{Tx: clone.Tx(), database: clone}, nil return &sqltx.Database{Database: clone, Tx: clone.Tx()}, nil
} }
// PopulateSchema looks up for the table info in the database and populates its // PopulateSchema looks up for the table info in the database and populates its
......
// Copyright (c) 2012-2015 The upper.io/db authors. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package postgresql
import (
"upper.io/db"
"upper.io/db/internal/sqlutil/tx"
)
type tx struct {
*sqltx.Tx
*database
}
var _ = db.Tx(&tx{})
// Driver returns the current transaction session.
func (t *tx) Driver() interface{} {
if t != nil && t.Tx != nil {
return t.Tx.Tx
}
return nil
}
// Commit commits the current transaction.
func (t *tx) Commit() error {
if err := t.Tx.Commit(); err != nil {
return err
}
return nil
}
// Rollback discards the current transaction.
func (t *tx) Rollback() error {
if err := t.Tx.Rollback(); err != nil {
return err
}
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment