go-pg

Code

package main

import (
    "fmt"
    "os"

    "github.com/go-pg/pg/v10"
)

type Greeting struct {
  greeting  string
}

func main() {
	opt, err := pg.ParseURL(os.Getenv("DATABASE_URL"))
	if err != nil {
	   panic(err)
	}
	
	db := pg.Connect(opt)
    defer db.Close()

    var greeting Greeting
    _, err = db.QueryOne(&greeting, "SELECT ?::text AS greeting", "Hello world!")
    if err != nil {
        panic(err)
    }

    fmt.Println(greeting)
}

Elephantshark transcript

listening ...
connected at t0 = 2025-10-08 22:40:22 +0200
client -> script: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
script -> client: "S" = SSL supported
TLSv1.3/TLS_AES_128_GCM_SHA256 connection established with client
  server name via SNI: 
client -> script: "\x00\x00\x00\x26" = 38 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
connecting to Postgres server: localhost
script -> server: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
server -> script: "S" = SSL supported
TLSv1.3/TLS_AES_256_GCM_SHA384 connection established with server
forwarding client startup message to server
script -> server: "\x00\x00\x00\x26" = 38 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
forwarding all later traffic
server -> client: "R" = Authentication "\x00\x00\x00\x2a" = 42 bytes "\x00\x00\x00\x0a" = AuthenticationSASL
  "SCRAM-SHA-256-PLUS\x00" = SASL mechanism
  "SCRAM-SHA-256\x00" = SASL mechanism
  "\x00" = end
^^ 43 bytes forwarded at +0.02s, 0 bytes left in buffer
client -> server: "p" = SASLInitialResponse "\x00\x00\x00\x39" = 57 bytes
  "SCRAM-SHA-256\x00" = selected mechanism
  "\x00\x00\x00\x23" = 35 bytes follow
  "n,,n=frodo,r=Rvch+i93dXwphBMOudxCVw" = SCRAM client-first-message
^^ 58 bytes forwarded at +0.03s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x5a" = 90 bytes "\x00\x00\x00\x0b" = AuthenticationSASLContinue
  "r=Rvch+i93dXwphBMOudxCVwhLtSMt0gfVj99c8SzUjmf/6F,s=ZPXsknNfrTfGBNripnqk4A==,i=4096" = SCRAM server-first-message
^^ 91 bytes forwarded at +0.03s, 0 bytes left in buffer
client -> server: "p" = SASLResponse "\x00\x00\x00\x6a" = 106 bytes
  "c=biws,r=Rvch+i93dXwphBMOudxCVwhLtSMt0gfVj99c8SzUjmf/6F,p=Ly0PnpO1yi1JMlhrlwYoU4xKnKcBBmblHZOvUTnkTiI=" = SCRAM client-final-message
^^ 107 bytes forwarded at +0.04s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x36" = 54 bytes "\x00\x00\x00\x0c" = AuthenticationSASLFinal
  "v=4WRTRb4wM89wVPbTcxWHh9klQI5nkacNTKvu7vm2sKw=" = SCRAM server-final-message
server -> client: "R" = Authentication "\x00\x00\x00\x08" = 8 bytes "\x00\x00\x00\x00" = AuthenticationOk
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "in_hot_standby\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "integer_datetimes\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x15" = 21 bytes "TimeZone\x00" = key "Etc/UTC\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1b" = 27 bytes "IntervalStyle\x00" = key "postgres\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "search_path\x00" = key "\"$user\", public\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x14" = 20 bytes "is_superuser\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x16" = 22 bytes "application_name\x00" = key "\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x26" = 38 bytes "default_transaction_read_only\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1a" = 26 bytes "scram_iterations\x00" = key "4096\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "DateStyle\x00" = key "ISO, MDY\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x23" = 35 bytes "standard_conforming_strings\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "session_authorization\x00" = key "frodo\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "client_encoding\x00" = key "UTF8\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x31" = 49 bytes "server_version\x00" = key "18.0 (Debian 18.0-1.pgdg13+3)\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "server_encoding\x00" = key "UTF8\x00" = value
server -> client: "K" = BackendKeyData "\x00\x00\x00\x0c" = 12 bytes "\x00\x00\x00\x4c" = process ID "\xaf\x29\xb7\xa4" = secret key
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 521 bytes forwarded at +0.05s, 0 bytes left in buffer
client -> server: "Q" = Query "\x00\x00\x00\x2c" = 44 bytes "SELECT 'Hello world!'::text AS greeting\x00" = query
^^ 45 bytes forwarded at +0.05s, 0 bytes left in buffer
server -> client: "T" = RowDescription "\x00\x00\x00\x21" = 33 bytes "\x00\x01" = 1 columns follow
  "greeting\x00" = column name "\x00\x00\x00\x00" = table OID: 0 "\x00\x00" = table attrib no: 0
  "\x00\x00\x00\x19" = type OID: 25 "\xff\xff" = type length: -1 "\xff\xff\xff\xff" = type modifier: -1 "\x00\x00" = format: text
server -> client: "D" = DataRow "\x00\x00\x00\x16" = 22 bytes "\x00\x01" = 1 columns follow
  "\x00\x00\x00\x0c" = 12 bytes "Hello world!" = column value
server -> client: "C" = CommandComplete "\x00\x00\x00\x0d" = 13 bytes "SELECT 1\x00" = command tag
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 77 bytes forwarded at +0.05s, 0 bytes left in buffer
client -> server: "X" = Terminate "\x00\x00\x00\x04" = 4 bytes
^^ 5 bytes forwarded at +0.05s, 0 bytes left in buffer
client hung up
connection end

listening ...
connection end