database

package
v0.0.0-...-f3ca651 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPort = 5432

DefaultPort is the default Postgres listen port

Variables

This section is empty.

Functions

func Connect

func Connect(s Settings) (*gorm.DB, error)

Connect to a Postgres database using the given settings and returns a *gorm.DB handle.

func NewID

func NewID() string

NewID returns a new unique identifier

Types

type AccessKey

type AccessKey struct {
	ID         string    `json:"id" gorm:"size:64;primary_key;unique_index"`
	RefID      string    `json:"ref_id" gorm:"size:64;index"`
	Name       string    `json:"name" gorm:"size:64"`
	Permission string    `json:"permission" gorm:"size:64"`
	CreatedAt  time.Time `json:"created_at"`
	Secret     string    `json:"value" gorm:"size:100"`
}

AccessKey is a database entry allowing access to FlameDB

func NewAccessKey

func NewAccessKey(name, refID string, perm AccessKeyPermission) (*AccessKey, string, error)

NewAccessKey initializes a new AccessKey with a random secret value. The AccessKey model is returned along with the plaintext value which should be stored externally.

func (*AccessKey) Compare

func (key *AccessKey) Compare(plaintext string) error

Compare the given plaintext against this key to see if it's a match. Returns nil if it matches.

type AccessKeyPermission

type AccessKeyPermission string

AccessKeyPermission defines the access level associated with an access key

const (
	// Denied access
	Denied AccessKeyPermission = ""

	// ReadOnly grant
	ReadOnly AccessKeyPermission = "r"

	// ReadWrite grant
	ReadWrite AccessKeyPermission = "rw"

	// ServiceRead provides read access from an external service
	ServiceRead AccessKeyPermission = "sr"

	// ServiceReadWrite provides rw access from an external service
	ServiceReadWrite AccessKeyPermission = "srw"
)

type AccessKeyStore

type AccessKeyStore interface {

	// Get returns the access key with the given key ID
	Get(id string) (*AccessKey, error)
}

AccessKeyStore is an interface to retrieve access permissions

func NewAccessKeyStore

func NewAccessKeyStore(gormDB *gorm.DB) (AccessKeyStore, error)

NewAccessKeyStore returns an initialized access key store

type Flame

type Flame interface {

	// Get a Record using the key
	Get(Key) (*Record, error)

	// Save the Record
	Save(*Record) error

	// Delete the Record
	Delete(*Record) error

	// List Records matching the query
	List(Query) ([]*Record, error)

	// GetIndexes returns a list of existing indexes
	GetIndexes() ([]Index, error)

	// CreateIndex creates a new index on the specified field or property
	CreateIndex(Index) error

	// DeleteIndex deletes the index
	DeleteIndex(Index) error

	// HasIndex returns true if the Index already exists
	HasIndex(Index) (bool, error)

	// DropTable removes the table from the database, deleting all records
	DropTable() error

	// Migrate the database schema
	Migrate() error
}

Flame is the database interface

func NewFlame

func NewFlame(gormDB *gorm.DB) Flame

NewFlame returns an interface to a FlameDB

type Index

type Index struct {
	Name     string
	Parent   string
	Property string
}

Index on a specified Record property used to ensure efficient queries. Optionally a Parent path may be specified to create the Index only on a subset of Records with that Parent path.

type Key

type Key struct {
	ID   string
	Path string
}

Key used to identify and look up a record

type PostgresIndex

type PostgresIndex struct {
	TableName string `gorm:"tablename"`
	IndexName string `gorm:"indexname"`
	IndexDef  string `gorm:"indexdef"`
}

PostgresIndex is a record in PG describing a table index

type PostgresIndexes

type PostgresIndexes []*PostgresIndex

PostgresIndexes is a slice of indexes

func (PostgresIndexes) Get

func (indexes PostgresIndexes) Get(name string) *PostgresIndex

Get the index with the specified name

type Query

type Query struct {
	Offset              int
	Limit               int
	Parent              string
	Prefix              string
	OrderBy             string
	OrderByDesc         bool
	OrderByProperty     string
	OrderByPropertyDesc bool
	PropertyFilter      map[string]string
}

Query used to list records

type Record

type Record struct {
	ID         string         `json:"id" gorm:"size:64;primary_key;unique_index"`
	Path       string         `json:"path" gorm:"size:320;unique_index"`
	Parent     string         `json:"parent" gorm:"size:256;index"`
	CreatedBy  string         `json:"created_by" gorm:"size:64"`
	UpdatedBy  string         `json:"updated_by" gorm:"size:64"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`
	Properties postgres.Jsonb `json:"properties"`
}

Record is an item with a unique ID stored in FlameDB at a specified Path. The Record has a handful of top-level meta attributes and a Properties field which may contain arbitrary JSON.

func (*Record) BeforeSave

func (r *Record) BeforeSave() error

BeforeSave is called to validate the Record before saving it to the database

func (*Record) GetProperties

func (r *Record) GetProperties() (map[string]interface{}, error)

GetProperties returns the record properties as a map

func (*Record) MustGetProperties

func (r *Record) MustGetProperties() map[string]interface{}

MustGetProperties returns the record properties as a map. If they fail to unmarshal this panics.

func (*Record) MustSetProperties

func (r *Record) MustSetProperties(properties map[string]interface{})

MustSetProperties sets properties and panics if marshaling fails

func (*Record) SetProperties

func (r *Record) SetProperties(properties map[string]interface{}) error

SetProperties sets the properites in JSONB format

type SSLMode

type SSLMode string

SSLMode defines SSL settings used to connect to Postgres

const (
	// SSLModeDisabled disables SSL
	SSLModeDisabled SSLMode = "disable"

	// SSLModeRequired makes SSL required
	SSLModeRequired SSLMode = "require"

	// SSLModeVerifyCA enables SSL with server and client certificates
	SSLModeVerifyCA SSLMode = "verify-ca"
)

type Settings

type Settings struct {
	Host        string
	Port        int
	User        string
	Password    string
	Name        string
	SSLMode     SSLMode
	SSLRootCert string
	SSLCert     string
	SSLKey      string
}

Settings used to connect to the backing Postgres database

func GetSettings

func GetSettings() Settings

GetSettings returns application configuration derived from command line options and environment variables.

Directories

Path Synopsis
Package mock_database is a generated GoMock package.
Package mock_database is a generated GoMock package.

Jump to

Keyboard shortcuts

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