dataview

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dataview reads what a database holds, for the panel's data viewer. It never writes: queries are built here from a typed request, names are checked against the database's own catalog, and every query runs in a read-only transaction with a time limit, through the client that ships in the database's image.

Index

Constants

View Source
const (
	PageTimeout   = 5 * time.Second
	ExportTimeout = 10 * time.Minute
)

How long a query may take: a page is meant to be quick, and a slow one should be narrowed with a filter rather than hold the database.

View Source
const (
	MaxCell = 1000
	MaxFull = 64 << 10
)

A value longer than this is cut in a page; a row asked for in full keeps up to MaxFull characters of each.

View Source
const (
	OpEq       = "eq"
	OpNe       = "ne"
	OpContains = "contains"
	OpStarts   = "starts"
	OpGt       = "gt"
	OpLt       = "lt"
	OpNull     = "null"
	OpNotNull  = "notnull"
)

The filters there are.

View Source
const ItemCount = 100

ItemCount is how many items of a list, hash, set, sorted set or stream are shown.

View Source
const PageSize = 50

PageSize is how many rows a page holds.

Variables

This section is empty.

Functions

func Export

func Export(ctx context.Context, exec Exec, engineName string, q Query, w io.Writer) error

Export writes every row the query finds as CSV, whole, with the column names first.

func IsUser

func IsUser(err error) bool

IsUser reports whether err is meant for the user rather than Zelie's own.

func Supports

func Supports(engineName string) bool

Supports reports whether the viewer reads tables of an engine.

Types

type Column

type Column struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Nullable bool   `json:"nullable"`
	// Key is set for the columns of the primary key.
	Key bool `json:"key,omitempty"`
	// Binary columns are shown as hex.
	Binary bool `json:"binary,omitempty"`
}

Column describes one column of a table.

type Exec

type Exec func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (uint32, error)

Exec runs a command in the database's container, with the container's environment, which holds the database's password.

type Filter

type Filter struct {
	Column string `json:"column"`
	Op     string `json:"op"`
	Value  string `json:"value,omitempty"`
}

Filter narrows the rows to those whose column matches.

type Key

type Key struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Binary bool   `json:"binary,omitempty"`
	Type   string `json:"type"`
	// TTL is in seconds, -1 for a key that never expires.
	TTL int64 `json:"ttl"`
}

Key is one key. ID is its name in Redis's quoting, which the viewer sends back to open it; Name is how it reads.

type KeyPage

type KeyPage struct {
	Keys   []Key  `json:"keys"`
	Cursor string `json:"cursor"`
}

KeyPage is one step through the keys. Cursor is where the next step starts, "0" when the whole key space has been gone through.

func Keys

func Keys(ctx context.Context, exec Exec, pattern, cursor string) (KeyPage, error)

Keys goes one step through the keys whose names match pattern, a Redis glob.

type Page

type Page struct {
	Columns []string    `json:"columns"`
	Rows    [][]*string `json:"rows"`
	// Cut lists the values that were cut short, as row and column.
	Cut [][2]int `json:"cut,omitempty"`
	// More says there are rows after this page.
	More bool `json:"more"`
}

Page is what a query found.

func Rows

func Rows(ctx context.Context, exec Exec, engineName string, q Query) (Page, error)

Rows reads one page of a table.

type Query

type Query struct {
	Schema  string   `json:"schema"`
	Table   string   `json:"table"`
	Filters []Filter `json:"filters,omitempty"`
	// Search looks for text in every column.
	Search string `json:"search,omitempty"`
	Sort   string `json:"sort,omitempty"`
	Desc   bool   `json:"desc,omitempty"`
	Offset int    `json:"offset,omitempty"`
	// Full keeps each value up to MaxFull characters, for one row opened
	// on its own.
	Full bool `json:"full,omitempty"`
}

Query asks for a page of a table's rows.

type Table

type Table struct {
	Schema  string   `json:"schema"`
	Name    string   `json:"name"`
	View    bool     `json:"view,omitempty"`
	Rows    int64    `json:"rows"`
	Bytes   int64    `json:"bytes"`
	Columns []Column `json:"columns"`
}

Table is a table or view. Rows is the database's own estimate, -1 when it has none yet; counting a large table exactly would take too long.

func Tables

func Tables(ctx context.Context, exec Exec, engineName string) ([]Table, error)

Tables lists the tables and views, with their columns.

type Value

type Value struct {
	Key     Key         `json:"key"`
	Size    int64       `json:"size"`
	Columns []string    `json:"columns"`
	Rows    [][]*string `json:"rows"`
	// Binary lists the cells shown as hex, as row and column, and Cut the
	// ones cut short.
	Binary [][2]int `json:"binary,omitempty"`
	Cut    [][2]int `json:"cut,omitempty"`
}

Value is what a key holds: up to ItemCount items, as rows under Columns. Size is its full length: characters, items or entries.

func KeyValue

func KeyValue(ctx context.Context, exec Exec, id string) (Value, error)

KeyValue reads what a key holds.

Jump to

Keyboard shortcuts

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