database

package
v0.0.0-...-fd1ce1a Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package database manages Tempest's database.

Tempest uses SQLite, but we encapsulate our queries here to avoid having SQL strewn throughout the codebase. This package provides some wrapper objects for the database & transactions, which have methods for the queries we want to support.

Index

Constants

View Source
const (
	DBPath = config.Localstatedir + "/sandstorm/sandstorm.sqlite3"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

Wrapper object around a SQL database.

func InitDB

func InitDB(sqlDB *sql.DB) (DB, error)

Initializes the database schema if needed, and returns a DB object.

func Open

func Open() (DB, error)

func (DB) Begin

func (db DB) Begin() (Tx, error)

Begin wraps sql.DB.Begin

func (DB) Close

func (db DB) Close() error

Closes the underlying database

type GrainInfo

type GrainInfo struct {
	ID    types.GrainID
	Title string
	Owner string
}

type Keyring

type Keyring struct {
	// contains filtered or unexported fields
}

Represent's an account's keyring.

func (Keyring) AllUiViews

func (kr Keyring) AllUiViews() ([]UiViewInfo, error)

AllUiViews returns all the UiViews in the keyring.

func (Keyring) AttachGrain

func (kr Keyring) AttachGrain(grainID types.GrainID, permissions []bool) error

type NewAccount

type NewAccount struct {
	ID      types.AccountID
	Role    types.Role
	Profile identity.Profile
}

type NewCredential

type NewCredential struct {
	AccountID  types.AccountID
	Login      bool
	Credential types.Credential
}

type NewGrain

type NewGrain struct {
	GrainID types.GrainID
	PkgID   types.ID[Package]
	OwnerID types.AccountID
	Title   string
}

type Package

type Package struct {
	ID       types.ID[Package] // The package id.
	Manifest spk.Manifest      // The manifest as encoded in the spk.
}

A Package records information about a package in the database.

type SturdyRefKey

type SturdyRefKey struct {
	Token     []byte
	OwnerType string
	Owner     types.AccountID
}

A SturdyRefKey is the data by which a sturdyRef may be fetched from the database (using RestoreSturdyRef).

type SturdyRefValue

type SturdyRefValue struct {
	Expires  time.Time
	GrainID  types.GrainID
	ObjectID capnp.Struct
}

A SturdyRefValue is a persistent value stored in the database, which may be fetched via RestoreSturdyRef.

type Tx

type Tx struct {
	// contains filtered or unexported fields
}

Transaction

func (Tx) AccountGrainPermissions

func (tx Tx) AccountGrainPermissions(accountID types.AccountID, grainID types.GrainID) (permissions []bool, err error)

func (Tx) AccountKeyring

func (tx Tx) AccountKeyring(id types.AccountID) Keyring

func (Tx) AccountProfile

func (tx Tx) AccountProfile(accountID types.AccountID) (identity.Profile, error)

func (Tx) AddAccount

func (tx Tx) AddAccount(a NewAccount) error

func (Tx) AddCredential

func (tx Tx) AddCredential(c NewCredential) error

func (Tx) AddGrain

func (tx Tx) AddGrain(g NewGrain) error

func (Tx) AddPackage

func (tx Tx) AddPackage(pkg Package) error

AddPackage adds a package to the database, initally marked as not ready. The caller must then move the extracted package to the right location, and then call ReadyPackage to complete installation.

func (Tx) Commit

func (tx Tx) Commit() error

Rollback wraps sql.Tx.Commit

func (Tx) CredentialAccount

func (tx Tx) CredentialAccount(cred types.Credential) (types.AccountID, error)

CredentialAccount returns the account ID associated with the credential. If there is no existing account, one is created with the visitor role.

func (Tx) CredentialPackages

func (tx Tx) CredentialPackages(cred types.Credential) ([]Package, error)

CredentialPackages returns a list of all packages installed for the user associated with the credential.

func (Tx) CredentialRole

func (tx Tx) CredentialRole(cred types.Credential) (role types.Role, err error)

CredentialRole gets the role corresponding to the credential. Returns RoleVisitor for unknown credentials.

func (Tx) DeleteSturdyRef

func (tx Tx) DeleteSturdyRef(k SturdyRefKey) error

Delete a sturdyref from the database.

func (Tx) GrainInfo

func (tx Tx) GrainInfo(grainID types.GrainID) (GrainInfo, error)

func (Tx) GrainPackageID

func (tx Tx) GrainPackageID(grainID types.GrainID) (string, error)

GrainPackageID returns the package id for the specified grain

func (Tx) NewSharingToken

func (tx Tx) NewSharingToken(
	grainID types.GrainID,
	perms []bool,
	note string,
) (string, error)

func (Tx) ReadyPackage

func (tx Tx) ReadyPackage(id types.ID[Package]) error

func (Tx) RestoreSturdyRef

func (tx Tx) RestoreSturdyRef(k SturdyRefKey) (SturdyRefValue, error)

Restore a SturdyRef from the database.

func (Tx) Rollback

func (tx Tx) Rollback() error

Rollback wraps sql.Tx.Rollback

func (Tx) SaveSturdyRef

func (tx Tx) SaveSturdyRef(k SturdyRefKey, v SturdyRefValue) ([sha256.Size]byte, error)

Save a SturdyRef in the database. k's token must not be nil. Returns the sha256 hash of the token, which serves as a key in the database.

func (Tx) SetGrainViewInfo

func (tx Tx) SetGrainViewInfo(grainID string, viewInfo grain.UiView_ViewInfo) error

type UiViewInfo

type UiViewInfo struct {
	Grain       GrainInfo
	Permissions []bool
}

Directories

Path Synopsis
package legacy provides support for importing data from legacy sandstorm installations.
package legacy provides support for importing data from legacy sandstorm installations.

Jump to

Keyboard shortcuts

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