database

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package database provides database interactions using sqlx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path string // Database file path
}

Config holds database configuration options

type DB

type DB struct {
	*sqlx.DB // Embed sqlx.DB
}

DB holds the database connection pool using sqlx.

func New

func New(dataSourceName string) (*DB, error)

New initializes the database connection using sqlx and ensures the schema is up-to-date.

func (*DB) AddServer

func (db *DB) AddServer(name, url string) (int64, error)

AddServer inserts a new server and returns its ID.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) GetServerByID

func (db *DB) GetServerByID(id int64) (*models.MCPServer, error)

GetServerByID retrieves a server by its ID.

func (*DB) GetServerByURL

func (db *DB) GetServerByURL(url string) (*models.MCPServer, error)

GetServerByURL retrieves a server by its URL.

func (*DB) ListServers

func (db *DB) ListServers() ([]models.MCPServer, error)

ListServers retrieves all servers.

func (*DB) ListTools

func (db *DB) ListTools() ([]models.Tool, error)

ListTools retrieves all tools from the database.

func (*DB) ListToolsByServerID

func (db *DB) ListToolsByServerID(serverID int64) ([]models.Tool, error)

ListToolsByServerID retrieves all tools for a specific server.

func (*DB) RemoveServer

func (db *DB) RemoveServer(id int64) error

RemoveServer deletes a server by its ID.

func (*DB) RemoveToolsByServerID

func (db *DB) RemoveToolsByServerID(serverID int64) error

RemoveToolsByServerID deletes all tools associated with a specific server ID.

func (*DB) UpdateServerDetails

func (db *DB) UpdateServerDetails(id int64, name, url string) error

UpdateServerDetails updates the name and URL for a server.

func (*DB) UpdateServerStatus

func (db *DB) UpdateServerStatus(id int64, state models.ConnectionState, lastError *string, lastCheck time.Time) error

UpdateServerStatus updates the connection state, error message, and last checked timestamp for a server.

func (*DB) UpsertTool

func (db *DB) UpsertTool(tool models.Tool) (err error)

UpsertTool inserts a new tool or updates an existing one based on external_id and source_server_id.

type DBInterface

type DBInterface interface {
	// Server Management
	AddServer(name, url string) (int64, error)
	ListServers() ([]models.MCPServer, error)
	GetServerByID(id int64) (*models.MCPServer, error)
	GetServerByURL(url string) (*models.MCPServer, error)
	RemoveServer(id int64) error
	UpdateServerStatus(id int64, state models.ConnectionState, lastError *string, lastCheck time.Time) error
	UpdateServerDetails(id int64, name, url string) error

	// Tool Management
	UpsertTool(tool models.Tool) error
	ListTools() ([]models.Tool, error)
	ListToolsByServerID(serverID int64) ([]models.Tool, error)
	RemoveToolsByServerID(serverID int64) error

	// General
	Close() error
}

DBInterface defines the operations for interacting with the database.

Jump to

Keyboard shortcuts

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