Skip to content

Conversation

@loreto
Copy link
Contributor

@loreto loreto commented Jul 8, 2025

Summary

Replace NullableID with sql.Null[TypeID] for nullable columns

  • Remove custom NullableID type in favor of Go's standard sql.Null[TypeID]
  • Update all tests to use sql.Null[TypeID] instead of NullableID
  • Update examples to demonstrate sql.Null[TypeID] usage
  • Add documentation recommending sql.Null[TypeID] for nullable columns
  • Maintain full backward compatibility for database operations

Remove Must function from typeid.go to keep API surface small. Introduce MustParse as a helper only in tests (not part of public API)

How was it tested?

Updated unit tests and ran them.

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.

loreto added 2 commits July 8, 2025 14:57
- Remove custom NullableID type in favor of Go's standard sql.Null[TypeID]
- Update all tests to use sql.Null[TypeID] instead of NullableID
- Update examples to demonstrate sql.Null[TypeID] usage
- Add documentation recommending sql.Null[TypeID] for nullable columns
- Maintain full backward compatibility for database operations
- Remove Must function from typeid.go
- Add MustParse helper in shared_test.go for test usage
- Update all test files to use MustGenerate for new TypeIDs
- Update all test files to use MustParse for parsing TypeID strings
- All tests now pass with the new helper functions
@loreto loreto requested review from Copilot and gcurtis July 8, 2025 20:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the custom NullableID type with Go’s standard sql.Null[TypeID], removes the Must helper in the public API (introducing MustParse only for tests), and updates all tests, examples, and benchmarks accordingly.

  • Swap NullableID for sql.Null[TypeID] in code, tests, and examples
  • Remove the public Must function and add a test‐only MustParse helper
  • Update benchmarks to use MustGenerate (though helper isn’t yet defined)

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
typeid/typeid-go/typeid.go Removed the Must function
typeid/typeid-go/sql.go Deleted NullableID type and methods; added usage note
typeid/typeid-go/sql_test.go Replaced NullableID tests with sql.Null[TypeID] and MustParse
typeid/typeid-go/shared_test.go Added MustParse helper for tests
typeid/typeid-go/examples_test.go Updated examples to use sql.Null[TypeID] and MustParse
typeid/typeid-go/encoding_test.go Swapped Must(Parse) calls for MustParse
typeid/typeid-go/bench_test.go Swapped Must(Parse) for MustGenerate in benchmarks
Comments suppressed due to low confidence (1)

typeid/typeid-go/bench_test.go:55

  • The benchmark references typeid.MustGenerate, but no such helper is defined. You’ll need to implement MustGenerate (similar to MustParse) or revert to using Generate with error handling.
			ids = append(ids, typeid.MustGenerate(prefix))

if td.expectError {
assert.Error(t, err)
assert.Contains(t, err.Error(), "empty string is invalid TypeID")
assert.Contains(t, err.Error(), "cannot scan empty string into TypeID")
Copy link

Copilot AI Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test now expects "cannot scan empty string into TypeID", but TypeID.Scan still returns "empty string is invalid TypeID". Align the test or change the error message in TypeID.Scan so they match.

Copilot uses AI. Check for mistakes.
@loreto loreto merged commit 99c0b7f into main Jul 8, 2025
13 checks passed
@loreto loreto deleted the daniel/typeid-null branch July 8, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants