Documentation
¶
Overview ¶
Package db provides the high-level database interface for the storage app.
Index ¶
- func RegisterOpenHook(driverName string, hook func(*sql.DB) error)
- type DB
- func (db *DB) Close() error
- func (db *DB) CountUploads() (int, error)
- func (db *DB) ListUploads(q string, extraLabels []string, limit int) *UploadList
- func (db *DB) NewUpload(ctx context.Context) (*Upload, error)
- func (db *DB) Query(q string) *Query
- func (db *DB) ReplaceUpload(id string) (*Upload, error)
- type Query
- type Upload
- type UploadList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a high-level interface to a database for the storage app. It's safe for concurrent use by multiple goroutines.
func OpenSQL ¶
OpenSQL creates a DB backed by a SQL database. The parameters are the same as the parameters for sql.Open. Only mysql and sqlite3 are explicitly supported; other database engines will receive MySQL query syntax which may or may not be compatible.
func (*DB) CountUploads ¶
CountUploads returns the number of uploads in the database.
func (*DB) ListUploads ¶
func (db *DB) ListUploads(q string, extraLabels []string, limit int) *UploadList
ListUploads searches for uploads containing results matching the given query string. The query may be empty, in which case all uploads will be returned. For each label in extraLabels, one unspecified record's value will be obtained for each upload. If limit is non-zero, only the limit most recent uploads will be returned.
func (*DB) NewUpload ¶
NewUpload returns an upload for storing new files. All records written to the Upload will have the same upload ID.
func (*DB) Query ¶
Query searches for results matching the given query string.
The query string is first parsed into quoted words (as in the shell) and then each word must be formatted as one of the following: key:value - exact match on label "key" = "value" key>value - value greater than (useful for dates) key<value - value less than (also useful for dates)
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is the result of a query. Use Next to advance through the rows, making sure to call Close when done:
q := db.Query("key:value") defer q.Close() for q.Next() { res := q.Result() ... } err = q.Err() // get any error encountered during iteration ...
type Upload ¶
type Upload struct { // ID is the value of the "upload" key that should be // associated with every record in this upload. ID string // contains filtered or unexported fields }
An Upload is a collection of files that share an upload ID.
type UploadList ¶
type UploadList struct {
// contains filtered or unexported fields
}
UploadList is the result of ListUploads. Use Next to advance through the rows, making sure to call Close when done:
q := db.ListUploads("key:value") defer q.Close() for q.Next() { info := q.Info() ... } err = q.Err() // get any error encountered during iteration ...
func (*UploadList) Close ¶
func (ul *UploadList) Close() error
Close frees resources associated with the query.
func (*UploadList) Debug ¶
func (ul *UploadList) Debug() string
Debug returns the human-readable state of ul.
func (*UploadList) Err ¶
func (ul *UploadList) Err() error
Err returns the error state of the query.
func (*UploadList) Info ¶
func (ul *UploadList) Info() storage.UploadInfo
Info returns the most recent UploadInfo generated by a call to Next.
func (*UploadList) Next ¶
func (ul *UploadList) Next() bool
Next prepares the next result for reading with the Result method. It returns false when there are no more results, either by reaching the end of the input or an error.