xsql

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

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

Go to latest
Published: Jun 8, 2019 License: MIT Imports: 5 Imported by: 1

README

xsql Build Status Go Report Card GoDoc

SQL Query Results Pretty Printing

Dependencies

Examples

Example 1

package main

import (
	"database/sql"
	"fmt"
	"github.com/shomali11/xsql"
	"log"
)

const (
	dataSourceFormat = "user=%s password=%s dbname=%s sslmode=disable"
)

func main() {
	dataSource := fmt.Sprintf(dataSourceFormat, "<USERNAME>", "<PASSWORD>", "<DATABASE_NAME>")
	db, err := sql.Open("<DRIVER>", dataSource)
	if err != nil {
		log.Fatal(err)
	}

	defer db.Close()

	rows, err := db.Query("SELECT * FROM test")
	if err != nil {
		log.Fatal(err)
	}

	results, err := xsql.Pretty(rows)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(results)
}

Output:

 id  |      name      |         title         |         created_at          | number | decimal | active
-----+----------------+-----------------------+-----------------------------+--------+---------+--------
   1 | Raed Shomali   | Sr. Software Engineer | 2017-10-24T20:59:43.37154Z  |     11 | 789.123 | true
   2 | Dwayne Johnson | The Rock              | 2017-10-24T21:00:31.530534Z |   1000 |     3.7 | true
 300 | Steve Austin   | Stone Cold            | 2017-10-26T19:42:51.993465Z |  55000 |   55.55 | false
(3 rows)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pretty

func Pretty(rows *sql.Rows) (string, error)

Pretty returns a pretty sql string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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