dblens

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 12 Imported by: 1

README

dblens

An HTTP handler for database browsing.

BEWARE: dblens.Handler accepts ALL queries, including destructive ones. Don't expose the handler to the wide public.

Usage

go get -u github.com/maragudk/dblens
package main

import (
	"database/sql"
	"errors"
	"log"
	"net/http"
	"os"

	_ "github.com/mattn/go-sqlite3"

	"github.com/maragudk/dblens"
)

func main() {
	os.Exit(start())
}

func start() int {
	log := log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile|log.LUTC)

	db, err := sql.Open("sqlite3", "app.db?_journal=WAL&_timeout=5000&_fk=true")
	if err != nil {
		log.Println("Error opening database:", err)
		return 1
	}

	log.Println("Starting on http://localhost:8080")

	if err := http.ListenAndServe("localhost:8080", dblens.Handler(db, "sqlite3")); err != nil &&
		!errors.Is(err, http.ErrServerClosed) {
		log.Println("Error:", err)
		return 1
	}

	return 0
}

Screenshot

screenshot.png

Made in 🇩🇰 by maragu, maker of online Go courses.

Documentation

Overview

Package dblens provides a Handler which returns an HTML page (or page fragment) to query a database. There are no authentication and authorization mechanisms included, and queries are passed verbatim to the database, so use with care!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(db *sql.DB, driverName string) http.HandlerFunc

Handler returns a http.Handler ready to be added to your routes. It returns an HTML page with a query input box and a table of results from the query, if any. If

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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