| 1 |
// _example/example.go |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"log" |
| 6 |
"os" |
| 7 |
|
| 8 |
_ "github.com/lib/pq" |
| 9 |
"github.com/xo/dburl" |
| 10 |
"github.com/xo/tblfmt" |
| 11 |
) |
| 12 |
|
| 13 |
func main() { |
| 14 |
db, err := dburl.Open("postgres://booktest:booktest@localhost") |
| 15 |
if err != nil { |
| 16 |
log.Fatal(err) |
| 17 |
} |
| 18 |
defer db.Close() |
| 19 |
res, err := db.Query("select * from authors") |
| 20 |
if err != nil { |
| 21 |
log.Fatal(err) |
| 22 |
} |
| 23 |
defer res.Close() |
| 24 |
enc, err := tblfmt.NewTableEncoder( |
| 25 |
res, |
| 26 |
// force minimum column widths |
| 27 |
tblfmt.WithWidths(20, 20), |
| 28 |
) |
| 29 |
if err = enc.EncodeAll(os.Stdout); err != nil { |
| 30 |
log.Fatal(err) |
| 31 |
} |
| 32 |
} |