Documentation
¶
Index ¶
- func BuildDSN(dbType, host, user, password, dbName, extraParams string, port int) (string, error)
- func NewDB(dbType, dsn string) (*sql.DB, error)
- func QueryResultToJSON(qr *QueryResult) ([]byte, error)
- func Register(dbType string, p Provider)
- type ColumnDef
- type ColumnInfo
- type DBCapabilities
- type ExecResult
- type IndexDef
- type IndexInfo
- type Provider
- type QueryResult
- type QueryResultColumn
- type SchemaResult
- type TableInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QueryResultToJSON ¶
func QueryResultToJSON(qr *QueryResult) ([]byte, error)
QueryResultToJSON serializes a QueryResult to JSON bytes.
Types ¶
type ColumnDef ¶
type ColumnDef struct {
Name string `json:"name"`
Type string `json:"type"`
Nullable bool `json:"nullable"`
DefaultVal string `json:"defaultVal"`
DefaultType string `json:"defaultType"` // "none" | "null" | "value" | "auto"
Comment string `json:"comment"`
Collation string `json:"collation"`
OnUpdate bool `json:"onUpdate"`
}
ColumnDef is the structured input for adding or modifying a column.
type ColumnInfo ¶
type ColumnInfo struct {
Name string `json:"name"`
Type string `json:"type"`
Nullable bool `json:"nullable"`
DefaultVal string `json:"defaultVal"`
DefaultType string `json:"defaultType"` // "none" | "null" | "value" | "auto"
IsPrimary bool `json:"isPrimary"`
Comment string `json:"comment"`
Collation string `json:"collation"`
OnUpdate bool `json:"onUpdate"`
}
type DBCapabilities ¶
DBCapabilities describes the features supported by a database type. Providers return only the fields they override; unset fields use defaults.
func MergeCapabilities ¶
func MergeCapabilities(overrides DBCapabilities) DBCapabilities
MergeCapabilities merges provider overrides into the default config.
type ExecResult ¶
type ExecResult struct {
Affected int64 `json:"affected"`
LastInsertID int64 `json:"lastInsertId"`
}
func ExecuteStatement ¶
type IndexDef ¶
type IndexDef struct {
Name string `json:"name"`
Columns []string `json:"columns"`
Unique bool `json:"unique"`
IsPrimary bool `json:"isPrimary"`
}
IndexDef is the structured input for creating an index.
type Provider ¶
type Provider interface {
// DSN generates a driver-specific connection string from connection fields.
DSN(host string, port int, user, password, dbName string, extraParams map[string]string) string
// DriverName returns the Go SQL driver name to use for sql.Open.
DriverName() string
// Quote returns an identifier quoted for this database.
Quote(name string) string
// Schema discovery
GetDatabases(db *sql.DB) ([]string, error)
GetTables(db *sql.DB, dbName string) ([]TableInfo, error)
GetTableSchema(db *sql.DB, dbName, tableName string) (*SchemaResult, error)
// DefaultTableQuery returns the default SELECT statement used when opening a table.
DefaultTableQuery(dbName, tableName string, limit int) string
// Row-level CRUD helpers for the result-grid inline actions.
InsertRow(db *sql.DB, dbName, tableName string, values map[string]any) error
UpdateRow(db *sql.DB, dbName, tableName string, set, where map[string]any) error
DeleteRow(db *sql.DB, dbName, tableName string, where map[string]any) error
// DDL: Database
CreateDatabase(db *sql.DB, dbName string) error
DropDatabase(db *sql.DB, dbName string) error
// DDL: Table
CreateTable(db *sql.DB, dbName, tableName string) error
DropTable(db *sql.DB, dbName, tableName string) error
DropView(db *sql.DB, dbName, viewName string) error
TruncateTable(db *sql.DB, dbName, tableName string) error
// DDL: Column
AddColumn(db *sql.DB, dbName, tableName string, col ColumnDef) error
ModifyColumn(db *sql.DB, dbName, tableName string, col ColumnDef) error
DropColumn(db *sql.DB, dbName, tableName string, colName string) error
// DDL: Index
AddIndex(db *sql.DB, dbName, tableName string, idx IndexDef) error
DropIndex(db *sql.DB, dbName, tableName string, idxName string, isPrimary bool, autoIncCols []string) error
// Capabilities
GetCapabilities() DBCapabilities
// PrepareExec executes any per-database setup before running user SQL.
PrepareExec(db execer, dbName string) error
}
Provider encapsulates all database-type-specific behavior.
func NewProvider ¶
NewProvider returns the Provider for the given database type, or an error if the type is not supported.
type QueryResult ¶
type QueryResult struct {
Columns []QueryResultColumn `json:"columns"`
Rows []map[string]any `json:"rows"`
}
func ExecuteQuery ¶
type QueryResultColumn ¶
type SchemaResult ¶
type SchemaResult struct {
Columns []ColumnInfo `json:"columns"`
Indexes []IndexInfo `json:"indexes"`
}
Click to show internal directories.
Click to hide internal directories.