package pg

import (
	
	
	

	
	
)

// Connect connects to a database using provided options.
//
// The returned DB is safe for concurrent use by multiple goroutines
// and maintains its own connection pool.
func ( *Options) *DB {
	.init()
	return newDB(
		context.Background(),
		&baseDB{
			opt:   ,
			pool:  newConnPool(),
			fmter: orm.NewFormatter(),
		},
	)
}

func ( context.Context,  *baseDB) *DB {
	 := &DB{
		baseDB: .clone(),
		ctx:    ,
	}
	.baseDB.db = 
	return 
}

// DB is a database handle representing a pool of zero or more
// underlying connections. It's safe for concurrent use by multiple
// goroutines.
type DB struct {
	*baseDB
	ctx context.Context
}

var _ orm.DB = (*DB)(nil)

func ( *DB) () string {
	return fmt.Sprintf("DB<Addr=%q%s>", .opt.Addr, .fmter)
}

// Options returns read-only Options that were used to connect to the DB.
func ( *DB) () *Options {
	return .opt
}

// Context returns DB context.
func ( *DB) () context.Context {
	return .ctx
}

// WithContext returns a copy of the DB that uses the ctx.
func ( *DB) ( context.Context) *DB {
	return newDB(, .baseDB)
}

// WithTimeout returns a copy of the DB that uses d as the read/write timeout.
func ( *DB) ( time.Duration) *DB {
	return newDB(.ctx, .baseDB.WithTimeout())
}

// WithParam returns a copy of the DB that replaces the param with the value
// in queries.
func ( *DB) ( string,  interface{}) *DB {
	return newDB(.ctx, .baseDB.WithParam(, ))
}

// Listen listens for notifications sent with NOTIFY command.
func ( *DB) ( context.Context,  ...string) *Listener {
	 := &Listener{
		db: ,
	}
	.init()
	_ = .Listen(, ...)
	return 
}

// Conn represents a single database connection rather than a pool of database
// connections. Prefer running queries from DB unless there is a specific
// need for a continuous single database connection.
//
// A Conn must call Close to return the connection to the database pool
// and may do so concurrently with a running query.
//
// After a call to Close, all operations on the connection fail.
type Conn struct {
	*baseDB
	ctx context.Context
}

var _ orm.DB = (*Conn)(nil)

// Conn returns a single connection from the connection pool.
// Queries run on the same Conn will be run in the same database session.
//
// Every Conn must be returned to the database pool after use by
// calling Conn.Close.
func ( *DB) () *Conn {
	return newConn(.ctx, .baseDB.withPool(pool.NewStickyConnPool(.pool)))
}

func ( context.Context,  *baseDB) *Conn {
	 := &Conn{
		baseDB: ,
		ctx:    ,
	}
	.baseDB.db = 
	return 
}

// Context returns DB context.
func ( *Conn) () context.Context {
	if .ctx != nil {
		return .ctx
	}
	return context.Background()
}

// WithContext returns a copy of the DB that uses the ctx.
func ( *Conn) ( context.Context) *Conn {
	return newConn(, .baseDB)
}

// WithTimeout returns a copy of the DB that uses d as the read/write timeout.
func ( *Conn) ( time.Duration) *Conn {
	return newConn(.ctx, .baseDB.WithTimeout())
}

// WithParam returns a copy of the DB that replaces the param with the value
// in queries.
func ( *Conn) ( string,  interface{}) *Conn {
	return newConn(.ctx, .baseDB.WithParam(, ))
}