/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.

Primary LanguageGo

addata

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.go

Usage:

$ ./addata -c [JSON config file]

Variables

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

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

func NewAPI(port uint, i *Index, s *Store) *API

NewAPI returns a pointer to a new API instance, creating all the required types for the API to function.

func (*API) ReturnTable

func (a *API) ReturnTable(ctx *web.Context, tablename string)

ReturnTable returns a CSV-encoded download of a table's contents.

func (*API) Run

func (a *API) Run()

Run starts the API instance, which in turn starts the web.Server.

func (*API) Search

func (a *API) Search(ctx *web.Context) []byte

Search searches for a given table name against the Index, and returns a list of string tablenames.

type Application

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

func NewApplication(c *Configuration) *Application

NewApplication returns a pointer to a new Application. Most implemenations will only need to call this to create all the required other types.

func (*Application) Maintenance

func (a *Application) Maintenance()

Maintenance creates a loop that refreshs the index on an interval.

func (*Application) Run

func (a *Application) Run()

Run starts the Application, which then starts all the other required types within.

type Configuration

type Configuration struct {
    Username, Password, Hostname, Database string
    DBPort, APIPort                        uint
}

Configuration maps directly to the passed JSON configuration file keys.

type Index

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

func NewIndex() *Index

NewIndex returns a pointer to a new Index.

func (*Index) Query

func (i *Index) Query(term string) []string

Query checks a given string against the internal ferret.InvertedSuffix and return a slice of string matches.

func (*Index) RebuildWith

func (i *Index) RebuildWith(names []string)

RebuildWith rebuilds the Index's internal ferret.InvertedSuffix with the supplied slice of strings.

func (*Index) Run

func (i *Index) Run()

Run starts the Index running it's required goroutines.

type Query

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

type Store struct {
    DSN string
    DB  *sql.DB
}

Type Store stores the DSN for the Database access, derived from the Application Configuration.

func NewStore

func NewStore(dsn string) *Store

NewStore returns a pointer to a new Store

func (*Store) GetTableNames

func (s *Store) GetTableNames() []string

GetTableNames returns a list of the string table names, gathered from the database.

func (*Store) ReturnTable

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