github.com/mitranim/gg@v0.1.17/gsql/gsql_constraints.go (about)

     1  package gsql
     2  
     3  import (
     4  	"context"
     5  	"database/sql"
     6  	"io"
     7  
     8  	"github.com/mitranim/gg"
     9  )
    10  
    11  // Implemented by stdlib types such as `sql.DB`.
    12  type Db interface {
    13  	DbConn
    14  	DbTxer
    15  }
    16  
    17  // Implemented by stdlib types such as `sql.DB`.
    18  type DbTxer interface {
    19  	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
    20  }
    21  
    22  // Implemented by stdlib types such as `sql.Conn` and `sql.Tx`.
    23  type DbConn interface {
    24  	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
    25  	ExecContext(context.Context, string, ...any) (sql.Result, error)
    26  }
    27  
    28  // Implemented by stdlib types such as `sql.Tx`.
    29  type DbTx interface {
    30  	DbConn
    31  	Commit() error
    32  	Rollback() error
    33  }
    34  
    35  // Interface of `sql.Rows`. Used by various scanning tools.
    36  type Rows interface {
    37  	io.Closer
    38  	gg.Errer
    39  	gg.Nexter
    40  	ColumnerScanner
    41  }
    42  
    43  // Sub-interface of `Rows` used by `ScanNext`.
    44  type ColumnerScanner interface {
    45  	Columns() ([]string, error)
    46  	Scan(...any) error
    47  }