good morning!!!!

Skip to content
Snippets Groups Projects
query.go 748 B
Newer Older
Garet Halliday's avatar
Garet Halliday committed
package gsql

import (
Garet Halliday's avatar
Garet Halliday committed
	"gfx.cafe/gfx/pggat/lib/fed"
	packets "gfx.cafe/gfx/pggat/lib/fed/packets/v3.0"
func Query(client *fed.Conn, results []any, query string) error {
Garet Halliday's avatar
Garet Halliday committed
	var q = packets.Query(query)
	if err := client.WritePacket(&q); err != nil {
		return err
	if err := readQueryResults(client, results...); err != nil {
		return err
	// make sure we receive ready for query
	packet, err := client.ReadPacket(true)
	if err != nil {
Garet Halliday's avatar
Garet Halliday committed
		return err
	}

	if packet.Type() != packets.TypeReadyForQuery {
		return ErrExpectedReadyForQuery
func readQueryResults(client *fed.Conn, results ...any) error {
	for _, result := range results {
		if err := readRows(client, result); err != nil {
			return err
		}
	}
	return nil
}