qp

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 9 Imported by: 0

README

qp

Printer that prints the results of a query to the database.

Usage

package main

import (
	"database/sql"
	"log"

	"github.com/k1LoW/qp"
	_ "github.com/mattn/go-sqlite3"
)

func main() {
	db, err := sql.Open("sqlite3", "path/to/db")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	_, _, = qp.Print(db, "SELECT * FROM users WHERE username = 'alice'")
}
$ go run main.go
+----+----------+----------+-------------------+---------------------+---------+
| id | username | password |       email       |       created       | updated |
+----+----------+----------+-------------------+---------------------+---------+
|  1 | alice    | passw0rd | alice@example.com | 2017-12-05 00:00:00 | <nil>   |
+----+----------+----------+-------------------+---------------------+---------+
(1 row)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(db Querier, stmt string) (int, error)

Types

type Option

type Option func(*QueryPrinter) error

func Context

func Context(ctx context.Context) Option

func Out

func Out(out io.Writer) Option

type Querier

type Querier interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

type QueryPrinter

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

func New

func New(db Querier, opts ...Option) *QueryPrinter

func (*QueryPrinter) Print

func (qp *QueryPrinter) Print(stmt string) (int, error)

Jump to

Keyboard shortcuts

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