CodeSampleX

Sample

github.com/jackc/pgx/v5 v5.10.0: pgtype.NewMap

Verified sample for golang github.com/jackc/pgx/v5 v5.10.0: pgtype.NewMap. The contract ran on go 1.26 · linux alpine/x64 · docker and passed.

sha256:539df80063eb3f2fcc1b62e81cd7faffbf8a875d9f8db037134acd800547086d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/jackc/pgx/v5/pgtype.NewMap in pkg:golang/github.com/jackc/pgx/v5@v5.10.0
Packages
Symbols
  • github.com/jackc/pgx/v5/pgtype.NewMap
Created
2026-08-28T01:33:58Z

Contract

  1. pgtype.NewMap returns a non-nil Map instance
  2. TypeForName finds standard registered types text, int4, bool, timestamptz, json, bytea
  3. TypeForOID finds standard registered types by OID
  4. Encode and Scan roundtrip string values using text format code
  5. Encode and Scan roundtrip int32 values using binary format code
  6. Scan into non-pointer or unsupported destination types returns an error

Files

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

Download the source artifact (tar.gz)

Source

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/pgtype.NewMap 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/pgtype.NewMap
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:a9e71f2c3cae6829dd5e606ba0d1331e5194c6c3bf2228e2f88fd01016dcb1a1","contract":["pgtype.NewMap returns a non-nil Map instance","TypeForName finds standard registered types text, int4, bool, timestamptz, json, bytea","TypeForOID finds standard registered types by OID","Encode and Scan roundtrip string values using text format code","Encode and Scan roundtrip int32 values using binary format code","Scan into non-pointer or unsupported destination types returns an error"],"goal":"verify github.com/jackc/pgx/v5/pgtype.NewMap 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/pgtype.NewMap"]},"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/pgtype.NewMap"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/jackc/pgx/v5 v5.10.0
go.sum
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/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/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
pgtype_map.go
package sample

import (
	"fmt"

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

// CreateTypeMap initializes and returns a default pgtype.Map using pgtype.NewMap().
func CreateTypeMap() *pgtype.Map {
	return pgtype.NewMap()
}

// EncodeText uses the pgtype.Map to encode a string value into text format bytes.
func EncodeText(m *pgtype.Map, value string) ([]byte, error) {
	t, ok := m.TypeForName("text")
	if !ok {
		return nil, fmt.Errorf("text type not found in type map")
	}
	return m.Encode(t.OID, pgtype.TextFormatCode, value, nil)
}

// ScanText uses the pgtype.Map to scan text format bytes into a string destination.
func ScanText(m *pgtype.Map, src []byte) (string, error) {
	t, ok := m.TypeForName("text")
	if !ok {
		return "", fmt.Errorf("text type not found in type map")
	}
	var dst string
	err := m.Scan(t.OID, pgtype.TextFormatCode, src, &dst)
	return dst, err
}

// EncodeInt4 uses the pgtype.Map to encode an int32 value into binary format bytes.
func EncodeInt4(m *pgtype.Map, value int32) ([]byte, error) {
	t, ok := m.TypeForName("int4")
	if !ok {
		return nil, fmt.Errorf("int4 type not found in type map")
	}
	return m.Encode(t.OID, pgtype.BinaryFormatCode, value, nil)
}

// ScanInt4 uses the pgtype.Map to scan binary format bytes into an int32 destination.
func ScanInt4(m *pgtype.Map, src []byte) (int32, error) {
	t, ok := m.TypeForName("int4")
	if !ok {
		return 0, fmt.Errorf("int4 type not found in type map")
	}
	var dst int32
	err := m.Scan(t.OID, pgtype.BinaryFormatCode, src, &dst)
	return dst, err
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/jackc/pgx/v5/pgtype.NewMap 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/pgtype.NewMap"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"

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

func main() {
	// Assertion 1: pgtype.NewMap returns a non-nil Map instance
	m := pgtype.NewMap()
	if m == nil {
		fmt.Fprintf(os.Stderr, "expected pgtype.NewMap() to return non-nil *pgtype.Map\n")
		os.Exit(1)
	}

	// Assertion 2: TypeForName finds standard registered types
	for _, typeName := range []string{"text", "int4", "bool", "timestamptz", "json", "bytea"} {
		t, ok := m.TypeForName(typeName)
		if !ok || t == nil {
			fmt.Fprintf(os.Stderr, "expected type %q to be registered in pgtype.Map\n", typeName)
			os.Exit(1)
		}
	}

	// Assertion 3: TypeForOID finds standard registered types by OID
	textType, ok := m.TypeForOID(pgtype.TextOID)
	if !ok || textType == nil || textType.Name != "text" {
		fmt.Fprintf(os.Stderr, "expected OID %d to map to 'text' type\n", pgtype.TextOID)
		os.Exit(1)
	}

	int4Type, ok := m.TypeForOID(pgtype.Int4OID)
	if !ok || int4Type == nil || int4Type.Name != "int4" {
		fmt.Fprintf(os.Stderr, "expected OID %d to map to 'int4' type\n", pgtype.Int4OID)
		os.Exit(1)
	}

	// Assertion 4: Encode and Scan roundtrip for text data
	sampleMap := sample.CreateTypeMap()
	inputStr := "CodeSampleX pgtype.NewMap contract verification"
	encodedText, err := sample.EncodeText(sampleMap, inputStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to encode text: %v\n", err)
		os.Exit(1)
	}
	scannedStr, err := sample.ScanText(sampleMap, encodedText)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to scan text: %v\n", err)
		os.Exit(1)
	}
	if scannedStr != inputStr {
		fmt.Fprintf(os.Stderr, "expected scanned string %q, got %q\n", inputStr, scannedStr)
		os.Exit(1)
	}

	// Assertion 5: Encode and Scan roundtrip for binary int4 data
	var inputInt int32 = 424242
	encodedInt4, err := sample.EncodeInt4(sampleMap, inputInt)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to encode int4: %v\n", err)
		os.Exit(1)
	}
	scannedInt4, err := sample.ScanInt4(sampleMap, encodedInt4)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to scan int4: %v\n", err)
		os.Exit(1)
	}
	if scannedInt4 != inputInt {
		fmt.Fprintf(os.Stderr, "expected scanned int4 %d, got %d\n", inputInt, scannedInt4)
		os.Exit(1)
	}

	// Assertion 6: Scan into non-pointer destination returns an error
	var nonPtr int32 = 0
	err = sampleMap.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, encodedInt4, nonPtr)
	if err == nil {
		fmt.Fprintf(os.Stderr, "expected scan into non-pointer to fail, but succeeded\n")
		os.Exit(1)
	}

	// Assertion 7: Scan into unsupported destination type returns an error
	var unsupportedDst struct{ Field string }
	err = sampleMap.Scan(pgtype.Int4OID, pgtype.BinaryFormatCode, encodedInt4, &unsupportedDst)
	if err == nil {
		fmt.Fprintf(os.Stderr, "expected scan into unsupported struct to fail, but succeeded\n")
		os.Exit(1)
	}

	fmt.Println("All pgtype.NewMap contract assertions passed.")
}

Origin Seeder

anonymous