relation

package
v0.0.0-...-15d0b39 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ZSetToTable

func ZSetToTable(z zset.ZSet, t *Table) error

ZSetToTable attempts to load a ZSet into a Table. Note: This assumes the Documents in the ZSet are compatible with the Table Schema.

Types

type Column

type Column struct {
	Name          string
	QualifiedName string
	Type          ColumnType
}

type ColumnType

type ColumnType int
const (
	TypeAny ColumnType = iota
	TypeInt
	TypeString
	TypeFloat
)

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database holds table schemas for query compilation.

func NewDatabase

func NewDatabase(name string) *Database

NewDatabase creates a new empty catalog.

func (*Database) Delete

func (d *Database) Delete(table string, pk string) (bool, error)

Delete removes a row by primary key from a table.

func (*Database) DropTable

func (d *Database) DropTable(name string) error

DropTable removes a table from the catalog.

func (*Database) GetName

func (d *Database) GetName() string

GetName returns the name of the database.

func (*Database) GetTable

func (d *Database) GetTable(name string) (*Table, error)

GetTable returns the schema for a table, or an error if not found.

func (*Database) Insert

func (d *Database) Insert(table string, data []any) error

Insert inserts a row into a table.

func (*Database) MarshalJSON

func (d *Database) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Database) RegisterTable

func (d *Database) RegisterTable(name string, table *Table)

RegisterTable adds a table schema to the catalog.

func (*Database) Tables

func (d *Database) Tables() []string

Tables returns all table names in sorted order.

func (*Database) UnmarshalJSON

func (d *Database) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Database) Update

func (d *Database) Update(table string, pk string, fn func(row *Row) error) (*Row, error)

Update updates a row by primary key using the updater callback.

type Row

type Row struct {
	Table *Table
	Data  []any
}

Row implements Document. It uses orderedcode for keys and a slice for data.

func ConcatRows

func ConcatRows(r, r2 *Row) *Row

ConcatRows combines two rows into a joined row with qualified columns.

func (*Row) Copy

func (r *Row) Copy() datamodel.Document

func (*Row) Fields

func (r *Row) Fields() map[string]any

Fields returns a deep copy of row fields as a map.

func (*Row) GetField

func (r *Row) GetField(field string) (any, error)

func (*Row) Hash

func (r *Row) Hash() string

func (*Row) MarshalJSON

func (r *Row) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Row) Merge

func (r *Row) Merge(other datamodel.Document) datamodel.Document

Merge combines two rows into a joined row with qualified columns.

func (*Row) New

func (r *Row) New() datamodel.Document

func (*Row) PrimaryKey

func (r *Row) PrimaryKey() (string, error)

func (*Row) SetField

func (r *Row) SetField(field string, value any) error

func (*Row) String

func (r *Row) String() string

String returns a string representation of the row.

func (*Row) UnmarshalJSON

func (r *Row) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Schema

type Schema struct {
	Columns   []Column
	PKIndices []int // Indices of columns that make up the Primary Key
	Aliases   map[string]string
}

Schema defines the table schemata

func NewSchema

func NewSchema(columns ...string) *Schema

NewSchema creates a schema from column names.

func (*Schema) AliasForColumn

func (s *Schema) AliasForColumn(name string) (string, bool)

func (*Schema) WithPrimaryKey

func (s *Schema) WithPrimaryKey(indices ...int) *Schema

WithPrimaryKey sets primary key column indices.

func (*Schema) WithQualifiedNames

func (s *Schema) WithQualifiedNames(table string) *Schema

WithQualifiedNames fills QualifiedName as table.column when missing.

type Table

type Table struct {
	Name   string
	Schema *Schema
	// contains filtered or unexported fields
}

func NewTable

func NewTable(name string, schema *Schema) *Table

func (*Table) Claim

func (t *Table) Claim(row *Row) (*Row, error)

Claim reassigns a row to this table with optional compatibility checks.

func (*Table) Delete

func (t *Table) Delete(pk string) bool

Delete removes a row by primary key.

func (*Table) Insert

func (t *Table) Insert(data []any) error

func (*Table) InsertRow

func (t *Table) InsertRow(row *Row) error

InsertRow inserts a row into the table after claiming it.

func (*Table) Lookup

func (t *Table) Lookup(pk string) (*Row, bool)

Lookup returns a row by primary key.

func (*Table) MarshalJSON

func (t *Table) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Table) ToZSet

func (t *Table) ToZSet() zset.ZSet

ToZSet converts the Table to a ZSet with weight 1.

func (*Table) UnmarshalJSON

func (t *Table) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Table) Update

func (t *Table) Update(pk string, fn func(row *Row) error) (*Row, error)

Update updates a row by primary key using the updater callback.

Jump to

Keyboard shortcuts

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