db

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	ID     string
	Driver string
	DSN    string
	DB     *sql.DB
}

Connection represents an active database connection.

type ConnectionInfo

type ConnectionInfo struct {
	ID     string `json:"id"`
	Driver string `json:"driver"`
	DSN    string `json:"dsn"`
}

ConnectionInfo is a read-only summary of a connection (no *sql.DB exposed).

type Manager

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

Manager manages multiple database connections.

func NewManager

func NewManager() *Manager

NewManager creates a new Manager with an empty connection map.

func (*Manager) Connect

func (m *Manager) Connect(driver, dsn string) (string, error)

Connect opens a new database connection with the given driver and DSN. Supported drivers: "postgres", "sqlite3", "mysql". Returns the connection ID on success.

func (*Manager) Disconnect

func (m *Manager) Disconnect(id string) error

Disconnect closes and removes the connection with the given ID.

func (*Manager) Exec

func (m *Manager) Exec(id, query string, args ...any) (int64, error)

Exec executes a non-SELECT statement (INSERT, UPDATE, DELETE, etc.) on the given connection and returns the number of rows affected.

func (*Manager) Get

func (m *Manager) Get(id string) (*Connection, error)

Get returns the connection with the given ID or an error if not found.

func (*Manager) List

func (m *Manager) List() []ConnectionInfo

List returns info about all active connections.

func (*Manager) Query

func (m *Manager) Query(id, query string, args ...any) ([]map[string]any, error)

Query executes a SELECT query on the given connection and returns rows as a slice of maps. Each map key is a column name, each value is the column value (as returned by sql.Rows.Scan into *any).

Jump to

Keyboard shortcuts

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