No description
Find a file
2026-08-06 21:13:28 +03:00
types test(types): add nullable type coverage 2026-08-06 21:13:28 +03:00
.gitignore chore: add .gitignore 2025-09-08 19:16:36 +03:00
go.mod build(module): update canonical import path 2026-08-06 21:01:01 +03:00
LICENSE add license 2025-07-28 05:04:38 +03:00
README.md build(module): update canonical import path 2026-08-06 21:01:01 +03:00

simple-types-go

Simple nullable types for Go with first-class support for Postgres and JSON.

simple-types-go provides lightweight wrappers for primitive types (such as string, int, etc.) that handle NULL values gracefully in both database operations (via database/sql) and JSON marshaling/unmarshaling. These types are useful when dealing with nullable columns in PostgreSQL and when interoperating with APIs where null values are common.

I personally use these types with sqlc to generate type-safe code for database operations, but they can be used in any Go application that requires nullable types.

Features

  • Supports sql.Scanner and driver.Valuer interfaces for database use (e.g. PostgreSQL).
  • Implements json.Marshaler and json.Unmarshaler interfaces.

Installation

go get code.faceguy.dev/faceguy/simple-types-go

Usage

package main

import (
	"encoding/json"
	"fmt"
	"code.faceguy.dev/faceguy/simple-types-go/types"
)

func main() {
	s := types.NewString("hello")

	data, _ := json.Marshal(s)
	fmt.Println(string(data)) // Output: "hello"

	var s2 types.String
	json.Unmarshal([]byte("null"), &s2)
	fmt.Println(s2.Valid) // Output: false

	fmt.Println(s2.String()) // Output: ""
}

License

This project is licensed under the MIT License. See the LICENSE file for details