standards

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package standards centralizes interoperability constants and helpers used by tinySQL and applications built on top of it.

Index

Constants

View Source
const (
	// MediaTypeJSON is the RFC 8259 JSON media type with an explicit UTF-8 charset.
	MediaTypeJSON = "application/json; charset=utf-8"

	// MediaTypeProblemJSON is the RFC 9457 Problem Details media type.
	MediaTypeProblemJSON = "application/problem+json"

	// MediaTypeCSV is the RFC 4180 CSV media type with an explicit UTF-8 charset.
	MediaTypeCSV = "text/csv; charset=utf-8"
	// MediaTypeTSV is the tab-separated-values media type with an explicit UTF-8 charset.
	MediaTypeTSV = "text/tab-separated-values; charset=utf-8"

	// MediaTypeXML is the XML 1.0 media type with an explicit UTF-8 charset.
	MediaTypeXML = "application/xml; charset=utf-8"
	// MediaTypeXLSX is the Office Open XML spreadsheet media type.
	MediaTypeXLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

	// SQLStateSuccessfulCompletion is the ISO/IEC 9075 SQLSTATE success code.
	SQLStateSuccessfulCompletion = "00000"
	SQLStateWarning              = "01000"
	SQLStateNoData               = "02000"
	SQLStateDataException        = "22000"
	SQLStateInvalidDatetime      = "22007"
	SQLStateInvalidParameter     = "22023"
	SQLStateSyntaxError          = "42601"
	SQLStateUndefinedTable       = "42P01"
	SQLStateIntegrityViolation   = "23000"
	SQLStateInvalidAuthorization = "28000"
	SQLStateTransactionRollback  = "40000"
	SQLStateInternalError        = "XX000"
)

Variables

This section is empty.

Functions

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats timestamps for public APIs using RFC 3339 in UTC.

func ParseTime

func ParseTime(value string) (time.Time, error)

ParseTime parses API timestamps using RFC 3339.

func SQLState

func SQLState(err error) string

SQLState returns the SQLSTATE attached to err, if present.

func WithSQLState

func WithSQLState(state string, err error) error

WithSQLState wraps err with a SQLSTATE code. Nil errors stay nil.

func WriteProblem

func WriteProblem(w http.ResponseWriter, problem Problem)

WriteProblem writes an RFC 9457 problem+json response.

Types

type Problem

type Problem struct {
	Type     string `json:"type"`
	Title    string `json:"title"`
	Status   int    `json:"status"`
	Detail   string `json:"detail,omitempty"`
	Instance string `json:"instance,omitempty"`
	Error    string `json:"error,omitempty"`
}

Problem is an RFC 9457 Problem Details response. Error is a compatibility extension for older tinySQL/dbweb clients that read JSON responses via data.error.

func NewProblem

func NewProblem(status int, title, detail, instance string) Problem

NewProblem creates a Problem with a stable default type URI.

type SQLStateError

type SQLStateError struct {
	State string
	Err   error
}

SQLStateError attaches a SQLSTATE code to an underlying error.

func (*SQLStateError) Error

func (e *SQLStateError) Error() string

func (*SQLStateError) Unwrap

func (e *SQLStateError) Unwrap() error

Jump to

Keyboard shortcuts

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