r3utils

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package r3utils provides shared utility functions used across r3 packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRelationType

func IsRelationType(t reflect.Type) bool

IsRelationType returns true if the Go type represents a relation field (slice, map, pointer-to-struct, or struct — except time.Time and types that round-trip as a single column via database/sql).

A struct/slice/map that implements driver.Valuer or sql.Scanner (checked on the type and its pointer, since Scan's receiver is conventionally a pointer) is a scalar-like column, not a relation — this is what makes r3.JSONColumn persist as a JSON column instead of being silently dropped.

This is the SQL-shaped classification: what cannot be one SQL column without serialisation. It gates engine/sql and r3.SchemaOf, where an untagged slice or struct field is therefore not persisted at all. The document-store engines (engine/mongo, engine/file) classify by declaration instead - see r3tag.DeclaresRelation - because there an array or a subdocument is the native representation of such a field.

func ResolveElementType

func ResolveElementType(t reflect.Type) reflect.Type

ResolveElementType unwraps slice and pointer types to get the underlying struct type. E.g. []CityTranslation -> CityTranslation, *City -> City.

func ToSnakeCase

func ToSnakeCase(s string) string

ToSnakeCase converts a name (PascalCase, camelCase, etc.) to snake_case. It correctly handles acronyms like "CityID" → "city_id".

func ToSnakeCasePlural

func ToSnakeCasePlural(s string) string

ToSnakeCasePlural converts a name to snake_case and applies naive pluralization.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL