CodeSampleX

샘플

github.com/go-sql-driver/mysql v1.7.1: NullTime

검증된 샘플 — golang github.com/go-sql-driver/mysql v1.7.1: NullTime. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: mysql.NullTime represents…

sha256:44928dd902c3bf625051ddf3d9d83a882a2537da03416b2a7f17f548ace804dc

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
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-26
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-07

케이스

HOW
목표
verify github.com/go-sql-driver/mysql.NullTime in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
패키지
심벌
  • github.com/go-sql-driver/mysql.NullTime
생성일
2026-08-26T01:37:07Z

컨트랙트

  1. mysql.NullTime represents nullable time values with Time and Valid fields
  2. mysql.NullTime.Scan sets Valid to false and Time to zero time when given nil
  3. mysql.NullTime.Scan sets Time and Valid to true when given a time.Time value
  4. mysql.NullTime.Scan parses valid date and datetime byte slices or strings into Time with Valid true
  5. mysql.NullTime.Scan returns an error when given invalid time strings or unsupported data types
  6. mysql.NullTime.Value returns nil when Valid is false and returns Time when Valid is true implementing driver.Valuer

파일

  • 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/go-sql-driver/mysql.NullTime in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/go-sql-driver/mysql@v1.7.1
Demonstrate these symbols/APIs:
  - github.com/go-sql-driver/mysql.NullTime
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:a2b05b8d13498cbe50b6f239125dbbd28fcf46353f3898a832a41d3856f1d8d5","contract":["mysql.NullTime represents nullable time values with Time and Valid fields","mysql.NullTime.Scan sets Valid to false and Time to zero time when given nil","mysql.NullTime.Scan sets Time and Valid to true when given a time.Time value","mysql.NullTime.Scan parses valid date and datetime byte slices or strings into Time with Valid true","mysql.NullTime.Scan returns an error when given invalid time strings or unsupported data types","mysql.NullTime.Value returns nil when Valid is false and returns Time when Valid is true implementing driver.Valuer"],"goal":"verify github.com/go-sql-driver/mysql.NullTime in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1","kind":"HOW","packages":["pkg:golang/github.com/go-sql-driver/mysql@v1.7.1"],"schemaVersion":1,"symbols":["github.com/go-sql-driver/mysql.NullTime"]},"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/go-sql-driver/mysql@v1.7.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/go-sql-driver/mysql@v1.7.1","symbols":["github.com/go-sql-driver/mysql.NullTime"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require github.com/go-sql-driver/mysql v1.7.1
go.sum
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
main.go
package main

import (
	"database/sql/driver"
	"fmt"
	"time"

	"github.com/go-sql-driver/mysql"
)

func main() {
	// Initialize a NullTime representing a valid timestamp
	nt := mysql.NullTime{
		Time:  time.Date(2026, 8, 26, 12, 0, 0, 0, time.UTC),
		Valid: true,
	}

	val, err := nt.Value()
	if err != nil {
		panic(err)
	}
	fmt.Printf("Valid NullTime value: %v\n", val)

	// Scan a nil value to represent a NULL database column
	var nullVal mysql.NullTime
	if err := nullVal.Scan(nil); err != nil {
		panic(err)
	}
	fmt.Printf("Null NullTime valid: %v\n", nullVal.Valid)

	// Verify driver.Valuer interface compatibility
	var _ driver.Valuer = nt
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/go-sql-driver/mysql.NullTime in pkg:golang/github.com/go-sql-driver/mysql@v1.7.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/go-sql-driver/mysql@v1.7.1"
  ],
  "symbols": [
    "github.com/go-sql-driver/mysql.NullTime"
  ],
  "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 (
	"database/sql/driver"
	"fmt"
	"os"
	"time"

	"github.com/go-sql-driver/mysql"
)

func main() {
	// Assertion 1: mysql.NullTime represents nullable time values with Time and Valid fields
	{
		testTime := time.Date(2026, 8, 26, 10, 0, 0, 0, time.UTC)
		nt := mysql.NullTime{
			Time:  testTime,
			Valid: true,
		}
		if !nt.Time.Equal(testTime) {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Time %v, got %v\n", testTime, nt.Time)
			os.Exit(1)
		}
		if !nt.Valid {
			fmt.Fprintf(os.Stderr, "Assertion 1 failed: expected Valid true, got false\n")
			os.Exit(1)
		}
	}

	// Assertion 2: mysql.NullTime.Scan sets Valid to false and Time to zero time when given nil
	{
		nt := mysql.NullTime{
			Time:  time.Date(2026, 8, 26, 10, 0, 0, 0, time.UTC),
			Valid: true,
		}
		if err := nt.Scan(nil); err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: unexpected error on Scan(nil): %v\n", err)
			os.Exit(1)
		}
		if nt.Valid {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected Valid false, got true\n")
			os.Exit(1)
		}
		if !nt.Time.IsZero() {
			fmt.Fprintf(os.Stderr, "Assertion 2 failed: expected zero Time, got %v\n", nt.Time)
			os.Exit(1)
		}
	}

	// Assertion 3: mysql.NullTime.Scan sets Time and Valid to true when given a time.Time value
	{
		var nt mysql.NullTime
		expectedTime := time.Date(2026, 1, 15, 8, 30, 0, 0, time.UTC)
		if err := nt.Scan(expectedTime); err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed: unexpected error on Scan(time.Time): %v\n", err)
			os.Exit(1)
		}
		if !nt.Valid {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected Valid true, got false\n")
			os.Exit(1)
		}
		if !nt.Time.Equal(expectedTime) {
			fmt.Fprintf(os.Stderr, "Assertion 3 failed: expected Time %v, got %v\n", expectedTime, nt.Time)
			os.Exit(1)
		}
	}

	// Assertion 4: mysql.NullTime.Scan parses valid date and datetime byte slices or strings into Time with Valid true
	{
		var ntString mysql.NullTime
		if err := ntString.Scan("2026-08-26 15:04:05"); err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: Scan string failed: %v\n", err)
			os.Exit(1)
		}
		if !ntString.Valid {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected Valid true for string datetime\n")
			os.Exit(1)
		}
		expectedTime := time.Date(2026, 8, 26, 15, 4, 5, 0, time.UTC)
		if !ntString.Time.Equal(expectedTime) {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected %v, got %v\n", expectedTime, ntString.Time)
			os.Exit(1)
		}

		var ntBytes mysql.NullTime
		if err := ntBytes.Scan([]byte("2026-08-26 15:04:05.123456")); err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: Scan byte slice failed: %v\n", err)
			os.Exit(1)
		}
		if !ntBytes.Valid {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected Valid true for byte slice datetime\n")
			os.Exit(1)
		}
		expectedNano := time.Date(2026, 8, 26, 15, 4, 5, 123456000, time.UTC)
		if !ntBytes.Time.Equal(expectedNano) {
			fmt.Fprintf(os.Stderr, "Assertion 4 failed: expected %v, got %v\n", expectedNano, ntBytes.Time)
			os.Exit(1)
		}
	}

	// Assertion 5: mysql.NullTime.Scan returns an error when given invalid time strings or unsupported data types
	{
		var nt mysql.NullTime
		if err := nt.Scan("invalid-date-string"); err == nil {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected error scanning invalid string, got nil\n")
			os.Exit(1)
		}

		if err := nt.Scan(12345); err == nil {
			fmt.Fprintf(os.Stderr, "Assertion 5 failed: expected error scanning unsupported int type, got nil\n")
			os.Exit(1)
		}
	}

	// Assertion 6: mysql.NullTime.Value returns nil when Valid is false and returns Time when Valid is true implementing driver.Valuer
	{
		invalidNT := mysql.NullTime{Valid: false}
		val, err := invalidNT.Value()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: unexpected error on invalid NullTime.Value(): %v\n", err)
			os.Exit(1)
		}
		if val != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: expected nil driver.Value, got %v\n", val)
			os.Exit(1)
		}

		now := time.Date(2026, 8, 26, 12, 0, 0, 0, time.UTC)
		validNT := mysql.NullTime{Time: now, Valid: true}
		val, err = validNT.Value()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: unexpected error on valid NullTime.Value(): %v\n", err)
			os.Exit(1)
		}
		tVal, ok := val.(time.Time)
		if !ok || !tVal.Equal(now) {
			fmt.Fprintf(os.Stderr, "Assertion 6 failed: expected time.Time %v, got %v\n", now, val)
			os.Exit(1)
		}

		var _ driver.Valuer = validNT
	}

	fmt.Println("All NullTime contract assertions passed.")
}

오리진 시더

익명