No description
Find a file
2025-10-30 01:11:57 +02:00
types feat: add combine function for timestamp 2025-09-09 21:00:18 +03:00
.gitignore chore: add .gitignore 2025-09-08 19:16:36 +03:00
go.mod chore: update go.mod module name 2025-09-09 21:01:18 +03:00
LICENSE add license 2025-07-28 05:04:38 +03:00
README.md docs: fix README 2025-10-30 01:11:57 +02: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 github.com/j0h-dev/simple-types-go

Usage

package main

import (
	"encoding/json"
	"fmt"
	"github.com/j0h-dev/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