import "github.com/Lavos/addata"
Ad Data is an application that creates a search index of all tables within a database, and allows a user to dump the contents of a table into a CSV-encoded file.
Building:
$ go build -o addata command/command.goUsage:
$ ./addata -c [JSON config file]var (
IndexCorrection = func(b []byte) [][]byte { return ferret.ErrorCorrect(b, ferret.LowercaseLetters) }
IndexSorter = func(s string, v interface{}, l int, i int) float64 { return -float64(l + i) }
IndexConverter = func(s string) []byte { return []byte(s) }
)type API struct {
Port uint
Server *web.Server
Store *Store
Index *Index
}API creates and managers a pointer to a web.Server, and has methods for the HTTP API so we can easily expose the other required types.
func NewAPI(port uint, i *Index, s *Store) *APINewAPI returns a pointer to a new API instance, creating all the required types for the API to function.
func (a *API) ReturnTable(ctx *web.Context, tablename string)ReturnTable returns a CSV-encoded download of a table's contents.
func (a *API) Run()Run starts the API instance, which in turn starts the web.Server.
func (a *API) Search(ctx *web.Context) []byteSearch searches for a given table name against the Index, and returns a list of string tablenames.
type Application struct {
API *API
Store *Store
Index *Index
}Application represents a collection of the other types within this package. This is the only type that most implementations will have to create, usually via NewApplication.
func NewApplication(c *Configuration) *ApplicationNewApplication returns a pointer to a new Application. Most implemenations will only need to call this to create all the required other types.
func (a *Application) Maintenance()Maintenance creates a loop that refreshs the index on an interval.
func (a *Application) Run()Run starts the Application, which then starts all the other required types within.
type Configuration struct {
Username, Password, Hostname, Database string
DBPort, APIPort uint
}Configuration maps directly to the passed JSON configuration file keys.
type Index struct {
InvertedSuffix *ferret.InvertedSuffix
QueryChan chan Query
RebuildChan chan []string
}Index stores the internal ferret.InvertedSuffix and required channels for concurrent access.
func NewIndex() *IndexNewIndex returns a pointer to a new Index.
func (i *Index) Query(term string) []stringQuery checks a given string against the internal ferret.InvertedSuffix and return a slice of string matches.
func (i *Index) RebuildWith(names []string)RebuildWith rebuilds the Index's internal ferret.InvertedSuffix with the supplied slice of strings.
func (i *Index) Run()Run starts the Index running it's required goroutines.
type Query struct {
Term string
ReturnChan chan []string
}Query gathers the required information to make a query together for ease of communication across channels.
type Store struct {
DSN string
DB *sql.DB
}Type Store stores the DSN for the Database access, derived from the Application Configuration.
func NewStore(dsn string) *StoreNewStore returns a pointer to a new Store
func (s *Store) GetTableNames() []stringGetTableNames returns a list of the string table names, gathered from the database.
func (s *Store) ReturnTable(tablename string) ([][]string, error)ReturnTable returns the rows of a table in a format that's applicable for CSV encoding in the API.
Generated by godoc2md