Documentation
¶
Index ¶
- Constants
- type Count
- type Database
- type Erd
- type ErdColumn
- type ErdRelationship
- type ErdTable
- type Metadata
- type Options
- type Overview
- type Query
- type SQLiteDB
- func (d *SQLiteDB) Erd(ctx context.Context) (*Erd, error)
- func (d *SQLiteDB) Overview(ctx context.Context) (*Overview, error)
- func (d *SQLiteDB) Query(ctx context.Context, query string) (*Query, error)
- func (d *SQLiteDB) Table(ctx context.Context, name string) (*Table, error)
- func (d *SQLiteDB) TableData(ctx context.Context, name string, page int) (*TableData, error)
- func (d *SQLiteDB) Tables(ctx context.Context) (*Tables, error)
- func (d *SQLiteDB) TablesWithColumns(ctx context.Context) (*TablesWithColumns, error)
- type Server
- type Table
- type TableData
- type TableWithColumns
- type Tables
- type TablesWithColumns
Constants ¶
const ROWS_PER_PAGE = 50
ROWS_PER_PAGE is the number of rows returned per page of table data. Mirrors the Rust constant ROWS_PER_PAGE.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface {
Overview(ctx context.Context) (*Overview, error)
Tables(ctx context.Context) (*Tables, error)
Table(ctx context.Context, name string) (*Table, error)
TableData(ctx context.Context, name string, page int) (*TableData, error)
TablesWithColumns(ctx context.Context) (*TablesWithColumns, error)
Query(ctx context.Context, query string) (*Query, error)
Erd(ctx context.Context) (*Erd, error)
}
Database is the interface every backend implements to serve the UI's API. It mirrors the Rust `Database` trait. Additional backends (Postgres, MySQL, etc.) can be added later by implementing this interface.
type Erd ¶
type Erd struct {
Tables []ErdTable `json:"tables"`
Relationships []ErdRelationship `json:"relationships"`
}
type ErdRelationship ¶
type Options ¶
type Options struct {
// Address to bind to, e.g. "127.0.0.1:3030".
Address string
// BasePath to serve the UI under, e.g. "/sql-studio". Empty for root.
// Must start with "/" when set.
BasePath string
// NoShutdown disables the /api/shutdown endpoint and the UI shutdown button.
NoShutdown bool
// Version reported by /api/metadata.
Version string
}
Options configures the HTTP server. Mirrors the relevant Rust CLI args.
type Overview ¶
type Overview struct {
FileName string `json:"file_name"`
DBSize string `json:"db_size"`
SQLiteVersion *string `json:"sqlite_version"`
Created *time.Time `json:"created"`
Modified *time.Time `json:"modified"`
Tables int `json:"tables"`
Indexes int `json:"indexes"`
Triggers int `json:"triggers"`
Views int `json:"views"`
RowCounts []Count `json:"row_counts"`
ColumnCounts []Count `json:"column_counts"`
IndexCounts []Count `json:"index_counts"`
}
type SQLiteDB ¶
type SQLiteDB struct {
// contains filtered or unexported fields
}
SQLiteDB is the SQLite implementation of Database. It ports the Rust `sqlite` module, reusing the same SQL queries and result ordering.
func NewSQLite ¶
NewSQLite wraps an already-open *sql.DB in a *SQLiteDB without opening a new connection or mutating the pool. The caller owns the handle's lifecycle and tuning (e.g. SetMaxOpenConns); SQL Studio never closes the injected handle, so db must outlive the server. path is retained only for os.Stat-based file metadata in Overview and Tables and is not used to open db.
func OpenSQLite ¶
OpenSQLite opens a SQLite database. If path == "preview", the bundled sample database is written to "sample.db" and opened read-only; otherwise the file at path is opened read-write. sample is the embedded sample DB bytes (see server.SampleDB()).
func (*SQLiteDB) TablesWithColumns ¶
func (d *SQLiteDB) TablesWithColumns(ctx context.Context) (*TablesWithColumns, error)
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the embedded UI and the JSON API backed by a Database.
func New ¶
New builds a Server. The ui filesystem holds the built UI assets (e.g. an embed.FS rooted at the dist directory); the caller owns embedding so this package stays free of bundled binaries. New reads and rewrites index.html according to opts.BasePath, mirroring the Rust startup logic.
func (*Server) Handler ¶
Handler returns the fully-wired HTTP handler: the JSON API and the embedded UI, all served under the server's prefix (see Prefix). A host application can reach into this package as a library and mount the returned handler, e.g.:
mux.Handle(srv.Prefix()+"/", srv.Handler())
http.ServeMux does not strip the matched pattern before dispatching, so the inner handler still sees the full Prefix()+"/..." path and routes it correctly. CORS is applied to the app routes; the prefix redirects are not wrapped. Under such a subtree mount the host owns "/", so the inner standalone-root redirect below is unreachable (and harmless) — it exists only for running this handler directly as a standalone server.
type TableWithColumns ¶
type TablesWithColumns ¶
type TablesWithColumns struct {
Tables []TableWithColumns `json:"tables"`
}