package
0.0.1
Repository: https://github.com/ttacon/go-utils.git
Documentation: pkg.go.dev

# README

sqlutil

Package sqlutil is a package that contains several useful utility functions for interacting with sql databases.

When connecting to a database with a specific dsn ([user]:[password]@/[database]), information such as what databases on the current host are available to the current user, what tables are availble for a given database and how a given table was defined is not easily available. This collection of functions drastically simplifies the retreival of this information, as the following code demonstrates.

Usage

// assuming we have a *sql.DB from db, err := sql.Open(...)
// we create a SqlUtil
sqlUtil := sqlutil.New(db)

// We can then retrieve the databases on the host with
dbs, err := sqlUtil.ShowDatabases()

// We can show the tables for a given database with
tables, err := sqlUtil.ShowTables("myDB")

// And we can see how a table is defined with
columns, err := sqlUtil.DescribeTable("myTable")

Hope you find these useful!

Examples

There are a bunch of examples under the examples/ directory (they are each under their own package so you can go build/install them to play around with).

Links

Godoc: http://godoc.org/github.com/ttacon/go-utils/db/sqlutil

# Packages

No description provided by the author

# Functions

New returns a SqlUtil which uses the given db connection to communicate with the desired database host.

# Structs

ColumnInfo describes the six fields of information for a column in a SQL table.
SqlUtil is useful for extra information about a database, it has wrapper functions to show what databases exist on the host specified by dsn (or at least those that the user specified by the dsn can see), for showing what tables exist on a database and for describing a database table.