database

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyQuery         = errors.New("query is required")
	ErrMultipleStatements = errors.New("only a single SQL statement is allowed")
	ErrUnsafeQuery        = errors.New("only read-only SQL statements are allowed")
)

Functions

This section is empty.

Types

type ColumnSchema

type ColumnSchema struct {
	Name         string  `json:"name"`
	DataType     string  `json:"data_type"`
	Nullable     bool    `json:"nullable"`
	PrimaryKey   bool    `json:"primary_key"`
	DefaultValue *string `json:"default_value,omitempty"`
}

type QueryColumn

type QueryColumn struct {
	Name     string `json:"name"`
	DataType string `json:"data_type"`
}

type QueryRequest

type QueryRequest struct {
	SQL   string `json:"sql"`
	Limit int    `json:"limit"`
}

type QueryResponse

type QueryResponse struct {
	Dialect       string        `json:"dialect"`
	ReadOnly      bool          `json:"read_only"`
	StatementType string        `json:"statement_type"`
	Query         string        `json:"query"`
	Limit         int           `json:"limit"`
	DurationMs    int64         `json:"duration_ms"`
	RowCount      int           `json:"row_count"`
	Truncated     bool          `json:"truncated"`
	Columns       []QueryColumn `json:"columns"`
	Rows          [][]any       `json:"rows"`
}

type SchemaResponse

type SchemaResponse struct {
	Dialect  string        `json:"dialect"`
	Version  string        `json:"version,omitempty"`
	ReadOnly bool          `json:"read_only"`
	Tables   []TableSchema `json:"tables"`
}

type Service

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

func New

func New(ctx context.Context) *Service

func NewWithDB

func NewWithDB(ctx context.Context, gdb *gorm.DB) *Service

func (*Service) Query

func (s *Service) Query(req QueryRequest) (resp *QueryResponse, err error)

func (*Service) Schema

func (s *Service) Schema() (*SchemaResponse, error)

type TableSchema

type TableSchema struct {
	Name     string         `json:"name"`
	RowCount *int64         `json:"row_count,omitempty"`
	Columns  []ColumnSchema `json:"columns"`
}

Jump to

Keyboard shortcuts

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