datatable

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package datatable is a query's result in one shape every step and chat can read (spec_059_data DAT-01..DAT-05): its columns with portable types, its rows as arrays in the columns' order, its values as JSON's.

Index

Constants

View Source
const (
	String    = "string"
	Integer   = "integer"
	Number    = "number"
	Boolean   = "boolean"
	Date      = "date"
	Time      = "time"
	Timestamp = "timestamp"
	JSON      = "json"
	Bytes     = "bytes"
	Other     = "other"
)

The portable types (DAT-02): the same across databases.

View Source
const MarkdownRows = 50

MarkdownRows is how many rows Markdown shows (DAT-05).

Variables

This section is empty.

Functions

func TypeOf

func TypeOf(dbType string) string

TypeOf is a database type's portable type: VARCHAR(80), int4, "timestamp with time zone", SQLite's declared types by their affinity.

func Value

func Value(v any, typ string) any

Value is v, as a driver read it for a column of type typ, made JSON's (DAT-03): integers past 2^53 and decimals with more digits than a double keeps as strings, times as ISO 8601, bytes as base64, JSON as itself.

Types

type Column

type Column struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Type        string `json:"type"`
	Length      *int64 `json:"length"`
	DBType      string `json:"db_type,omitempty"`
	Nullable    *bool  `json:"nullable,omitempty"`
}

Column is a result's column: its name, its schema's comment, its portable type and declared length (nil when it has none), and the database's own type and whether it may be NULL (nil when unsaid).

type RowItem

type RowItem struct {
	Index   int            `json:"index"`
	Row     map[string]any `json:"row"`
	Columns []Column       `json:"columns"`
}

RowItem is one row standing alone (DAT-04): its place in the result, its values by column name, and its columns.

type Table

type Table struct {
	Columns   []Column `json:"columns"`
	Rows      [][]any  `json:"rows"`
	Total     int      `json:"total"`
	Truncated bool     `json:"truncated"`
}

Table is a query's result (DAT-01): Total is how many rows it holds, Truncated whether a limit cut the query's rows there.

func New

func New(columns []Column, rows [][]any, truncated bool) Table

New is the table of columns (Type left empty is worked out from DBType, else from the first value) and rows as a driver read them, each value made JSON's (DAT-03).

func (Table) Items

func (t Table) Items() []RowItem

Items are t's rows as row items (DAT-04).

func (Table) Markdown

func (t Table) Markdown(max int) string

Markdown is t as a Markdown table, its first max rows (MarkdownRows when max is 0), then a line saying how many more there are and whether a limit cut the result (DAT-05).

Jump to

Keyboard shortcuts

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