service

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package service provides application-level operations shared by the CLI and TUI frontends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpTable

func DumpTable(ctx context.Context, w io.Writer, opts DumpOptions) (output.Result, error)

DumpTable writes rows from one database table to w.

func ErrUnsupportedImportFormat

func ErrUnsupportedImportFormat(format string) error

ErrUnsupportedImportFormat formats unsupported table import formats.

func LoadTable

func LoadTable(ctx context.Context, r io.Reader, opts LoadOptions) (db.ImportResult, error)

LoadTable reads rows from r into one database table.

Types

type AccessService

type AccessService struct {
	Driver string
	DSN    string
}

AccessService reads database role and grant metadata.

func (AccessService) Grants

func (s AccessService) Grants(ctx context.Context, role string) ([]db.GrantInfo, error)

func (AccessService) Roles

func (s AccessService) Roles(ctx context.Context) ([]db.RoleInfo, error)

type Column

type Column struct {
	Name       string `json:"name"`
	Type       string `json:"type"`
	Nullable   bool   `json:"nullable"`
	Primary    bool   `json:"primary"`
	Unique     bool   `json:"unique,omitempty"`
	Default    string `json:"default,omitempty"`
	References string `json:"references,omitempty"`
}

Column describes one table column and common relational constraints.

type Completion

type Completion struct {
	Value string `json:"value"`
	Kind  string `json:"kind"`
	Table string `json:"table,omitempty"`
}

Completion describes one SQL completion candidate.

type DataEditService

type DataEditService struct {
	Driver string
	DSN    string
}

DataEditService performs row-level table edits.

func (DataEditService) Delete

func (s DataEditService) Delete(ctx context.Context, tableName, whereClause string) (int, error)

func (DataEditService) Insert

func (s DataEditService) Insert(ctx context.Context, tableName string, values map[string]string) (int, error)

func (DataEditService) Update

func (s DataEditService) Update(ctx context.Context, tableName string, values map[string]string, whereClause string) (int, error)

type DumpOptions

type DumpOptions struct {
	Driver  string
	DSN     string
	Table   string
	Format  string
	MaxRows int
}

DumpOptions controls table export.

type ExecOptions

type ExecOptions struct {
	Format      string
	MaxRows     int
	Driver      string
	DSN         string
	Explain     bool
	Analyze     bool
	Transaction bool
}

ExecOptions carries execution settings from the presentation layer into the service and database layers.

type Executor

type Executor struct{}

Executor executes SQL through the configured database backend.

func (Executor) Exec

func (Executor) Exec(ctx context.Context, sql string, opts ExecOptions) (output.Result, error)

Exec executes sql according to opts. Without a database connection it supports a small built-in "select 1" response for smoke tests and demo flows.

func (Executor) Write

func (Executor) Write(ctx context.Context, w io.Writer, sql string, opts ExecOptions) (output.Result, error)

Write executes sql and writes the result directly to w when a database-backed connection is available. Demo-mode SQL still uses the in-memory result path.

type Index

type Index struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
	Unique  bool     `json:"unique"`
	Primary bool     `json:"primary,omitempty"`
}

Index describes one table index.

type LoadOptions

type LoadOptions struct {
	Driver string
	DSN    string
	Table  string
	Format string
}

LoadOptions controls table import.

type MetadataService

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

MetadataService serves schema metadata from either a live database or an in-memory fallback schema.

func NewConnectedMetadataService

func NewConnectedMetadataService(driver, dsn string) MetadataService

NewConnectedMetadataService returns a metadata service backed by a live database connection.

func NewConnectedMetadataServiceWithSchema

func NewConnectedMetadataServiceWithSchema(driver, dsn, schemaName string) MetadataService

NewConnectedMetadataServiceWithSchema returns a metadata service backed by a live database connection and constrained to schemaName when supported.

func NewMetadataService

func NewMetadataService() MetadataService

NewMetadataService returns an in-memory metadata service used when no live database connection is configured.

func (MetadataService) Columns

func (s MetadataService) Columns(ctx context.Context, tableName string) ([]Column, error)

Columns returns metadata for columns in tableName.

func (MetadataService) Complete

func (s MetadataService) Complete(ctx context.Context, prefix, tableName string) ([]Completion, error)

Complete returns keyword, table, and column candidates matching prefix.

func (MetadataService) DDL

func (s MetadataService) DDL(ctx context.Context, tableName string) (string, error)

DDL returns a CREATE TABLE statement for tableName when metadata is available.

func (MetadataService) Indexes

func (s MetadataService) Indexes(ctx context.Context, tableName string) ([]Index, error)

Indexes returns metadata for indexes in tableName.

func (MetadataService) MermaidER

func (s MetadataService) MermaidER(ctx context.Context) (string, error)

MermaidER renders the schema as a Mermaid ER diagram.

func (MetadataService) Schema

func (s MetadataService) Schema(ctx context.Context) (Schema, error)

Schema returns the complete schema for the configured metadata source.

func (MetadataService) Schemas

func (s MetadataService) Schemas(ctx context.Context) ([]string, error)

Schemas returns schema/database names for connected metadata sources.

func (MetadataService) Tables

func (s MetadataService) Tables(ctx context.Context) ([]Table, error)

Tables returns all known tables for the configured metadata source.

type MigrationService

type MigrationService struct {
	Driver string
	DSN    string
}

MigrationService applies and inspects SQL migrations.

func (MigrationService) Apply

func (s MigrationService) Apply(ctx context.Context, dir string, limit int) (db.MigrationResult, error)

func (MigrationService) Baseline

func (s MigrationService) Baseline(ctx context.Context, dir, version string) (db.MigrationResult, error)

func (MigrationService) Plan

func (s MigrationService) Plan(ctx context.Context, dir string, rollbackLimit int) (db.MigrationPlan, error)

func (MigrationService) Rollback

func (s MigrationService) Rollback(ctx context.Context, dir string, limit int) (db.MigrationResult, error)

func (MigrationService) Status

func (s MigrationService) Status(ctx context.Context, dir string) ([]db.Migration, error)

type Schema

type Schema struct {
	Name   string  `json:"name,omitempty"`
	Tables []Table `json:"tables"`
}

Schema is the service-layer representation of database metadata.

type SchemaChange

type SchemaChange struct {
	Type   string `json:"type"`
	Table  string `json:"table"`
	Name   string `json:"name,omitempty"`
	Detail string `json:"detail,omitempty"`
}

SchemaChange describes one schema difference.

type SchemaDiff

type SchemaDiff struct {
	Changes []SchemaChange `json:"changes"`
}

SchemaDiff contains human-readable schema differences.

func DiffSchemas

func DiffSchemas(from, to Schema) SchemaDiff

DiffSchemas compares two schema snapshots and reports table, column, and index additions/removals.

type Table

type Table struct {
	Schema  string   `json:"schema,omitempty"`
	Name    string   `json:"name"`
	Columns []Column `json:"columns"`
	Indexes []Index  `json:"indexes,omitempty"`
	DDL     string   `json:"ddl"`
}

Table describes one table or view exposed to CLI and TUI callers.

Jump to

Keyboard shortcuts

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