db

package
v0.0.0-...-f3e401e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 15 Imported by: 9

Documentation

Overview

Package db provides the high-level database interface for the storage app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterOpenHook

func RegisterOpenHook(driverName string, hook func(*sql.DB) error)

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

func OpenSQL(driverName, dataSourceName string) (*DB, error)

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

func (db *DB) Close() error

Close closes the database connections, releasing any open resources.

func (*DB) CountUploads

func (db *DB) CountUploads() (int, error)

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

func (db *DB) NewUpload(ctx context.Context) (*Upload, error)

NewUpload returns an upload for storing new files. All records written to the Upload will have the same upload ID.

func (*DB) Query

func (db *DB) Query(q string) *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

func (db *DB) ReplaceUpload(id string) (*Upload, error)

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

func (q *Query) Close() error

Close frees resources associated with the query.

func (*Query) Debug

func (q *Query) Debug() string

Debug returns the human-readable state of the query.

func (*Query) Err

func (q *Query) Err() error

Err returns the error state of the query.

func (*Query) Next

func (q *Query) 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.

func (*Query) Result

func (q *Query) Result() *benchfmt.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

func (u *Upload) Abort() error

Abort cleans up resources associated with the upload. It does not attempt to clean up partial database state.

func (*Upload) Commit

func (u *Upload) Commit() error

Commit finishes processing the upload.

func (*Upload) InsertRecord

func (u *Upload) InsertRecord(r *benchfmt.Result) error

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.

Directories

Path Synopsis
Package sqlite3 provides the sqlite3 driver for x/perf/storage/db.
Package sqlite3 provides the sqlite3 driver for x/perf/storage/db.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL