db

package
v0.0.0-...-8dc4a41 Latest Latest
Warning

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

Go to latest
Published: May 25, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CURRENT_SCHEMA = `` /* 4706-byte string literal not displayed */

DO NOT EDIT BY HAND

This code was generated by the UpdateSchemaDotGo function. If you need to modify the database schema, please add a new schema update to update.go and the run 'make update-schema'.

Variables

View Source
var (
	// DbErrAlreadyDefined hapens when the given entry already exists,
	// for example a container.
	DbErrAlreadyDefined = fmt.Errorf("The container/snapshot already exists")

	/* NoSuchObjectError is in the case of joins (and probably other) queries,
	 * we don't get back sql.ErrNoRows when no rows are returned, even though we do
	 * on selects without joins. Instead, you can use this error to
	 * propagate up and generate proper 404s to the client when something
	 * isn't found so we don't abuse sql.ErrNoRows any more than we
	 * already do.
	 */
	NoSuchObjectError = fmt.Errorf("No such object")
)
View Source
var ImageSourceProtocol = map[int]string{
	0: "lxd",
	1: "direct",
	2: "simplestreams",
}

Functions

func Begin

func Begin(db *sql.DB) (*sql.Tx, error)

func CertDelete

func CertDelete(db *sql.DB, fingerprint string) error

CertDelete deletes a certificate from the db.

func CertSave

func CertSave(db *sql.DB, cert *CertInfo) error

CertSave stores a CertBaseInfo object in the db, it will ignore the ID field from the CertInfo.

func ConfigValueSet

func ConfigValueSet(db *sql.DB, key string, value string) error

func ConfigValuesGet

func ConfigValuesGet(db *sql.DB) (map[string]string, error)

func ContainerConfig

func ContainerConfig(db *sql.DB, containerId int) (map[string]string, error)

ContainerConfig gets the container configuration map from the DB

func ContainerConfigClear

func ContainerConfigClear(tx *sql.Tx, id int) error

func ContainerConfigGet

func ContainerConfigGet(db *sql.DB, id int, key string) (string, error)

func ContainerConfigInsert

func ContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error

func ContainerConfigRemove

func ContainerConfigRemove(db *sql.DB, id int, name string) error

func ContainerCreate

func ContainerCreate(db *sql.DB, args ContainerArgs) (int, error)

func ContainerGetSnapshots

func ContainerGetSnapshots(db *sql.DB, name string) ([]string, error)

func ContainerId

func ContainerId(db *sql.DB, name string) (int, error)

func ContainerName

func ContainerName(db *sql.DB, id int) (string, error)

func ContainerProfiles

func ContainerProfiles(db *sql.DB, containerId int) ([]string, error)

Get a list of profiles for a given container id.

func ContainerProfilesInsert

func ContainerProfilesInsert(tx *sql.Tx, id int, profiles []string) error

func ContainerRemove

func ContainerRemove(db *sql.DB, name string) error

func ContainerRename

func ContainerRename(db *sql.DB, oldName string, newName string) error

func ContainerSetState

func ContainerSetState(db *sql.DB, id int, state string) error

func ContainerSetStateful

func ContainerSetStateful(db *sql.DB, id int, stateful bool) error

func ContainerUpdate

func ContainerUpdate(tx *sql.Tx, id int, architecture int, ephemeral bool) error

func ContainersList

func ContainersList(db *sql.DB, cType ContainerType) ([]string, error)

func CreateDb

func CreateDb(db *sql.DB, patchNames []string) (err error)

Create the initial (current) schema for a given SQLite DB connection.

func Devices

func Devices(db *sql.DB, qName string, isprofile bool) (types.Devices, error)

func DevicesAdd

func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error

func Exec

func Exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error)

func GetLatestSchema

func GetLatestSchema() int

func GetSchema

func GetSchema(db *sql.DB) (v int)

func ImageAliasAdd

func ImageAliasAdd(db *sql.DB, name string, imageID int, desc string) error

Insert an alias ento the database.

func ImageAliasDelete

func ImageAliasDelete(db *sql.DB, name string) error

func ImageAliasGet

func ImageAliasGet(db *sql.DB, name string, isTrustedClient bool) (int, api.ImageAliasesEntry, error)

func ImageAliasRename

func ImageAliasRename(db *sql.DB, id int, name string) error

func ImageAliasUpdate

func ImageAliasUpdate(db *sql.DB, id int, imageID int, desc string) error

func ImageAliasesMove

func ImageAliasesMove(db *sql.DB, source int, destination int) error

func ImageDelete

func ImageDelete(db *sql.DB, id int) error

func ImageExists

func ImageExists(db *sql.DB, fingerprint string) (bool, error)

Whether an image with the given fingerprint exists.

func ImageGet

func ImageGet(db *sql.DB, fingerprint string, public bool, strictMatching bool) (int, *api.Image, error)

ImageGet gets an Image object from the database. If strictMatching is false, The fingerprint argument will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.

func ImageInsert

func ImageInsert(db *sql.DB, fp string, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string) error

func ImageLastAccessInit

func ImageLastAccessInit(db *sql.DB, fingerprint string) error

func ImageLastAccessUpdate

func ImageLastAccessUpdate(db *sql.DB, fingerprint string, date time.Time) error

func ImageSourceGet

func ImageSourceGet(db *sql.DB, imageId int) (int, api.ImageSource, error)

func ImageSourceInsert

func ImageSourceInsert(db *sql.DB, imageId int, server string, protocol string, certificate string, alias string) error

func ImageUpdate

func ImageUpdate(db *sql.DB, id int, fname string, sz int64, public bool, autoUpdate bool, architecture string, createdAt time.Time, expiresAt time.Time, properties map[string]string) error

func ImagesGet

func ImagesGet(db *sql.DB, public bool) ([]string, error)

func ImagesGetExpired

func ImagesGetExpired(db *sql.DB, expiry int64) ([]string, error)

func IsDbLockedError

func IsDbLockedError(err error) bool

func OpenDb

func OpenDb(path string) (*sql.DB, error)

OpenDb opens the database with the correct parameters for LXD.

func Patches

func Patches(db *sql.DB) ([]string, error)

func PatchesMarkApplied

func PatchesMarkApplied(db *sql.DB, patch string) error

func ProfileConfig

func ProfileConfig(db *sql.DB, name string) (map[string]string, error)

Get the profile configuration map from the DB

func ProfileConfigAdd

func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error

func ProfileConfigClear

func ProfileConfigClear(tx *sql.Tx, id int64) error

func ProfileContainersGet

func ProfileContainersGet(db *sql.DB, profile string) ([]string, error)

func ProfileCreate

func ProfileCreate(db *sql.DB, profile string, description string, config map[string]string,
	devices types.Devices) (int64, error)

func ProfileCreateDefault

func ProfileCreateDefault(db *sql.DB) error

func ProfileDelete

func ProfileDelete(db *sql.DB, name string) error

func ProfileDescriptionUpdate

func ProfileDescriptionUpdate(tx *sql.Tx, id int64, description string) error

func ProfileGet

func ProfileGet(db *sql.DB, name string) (int64, *api.Profile, error)

func ProfileUpdate

func ProfileUpdate(db *sql.DB, name string, newName string) error

func Profiles

func Profiles(db *sql.DB) ([]string, error)

Profiles returns a string list of profiles.

func QueryScan

func QueryScan(qi queryer, q string, inargs []interface{}, outfmt []interface{}) ([][]interface{}, error)

* . qi anything implementing the querier interface (i.e. either sql.DB or sql.Tx) * . q is the database query * . inargs is an array of interfaces containing the query arguments * . outfmt is an array of interfaces containing the right types of output * arguments, i.e. * var arg1 string * var arg2 int * outfmt := {}interface{}{arg1, arg2} * * The result will be an array (one per output row) of arrays (one per output argument) * of interfaces, containing pointers to the actual output arguments.

func TxCommit

func TxCommit(tx *sql.Tx) error

func UpdateSchemaDotGo

func UpdateSchemaDotGo() error

UpdateSchemaDotGo rewrites the 'schema.go' source file in this package to match the current schema updates.

The schema.go file contains a "flattened" render of all schema updates defined in this file, and it's used to initialize brand new databases.

func UpdatesApplyAll

func UpdatesApplyAll(db *sql.DB, doBackup bool, legacyPatches map[int]*LegacyPatch) error

UpdatesApplyAll applies all possible database patches. If "doBackup" is true, the sqlite file will be backed up before any update is applied. The legacyPatches parameter is used by the Daemon as a mean to apply the legacy V10, V11, V15, V29 and V30 non-db updates during the database upgrade sequence, to avoid any change in semantics wrt the old logic (see PR #3322).

Types

type CertInfo

type CertInfo struct {
	ID          int
	Fingerprint string
	Type        int
	Name        string
	Certificate string
}

CertInfo is here to pass the certificates content from the database around

func CertGet

func CertGet(db *sql.DB, fingerprint string) (cert *CertInfo, err error)

CertGet gets an CertBaseInfo object from the database. The argument fingerprint will be queried with a LIKE query, means you can pass a shortform and will get the full fingerprint. There can never be more than one image with a given fingerprint, as it is enforced by a UNIQUE constraint in the schema.

func CertsGet

func CertsGet(db *sql.DB) (certs []*CertInfo, err error)

CertsGet returns all certificates from the DB as CertBaseInfo objects.

type ContainerArgs

type ContainerArgs struct {
	// Don't set manually
	Id int

	Architecture int
	BaseImage    string
	Config       map[string]string
	CreationDate time.Time
	Ctype        ContainerType
	Devices      types.Devices
	Ephemeral    bool
	Name         string
	Profiles     []string
	Stateful     bool
}

ContainerArgs is a value object holding all db-related details about a container.

func ContainerGet

func ContainerGet(db *sql.DB, name string) (ContainerArgs, error)

type ContainerType

type ContainerType int

ContainerType encodes the type of container (either regular or snapshot).

const (
	CTypeRegular  ContainerType = 0
	CTypeSnapshot ContainerType = 1
)

type LegacyPatch

type LegacyPatch struct {
	NeedsDB bool         // Whether the patch does any DB-related work
	Hook    func() error // The actual patch logic
}

LegacyPatch is a "database" update that performs non-database work. They are needed for historical reasons, since there was a time were db updates could do non-db work and depend on functionality external to the db package. See UpdatesApplyAll below.

Directories

Path Synopsis
Package query implements helpers around database/sql to execute various kinds of very common SQL queries.
Package query implements helpers around database/sql to execute various kinds of very common SQL queries.
Package schema offers utilities to create and maintain a database schema.
Package schema offers utilities to create and maintain a database schema.

Jump to

Keyboard shortcuts

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