sqembv

package module
v0.0.0-...-cb638f8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 15 Imported by: 0

README

sqembv

sqembv is a Golang embedded web-based SQLite database "browser". It is a fork of sqlite-gobroem which is a little bit modernized and improved.

Main reason for the fork was extremely slow compilation speed of the original project. Also, this fork switched to CGO-optional SQLite driver and fixes some bugs.

Warning: avoid exposing this tool to the public Internet. It does not provide any authentication or authorization and can be used to read and modify your database.

Note: While the original project (and this fork) claims to be a "browser", it allows to execute arbitrary SQL queries.

Embedded Use

Include sqembv in your application:

import "github.com/andrianbdn/sqembv"

Initialize the API controller:

api, err := sqembv.NewAPI("test.sqlite3")
if err != nil {
    log.Fatalln("can not open db:", err)
}

Register the API handler:

http.Handle("/browser/", api.Handler("/browser/"))

or, even better — register it with HTTP basic auth (minimal implementation below)

h := api.Handler("/browser/")

u, p := "sql-user", "PasSw0rd" // Username and Password - CHANGE the password!
golden := "Basic " + base64.StdEncoding.EncodeToString([]byte(u+":"+p))

http.HandleFunc("/browser/", func(w http.ResponseWriter, r *http.Request) {
  if a := r.Header.Get("Authorization"); subtle.ConstantTimeCompare([]byte(a), []byte(golden)) != 1 {
    w.Header().Set("WWW-Authenticate", `Basic realm="restricted", charset="UTF-8"`)
    http.Error(w, "Unauthorized", http.StatusUnauthorized)
    return
  }
  h.ServeHTTP(w, r)
})

Standalone

Use go install to install the latest version of the program:

$ go install github.com/andrianbdn/sqembv/cmd/sqembv@latest

Run sqembv:

$ ./sqembv -h

sqembv, v0.1.1
Usage of ./sqembv:
  -bind string
        HTTP server host (default "localhost")
  -db string
        SQLite database file (default "test.sqlite3")
  -license
        Print program license and exit
  -listen uint
        HTTP server listen port (default 8000)


$ ./sqembv

Open browser http://localhost:8000/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func License

func License() string

func SliceScan

func SliceScan(r *sql.Rows) ([]interface{}, error)

SliceScan a row, returning a []interface{} with values similar to MapScan. This function is primarily intended for use where the number of columns is not known. Because you can pass an []interface{} directly to Scan, it's recommended that you do that as it will not have to allocate new slices per row.

Types

type API

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

API ...

func NewAPI

func NewAPI(dbFile string) (*API, error)

NewAPI initializes the API controller with a DB file.

func NewAPIFromDB

func NewAPIFromDB(db *sql.DB) (*API, error)

NewAPIFromDB initializes the API controller with a DB.

func (*API) Handler

func (a *API) Handler(browserRoot string) http.Handler

Handler ...

func (*API) Info

func (a *API) Info(w http.ResponseWriter, req *http.Request)

Info ...

func (*API) Query

func (a *API) Query(w http.ResponseWriter, req *http.Request)

Query ...

func (*API) Table

func (a *API) Table(w http.ResponseWriter, req *http.Request)

Table ...

func (*API) TableIndexes

func (a *API) TableIndexes(w http.ResponseWriter, req *http.Request)

TableIndexes ...

func (*API) TableInfo

func (a *API) TableInfo(w http.ResponseWriter, req *http.Request)

TableInfo ...

func (*API) TableSQL

func (a *API) TableSQL(w http.ResponseWriter, req *http.Request)

TableSQL ...

func (*API) Tables

func (a *API) Tables(w http.ResponseWriter, req *http.Request)

Tables ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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