standards

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 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 (
	// RFC 8259 JSON media type, sent with an explicit UTF-8 charset for HTTP.
	MediaTypeJSON = "application/json; charset=utf-8"

	// RFC 9457 Problem Details for HTTP APIs.
	MediaTypeProblemJSON = "application/problem+json"

	// RFC 4180 CSV and common tab-separated values media types.
	MediaTypeCSV = "text/csv; charset=utf-8"
	MediaTypeTSV = "text/tab-separated-values; charset=utf-8"

	// XML 1.0 and ECMA-376 / ISO/IEC 29500 spreadsheet exports.
	MediaTypeXML  = "application/xml; charset=utf-8"
	MediaTypeXLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

	// SQLSTATE class/code values from ISO/IEC 9075 and common vendor practice.
	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