|  | @@ -1,13 +1,15 @@
 | 
	
		
			
				|  |  |  package nosql
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import (
 | 
	
		
			
				|  |  | -	"database/sql"
 | 
	
		
			
				|  |  | +	"context"
 | 
	
		
			
				|  |  |  	"encoding/json"
 | 
	
		
			
				|  |  |  	"fmt"
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	"github.com/jackc/pgx/v5"
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // OpenTXMethod is callback functon to open transaction in NoSQL object
 | 
	
		
			
				|  |  | -type OpenTXMethod func() (*sql.Tx, error)
 | 
	
		
			
				|  |  | +type OpenTXMethod func(context.Context) (pgx.Tx, error)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // NoSQL object
 | 
	
		
			
				|  |  |  type NoSQL struct {
 | 
	
	
		
			
				|  | @@ -20,35 +22,35 @@ func New(openMethod OpenTXMethod) *NoSQL {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // CallJSON accepts raw json bytes and returns result raw json bytes
 | 
	
		
			
				|  |  | -func (_self *NoSQL) CallJSON(function string, rawJSON []byte) (resRawJSON []byte, err error) {
 | 
	
		
			
				|  |  | +func (_self *NoSQL) CallJSON(ctx context.Context, function string, rawJSON []byte) (resRawJSON []byte, err error) {
 | 
	
		
			
				|  |  |  	// open tx
 | 
	
		
			
				|  |  | -	var tx *sql.Tx
 | 
	
		
			
				|  |  | -	if tx, err = _self.openMethod(); err == nil {
 | 
	
		
			
				|  |  | +	var tx pgx.Tx
 | 
	
		
			
				|  |  | +	if tx, err = _self.openMethod(ctx); err == nil {
 | 
	
		
			
				|  |  |  		// execute query and scan result
 | 
	
		
			
				|  |  | -		row := tx.QueryRow(fmt.Sprintf("select * from %v($1)", function), rawJSON)
 | 
	
		
			
				|  |  | +		row := tx.QueryRow(context.Background(), fmt.Sprintf("select * from %v($1)", function), rawJSON)
 | 
	
		
			
				|  |  |  		if err = row.Scan(&resRawJSON); err != nil {
 | 
	
		
			
				|  |  | -			tx.Rollback()
 | 
	
		
			
				|  |  | +			tx.Rollback(context.Background())
 | 
	
		
			
				|  |  |  			return
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		err = tx.Commit()
 | 
	
		
			
				|  |  | +		err = tx.Commit(context.Background())
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	return
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // CallObjParam accepts interface{} object and returns result raw json bytes
 | 
	
		
			
				|  |  | -func (_self *NoSQL) CallObjParam(function string, data interface{}) (resRawJSON []byte, err error) {
 | 
	
		
			
				|  |  | +func (_self *NoSQL) CallObjParam(ctx context.Context, function string, data interface{}) (resRawJSON []byte, err error) {
 | 
	
		
			
				|  |  |  	// convert incoming object to raw json
 | 
	
		
			
				|  |  |  	var raw []byte
 | 
	
		
			
				|  |  |  	if raw, err = json.Marshal(data); err != nil {
 | 
	
		
			
				|  |  |  		return
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  | -	return _self.CallJSON(function, raw)
 | 
	
		
			
				|  |  | +	return _self.CallJSON(ctx, function, raw)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // Call accepts interface{} object and returns result interface{}
 | 
	
		
			
				|  |  | -func (_self *NoSQL) Call(function string, data interface{}) (res interface{}, err error) {
 | 
	
		
			
				|  |  | +func (_self *NoSQL) Call(ctx context.Context, function string, data interface{}) (res interface{}, err error) {
 | 
	
		
			
				|  |  |  	var resRawJSON []byte
 | 
	
		
			
				|  |  | -	if resRawJSON, err = _self.CallObjParam(function, data); err == nil {
 | 
	
		
			
				|  |  | +	if resRawJSON, err = _self.CallObjParam(ctx, function, data); err == nil {
 | 
	
		
			
				|  |  |  		// convert raw result data to obj
 | 
	
		
			
				|  |  |  		if len(resRawJSON) > 0 {
 | 
	
		
			
				|  |  |  			err = json.Unmarshal(resRawJSON, &res)
 | 
	
	
		
			
				|  | @@ -57,9 +59,9 @@ func (_self *NoSQL) Call(function string, data interface{}) (res interface{}, er
 | 
	
		
			
				|  |  |  	return
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -func (_self *NoSQL) CallObject(function string, data interface{}, resultObject interface{}) (err error) {
 | 
	
		
			
				|  |  | +func (_self *NoSQL) CallObject(ctx context.Context, function string, data interface{}, resultObject interface{}) (err error) {
 | 
	
		
			
				|  |  |  	var resRawJSON []byte
 | 
	
		
			
				|  |  | -	if resRawJSON, err = _self.CallObjParam(function, data); err == nil {
 | 
	
		
			
				|  |  | +	if resRawJSON, err = _self.CallObjParam(ctx, function, data); err == nil {
 | 
	
		
			
				|  |  |  		// convert raw result data to result object
 | 
	
		
			
				|  |  |  		err = json.Unmarshal(resRawJSON, resultObject)
 | 
	
		
			
				|  |  |  	}
 |