package db
import "golang.org/x/perf/storage/db"
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 OpenSQL(driverName, dataSourceName string) (*DB, error)
- 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
- func (q *Query) Close() error
- func (q *Query) Debug() string
- func (q *Query) Err() error
- func (q *Query) Next() bool
- func (q *Query) Result() *benchfmt.Result
- type Upload
- func (u *Upload) Abort() error
- func (u *Upload) Commit() error
- func (u *Upload) InsertRecord(r *benchfmt.Result) error
- type UploadList
Functions ¶
func RegisterOpenHook ¶
RegisterOpenHook registers a hook to be called after opening a connection to driverName. This is used by the sqlite3 package to register a ConnectHook. It must be called from an init function.
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) Close ¶
Close closes the database connections, releasing any open resources.
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)
func (*DB) ReplaceUpload ¶
ReplaceUpload removes the records associated with id if any and allows insertion of new records.
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 ...
func (*Query) Close ¶
Close frees resources associated with the query.
func (*Query) Debug ¶
Debug returns the human-readable state of the query.
func (*Query) Err ¶
Err returns the error state of the query.
func (*Query) Next ¶
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.
func (*Query) Result ¶
Result returns the most recent result generated by a call to Next.
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.
func (*Upload) Abort ¶
Abort cleans up resources associated with the upload. It does not attempt to clean up partial database state.
func (*Upload) Commit ¶
Commit finishes processing the upload.
func (*Upload) InsertRecord ¶
InsertRecord inserts a single record in an existing upload. If InsertRecord returns a non-nil error, the Upload has failed and u.Abort() must be called.
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.
Source Files ¶
db.go query.go
Directories ¶
Path | Synopsis |
---|---|
storage/db/dbtest | |
storage/db/sqlite3 | Package sqlite3 provides the sqlite3 driver for x/perf/storage/db. |
- Version
- v0.0.0-20250214215153-c95ad7d5b636 (latest)
- Published
- Feb 14, 2025
- Platform
- linux/amd64
- Imports
- 15 packages
- Last checked
- 1 week ago –
Tools for package owners.