CodeSampleX

Пример

github.com/jackc/pgx/v5 v5.10.0: ScanRow

Проверенный пример — golang github.com/jackc/pgx/v5 v5.10.0: ScanRow. Контракт выполнен на go 1.26 · linux alpine/x64 · docker и пройден.

sha256:8c5fe3976e9e9e244ffe28e6d51bf6d3bbf5f16841fb5fdb69ea4ce7260ad934

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 go

Среды запусков проверки

Окружение Контракт Этапы Запуск
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-28

Кейс

HOW
Цель
verify github.com/jackc/pgx/v5.ScanRow in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Пакеты
Символы
  • github.com/jackc/pgx/v5.ScanRow
Создан
2026-08-28T01:11:55Z

Контракт

  1. pgx.ScanRow decodes text format row data into primitive Go types (int32, string, bool)
  2. pgx.ScanRow decodes NULL database values into pointer destinations as nil
  3. pgx.ScanRow decodes binary format row data into destination variables
  4. pgx.ScanRow returns an error when field description count does not match destination count
  5. pgx.ScanRow returns ScanArgError with ColumnIndex when value conversion fails
  6. pgx.ScanRow decodes row values into pgtype custom types like pgtype.Text

Файлы

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Скачать артефакт с исходным кодом (tar.gz)

Исходный код

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify github.com/jackc/pgx/v5.ScanRow in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Demonstrate these symbols/APIs:
  - github.com/jackc/pgx/v5.ScanRow

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:a08f6764c7f4a5741e73cfe8a66ffcfdd4b4296d6cbde925081c337145c59707","contract":["pgx.ScanRow decodes text format row data into primitive Go types (int32, string, bool)","pgx.ScanRow decodes NULL database values into pointer destinations as nil","pgx.ScanRow decodes binary format row data into destination variables","pgx.ScanRow returns an error when field description count does not match destination count","pgx.ScanRow returns ScanArgError with ColumnIndex when value conversion fails","pgx.ScanRow decodes row values into pgtype custom types like pgtype.Text"],"goal":"verify github.com/jackc/pgx/v5.ScanRow in pkg:golang/github.com/jackc/pgx/v5@v5.10.0","kind":"HOW","packages":["pkg:golang/github.com/jackc/pgx/v5@v5.10.0"],"schemaVersion":1,"symbols":["github.com/jackc/pgx/v5.ScanRow"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/jackc/pgx/v5@v5.10.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/jackc/pgx/v5@v5.10.0","symbols":["github.com/jackc/pgx/v5.ScanRow"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/jackc/pgx/v5 v5.10.0

require (
	github.com/jackc/pgpassfile v1.0.0 // indirect
	github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
	golang.org/x/text v0.29.0 // indirect
)
go.sum
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0=
github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
main.go
package main

import (
	"fmt"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgconn"
	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	typeMap := pgtype.NewMap()

	fieldDescriptions := []pgconn.FieldDescription{
		{Name: "id", DataTypeOID: pgtype.Int4OID, Format: pgtype.TextFormatCode},
		{Name: "name", DataTypeOID: pgtype.TextOID, Format: pgtype.TextFormatCode},
	}

	values := [][]byte{
		[]byte("42"),
		[]byte("sample-item"),
	}

	var id int32
	var name string

	if err := pgx.ScanRow(typeMap, fieldDescriptions, values, &id, &name); err != nil {
		fmt.Printf("ScanRow error: %v\n", err)
		return
	}

	fmt.Printf("Decoded row: id=%d, name=%s\n", id, name)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/pgx/v5.ScanRow in pkg:golang/github.com/jackc/pgx/v5@v5.10.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/jackc/pgx/v5@v5.10.0"
  ],
  "symbols": [
    "github.com/jackc/pgx/v5.ScanRow"
  ]
}
test/contract.go
package main

import (
	"errors"
	"fmt"
	"os"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgconn"
	"github.com/jackc/pgx/v5/pgtype"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All github.com/jackc/pgx/v5.ScanRow contract assertions passed successfully.")
}

func runContract() error {
	typeMap := pgtype.NewMap()

	// Assertion 1: pgx.ScanRow decodes text format row data into primitive Go types (int32, string, bool)
	fdsText := []pgconn.FieldDescription{
		{Name: "id", DataTypeOID: pgtype.Int4OID, Format: pgtype.TextFormatCode},
		{Name: "title", DataTypeOID: pgtype.TextOID, Format: pgtype.TextFormatCode},
		{Name: "active", DataTypeOID: pgtype.BoolOID, Format: pgtype.TextFormatCode},
	}
	valuesText := [][]byte{
		[]byte("101"),
		[]byte("Sample Title"),
		[]byte("t"),
	}
	var id int32
	var title string
	var active bool

	if err := pgx.ScanRow(typeMap, fdsText, valuesText, &id, &title, &active); err != nil {
		return fmt.Errorf("assertion 1 failed: ScanRow error: %w", err)
	}
	if id != 101 || title != "Sample Title" || !active {
		return fmt.Errorf("assertion 1 failed: unexpected decoded values: id=%d, title=%q, active=%v", id, title, active)
	}

	// Assertion 2: pgx.ScanRow decodes NULL database values into pointer destinations as nil
	valuesNull := [][]byte{
		nil,
		[]byte("NotNullTitle"),
		nil,
	}
	var optID *int32
	var optTitle *string
	var optActive *bool

	if err := pgx.ScanRow(typeMap, fdsText, valuesNull, &optID, &optTitle, &optActive); err != nil {
		return fmt.Errorf("assertion 2 failed: ScanRow error: %w", err)
	}
	if optID != nil || optTitle == nil || *optTitle != "NotNullTitle" || optActive != nil {
		return fmt.Errorf("assertion 2 failed: expected nil pointers for NULL values, got optID=%v optTitle=%v optActive=%v", optID, optTitle, optActive)
	}

	// Assertion 3: pgx.ScanRow decodes binary format row data into destination variables
	fdsBin := []pgconn.FieldDescription{
		{Name: "id", DataTypeOID: pgtype.Int4OID, Format: pgtype.BinaryFormatCode},
		{Name: "active", DataTypeOID: pgtype.BoolOID, Format: pgtype.BinaryFormatCode},
	}
	valuesBin := [][]byte{
		{0x00, 0x00, 0x01, 0x2c}, // 300 in 4-byte big-endian
		{0x01},                   // true in binary boolean
	}
	var binID int32
	var binActive bool

	if err := pgx.ScanRow(typeMap, fdsBin, valuesBin, &binID, &binActive); err != nil {
		return fmt.Errorf("assertion 3 failed: ScanRow error: %w", err)
	}
	if binID != 300 || !binActive {
		return fmt.Errorf("assertion 3 failed: unexpected binary values: binID=%d, binActive=%v", binID, binActive)
	}

	// Assertion 4: pgx.ScanRow returns an error when field description count does not match destination count
	errMismatch := pgx.ScanRow(typeMap, fdsText, valuesText, &id, &title)
	if errMismatch == nil {
		return fmt.Errorf("assertion 4 failed: expected error when field descriptions and dest count mismatch, got nil")
	}

	// Assertion 5: pgx.ScanRow returns ScanArgError with ColumnIndex when value conversion fails
	badValues := [][]byte{
		[]byte("not-an-int"),
		[]byte("Valid Title"),
		[]byte("t"),
	}
	errConversion := pgx.ScanRow(typeMap, fdsText, badValues, &id, &title, &active)
	if errConversion == nil {
		return fmt.Errorf("assertion 5 failed: expected conversion error, got nil")
	}
	var scanArgErr pgx.ScanArgError
	if !errors.As(errConversion, &scanArgErr) {
		return fmt.Errorf("assertion 5 failed: expected ScanArgError, got %T: %v", errConversion, errConversion)
	}
	if scanArgErr.ColumnIndex != 0 {
		return fmt.Errorf("assertion 5 failed: expected ColumnIndex 0, got %d", scanArgErr.ColumnIndex)
	}

	// Assertion 6: pgx.ScanRow decodes row values into pgtype custom types like pgtype.Text
	fdsPgType := []pgconn.FieldDescription{
		{Name: "title", DataTypeOID: pgtype.TextOID, Format: pgtype.TextFormatCode},
	}
	valuesPgType := [][]byte{
		[]byte("pgtype value"),
	}
	var pgText pgtype.Text

	if err := pgx.ScanRow(typeMap, fdsPgType, valuesPgType, &pgText); err != nil {
		return fmt.Errorf("assertion 6 failed: ScanRow into pgtype.Text error: %w", err)
	}
	if !pgText.Valid || pgText.String != "pgtype value" {
		return fmt.Errorf("assertion 6 failed: unexpected pgtype.Text: %+v", pgText)
	}

	return nil
}

Исходный сидер

аноним