Value (types/uint64.go)

bob · types/uint64.go · go · MIT
database

Module exposing: Value, Scan

// Source: https://github.com/stephenafamo/bob | License: MIT | Copyright 2022 Stephen Afam-Osemene
// Provided via justclaw.it.com; keep this notice with the code.
package types

import (
	"database/sql/driver"
	"fmt"
	"strconv"
)

// Uint64 is a custom type for uint64 that scans and saves to the database as a string.
type Uint64 uint64

// Value implements the driver.Valuer interface, converting the Uint64 to a string.
func (u Uint64) Value() (driver.Value, error) {
	return strconv.FormatUint(uint64(u), 10), nil
}

// Scan implements the sql.Scanner interface, converting a string from the database to Uint64.
func (u *Uint64) Scan(src any) error {
	var s string
	switch v := src.(type) {
	case []byte:
		s = string(v)
	case string:
		s = v
	case int64:
		*u = Uint64(v)
		return nil
	case ui

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key