Documentation ¶
Overview ¶
Package db provides helper functions to access the pocoweb database.
Index ¶
- Constants
- func AuthenticateUser(db DB, user api.User, password string) error
- func Begin(db DB) (*sql.Tx, error)
- func CreateAllTables(db DB) error
- func CreateTableBooks(db DB) error
- func CreateTableJobs(db DB) error
- func CreateTableLines(db DB) error
- func CreateTablePages(db DB) error
- func CreateTableProjectPages(db DB) error
- func CreateTableProjects(db DB) error
- func CreateTableSessions(db DB) error
- func CreateTableSuggestions(db DB) error
- func CreateTableTypes(db DB) error
- func CreateTableUsers(db DB) error
- func DeleteJobByID(db DB, jobID int) error
- func DeleteSessionByUserID(db DB, id int64) error
- func DeleteUserByID(db DB, id int64) error
- func Exec(db DB, stmt string, args ...interface{}) (sql.Result, error)
- func FindAllUsers(db DB) ([]api.User, error)
- func FindBookPages(db DB, bookID int) ([]int, error)
- func FindJobByID(db DB, jobID int) (*api.JobStatus, bool, error)
- func FindPageLines(db DB, bookID, pageID int) ([]int, error)
- func FindProjectPages(db DB, projectID int) ([]int, error)
- func FindSessionByID(db DB, id string) (*api.Session, bool, error)
- func FindUserByEmail(db DB, email string) (api.User, bool, error)
- func FindUserByID(db DB, id int64) (api.User, bool, error)
- func InsertBook(db DB, book *Book) error
- func InsertLine(db DB, line *Line) error
- func InsertPage(db DB, page *Page) error
- func InsertProject(db DB, p *Project) error
- func InsertSession(db DB, u api.User) (*api.Session, error)
- func InsertUser(db DB, user *api.User) error
- func NewJob(db DB, bookID int, text string) (int, error)
- func NewType(db DB, str string, ids map[string]int) (int, error)
- func Query(db DB, stmt string, args ...interface{}) (*sql.Rows, error)
- func SetJobStatus(db DB, jobID, statusID int) error
- func SetJobStatusWithText(db DB, jobID, statusID int, text string) error
- func SetUserPassword(db DB, user api.User, password string) error
- func UpdateLine(db DB, line *Line) error
- func UpdateUser(db DB, user api.User) error
- type Book
- type BookWithContent
- type Char
- type Chars
- func (cs Chars) AverageConfidence() float64
- func (cs Chars) Cor() string
- func (cs Chars) IsFullyCorrected() bool
- func (cs Chars) IsPartiallyCorrected() bool
- func (cs Chars) NextWord() (word, rest Chars)
- func (cs Chars) OCR() string
- func (cs Chars) Trim(f func(Char) bool) Chars
- func (cs Chars) TrimLeft(f func(Char) bool) Chars
- func (cs Chars) TrimRight(f func(Char) bool) Chars
- type DB
- type Line
- type Page
- type PageWithContent
- type Project
- type Transaction
- func (t *Transaction) Begin() (*sql.Tx, error)
- func (t *Transaction) Do(f func(DB) error)
- func (t *Transaction) Done() error
- func (t *Transaction) Exec(stmt string, args ...interface{}) (sql.Result, error)
- func (t *Transaction) Prepare(query string) (*sql.Stmt, error)
- func (t *Transaction) Query(stmt string, args ...interface{}) (*sql.Rows, error)
- type TypeInserter
Constants ¶
const ( StatusIDFailed = iota StatusIDRunning StatusIDDone StatusIDEmpty StatusIDProfiled StatusIDPostCorrected StatusIDExtendedLexicon StatusIDProfiledWithEL )
Status IDs
const ( StatusFailed = "failed" StatusRunning = "running" StatusDone = "done" StatusEmpty = "empty" StatusProfiled = "profiled" StatusPostCorrected = "post-corrected" StatusExtendedLexicon = "extended-lexicon" StatusProfiledWithEL = "profiled-with-el" )
Status names
const ( // IDLength defines the length of auth tokens. IDLength = 10 // Expires defines the time after a session expires Expires = 10 * time.Hour )
const ( TypesTableName = "types" // Name of the types table. TypesTableID = "ID" // ID field TypesTableType = "typ" // type field MaxType = 50 // Max length of type strings )
const ( SuggestionsTableName = "suggestions" SuggestionsTableID = "id" SuggestionsTableBookID = "bookid" SuggestionsTableTokenTypeID = "tokentypid" SuggestionsTableSuggestionTypeID = "suggestiontypid" SuggestionsTableModernTypeID = "moderntypid" SuggestionsTableDict = "dict" SuggestionsTableWeight = "weight" SuggestionsTableTopSuggestion = "topsuggestion" SuggestionsTableDistance = "distance" SuggestionsTableHistPatterns = "histpatterns" SuggestionsTableOCRPatterns = "ocrpatterns" )
const ( // HashLength defines the lenght of the password hash. HashLength = 64 // SaltLength defines the length of the salt. SaltLength = 32 )
const BooksTableName = "books"
const ContentsTableName = "contents"
ContentsTableName defines the name of the contents table.
const JobsTableName = "jobs"
JobsTableName defines the name of the jobs table.
const PagesTableName = "pages"
const ProjectPagesTableName = "project_pages"
const ProjectsTableName = "projects"
ProjectsTableName of the the database table.
const SessionsTableName = "sessions"
Name defines the name of the sessions table.
const StatusTableName = "status"
StatusTableName defines the name of the jobs status table.
const TextLinesTableName = "textlines"
TextLinesTableName defines the name of the textlines table.
const UsersTableName = "users"
Name of the table
Variables ¶
This section is empty.
Functions ¶
func CreateAllTables ¶
CreateAllTables creates all tables in the right order. The order is: users -> projects -> books -> pages -> lines.
func CreateTableBooks ¶
CreateTableBooks the database table books if it does not already exist. This function will fail, if the projects table does not exist.
func CreateTableJobs ¶ added in v0.8.0
CreateTableJobs creates the jobs and jobs status database tables if they do not already exist.
func CreateTableLines ¶
CreateTableLines creates the two tables needed for the storing of text lines in the right order. The creation will fail, if the books and pages tables do not yet exist.
func CreateTablePages ¶
CreateTablePages creates the databases table pages if it does not already exist. This function will fail if the table books does not exist.
func CreateTableProjectPages ¶ added in v0.3.0
func CreateTableProjects ¶
CreateTableProjects creates the project table if it does not already exist. This function will fail, if the users table does not already exist.
func CreateTableSessions ¶
CreateTableSessions creates the sessions table.
func CreateTableSuggestions ¶ added in v0.9.2
CreateTableSuggestions creates the suggestion table.
func CreateTableTypes ¶ added in v0.9.1
CreateTableTypes creates the types table.
func CreateTableUsers ¶
CreateTableUsers creates the users table if it does not already exist.
func DeleteJobByID ¶ added in v0.8.0
DeleteJobByID delete the given job from the database table.
func DeleteSessionByUserID ¶
func DeleteUserByID ¶
func FindAllUsers ¶ added in v0.2.0
FindAllUsers returns all users in the database.
func FindBookPages ¶ added in v0.7.0
FindBookPages returns the page IDs for the given book.
func FindJobByID ¶ added in v0.8.0
FindJobByID returns the given job
func FindPageLines ¶ added in v0.6.0
FindPageLines returns all line IDs for the page identified by the given book and page IDs.
func FindProjectPages ¶ added in v0.3.0
FindProjectPages returns the page IDs for the given project.
func InsertBook ¶
func InsertLine ¶
InsertLine inserts the given line into the database.
func InsertPage ¶
func InsertProject ¶
func InsertSession ¶
InsertSession creates a new unique session for the given user in the database and returns the new session.
func InsertUser ¶
InsertUser inserts a new user into the database. The user's id is adjusted accordingly.
func NewJob ¶ added in v0.9.0
NewJob inserts a new running job into the jobs table and returns the new job ID.
func NewType ¶ added in v0.9.1
NewType inserts a new (string-) type into the types tables and returns its id. If the type does already exist in the table, the id of the existing string is returned and nothing is inserted into the table. All types are converted to lowercase.
An additional map can be supplied to speed up the creation of types. A nil map can be supplied.
func SetJobStatus ¶ added in v0.8.0
SetJobStatus sets a new status for a job.
func SetJobStatusWithText ¶ added in v0.9.2
SetJobStatusWithText sets a new status and text (name) for a job.
func UpdateLine ¶
UpdateLine updates the contents for the given line.
Types ¶
type Book ¶
type Book struct {
BookID, Year int
Status map[string]bool
Author, Title, Description, HistPatterns string
URI, ProfilerURL, Directory, Lang string
Pooled bool
}
func FindBookByID ¶ added in v0.4.0
FindBookByID loads the book from the database that is identified by the given ID.
type BookWithContent ¶ added in v0.9.2
type BookWithContent struct { Book Pages map[int]*PageWithContent }
func LoadBookWithContent ¶ added in v0.9.2
func LoadBookWithContent(db DB, bid, pid, lid int) (*BookWithContent, bool, error)
type Chars ¶ added in v0.6.0
type Chars []Char
Chars defines a slice of characters.
func (Chars) AverageConfidence ¶ added in v0.6.0
AverageConfidence calculates the average confidence of the character slice.
func (Chars) IsFullyCorrected ¶ added in v0.6.0
IsFullyCorrected returns true if all characters in the slice have been corrected.
func (Chars) IsPartiallyCorrected ¶ added in v0.6.0
IsPartiallyCorrected returns true if a part of the character slice contains corrections.
func (Chars) NextWord ¶ added in v0.9.1
NextWord returns the next word and the rest in this character sequence. A word/token is any sequence of non whitespace characters. Deletions are ignored.
type DB ¶
type DB interface { Exec(string, ...interface{}) (sql.Result, error) Query(string, ...interface{}) (*sql.Rows, error) Begin() (*sql.Tx, error) Prepare(string) (*sql.Stmt, error) }
DB defines a simple interface for database handling.
type Line ¶
type Line struct { ImagePath string Chars Chars LineID int PageID int BookID int Left, Right, Top, Bottom int }
Line defines the line of a page in a book.
type PageWithContent ¶ added in v0.9.2
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction wraps a sql.Tx to abbort database transactions.
func NewTransaction ¶
func NewTransaction(tx *sql.Tx, err error) *Transaction
func (*Transaction) Begin ¶
func (t *Transaction) Begin() (*sql.Tx, error)
Begin return this transaction's Tx object with all active errors encountered so far.
func (*Transaction) Do ¶
func (t *Transaction) Do(f func(DB) error)
Do runs a function within the transaction.
func (*Transaction) Done ¶
func (t *Transaction) Done() error
Done commits the transaction if no error was encountered during the execution. If an error was encountered, the whole transaction is rolled back.
func (*Transaction) Exec ¶
func (t *Transaction) Exec(stmt string, args ...interface{}) (sql.Result, error)
type TypeInserter ¶ added in v0.14.10
type TypeInserter struct {
// contains filtered or unexported fields
}
TypeInserter helps handle types with their according type IDs.
func NewTypeInserter ¶ added in v0.14.10
func NewTypeInserter(db *sql.DB) (*TypeInserter, error)
NewTypeInserter constructs a new TypeInserter instance.
func (*TypeInserter) Close ¶ added in v0.14.10
func (t *TypeInserter) Close() (err error)
Close closes the database connections.