github.com/Ali-iotechsys/sqlboiler/v4@v4.0.0-20221208124957-6aec9a5f1f71/boil/global.go (about)

     1  package boil
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  var (
     8  	// currentDB is a global database handle for the package
     9  	currentDB        Executor
    10  	currentContextDB ContextExecutor
    11  	// timestampLocation is the timezone used for the
    12  	// automated setting of created_at/updated_at columns
    13  	timestampLocation = time.UTC
    14  )
    15  
    16  // SetDB initializes the database handle for all template db interactions
    17  func SetDB(db Executor) {
    18  	currentDB = db
    19  	if c, ok := currentDB.(ContextExecutor); ok {
    20  		currentContextDB = c
    21  	}
    22  }
    23  
    24  // GetDB retrieves the global state database handle
    25  func GetDB() Executor {
    26  	return currentDB
    27  }
    28  
    29  // GetContextDB retrieves the global state database handle as a context executor
    30  func GetContextDB() ContextExecutor {
    31  	return currentContextDB
    32  }
    33  
    34  // SetLocation sets the global timestamp Location.
    35  // This is the timezone used by the generated package for the
    36  // automated setting of created_at and updated_at columns.
    37  // If the package was generated with the --no-auto-timestamps flag
    38  // then this function has no effect.
    39  func SetLocation(loc *time.Location) {
    40  	timestampLocation = loc
    41  }
    42  
    43  // GetLocation retrieves the global timestamp Location.
    44  // This is the timezone used by the generated package for the
    45  // automated setting of created_at and updated_at columns
    46  // if the package was not generated with the --no-auto-timestamps flag.
    47  func GetLocation() *time.Location {
    48  	return timestampLocation
    49  }