Documentation ¶
Index ¶
- type Cursor
- func (r *Cursor) Close()
- func (r *Cursor) CommandTag() pgconn.CommandTag
- func (r *Cursor) Conn() *pgx.Conn
- func (r *Cursor) Err() error
- func (r *Cursor) FieldDescriptions() []pgconn.FieldDescription
- func (r *Cursor) Next() bool
- func (r *Cursor) RawValues() [][]byte
- func (r *Cursor) Scan(dest ...any) error
- func (r *Cursor) Values() ([]any, error)
- type Querier
- type Queryable
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is a wrapper around pgx.Cursor.
func (*Cursor) CommandTag ¶
func (r *Cursor) CommandTag() pgconn.CommandTag
CommandTag implements pgx.Rows.
func (*Cursor) FieldDescriptions ¶
func (r *Cursor) FieldDescriptions() []pgconn.FieldDescription
FieldDescriptions implements pgx.Rows.
type Querier ¶
type Querier struct { // Capacity is the maximum number of rows to fetch for each iteration. Capacity int // Querier is the interface that wraps the Query method. Querier Queryable }
Querier represents a PostgreSQL cursor querier.
Example ¶
config, err := pgxpool.ParseConfig(os.Getenv("PGX_DATABASE_URL")) if err != nil { panic(err) } conn, err := pgxpool.NewWithConfig(context.TODO(), config) if err != nil { panic(err) } // close the pool defer conn.Close() querier := &pgxiter.Querier{Querier: conn} // start the cursor rows, err := querier.Query(context.TODO(), "SELECT * FROM user") if err != nil { panic(err) } // close the cursor defer rows.Close() // User represents a user. type User struct { Name string `db:"name"` Password string `db:"password"` } for rows.Next() { user, err := pgx.RowToStructByName[User](rows) if err != nil { panic(err) } fmt.Println(user.Name) }
Output:
type Queryable ¶
type Queryable interface { // Begin starts a pseudo nested transaction. Begin(ctx context.Context) (pgx.Tx, error) // Exec executes a query that doesn't return rows. Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error) // Query executes a query that returns rows. Query(ctx context.Context, query string, args ...any) (pgx.Rows, error) }
Queryable is the interface that wraps the Query method.
Click to show internal directories.
Click to hide internal directories.