model

package
v0.0.0-...-ec8378c Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pragma = "PRAGMA foreign_keys = ON"
)
View Source
const (
	Tag = "sql"
)

Variables

View Source
var DeleteSQL = `` /* 198-byte string literal not displayed */
View Source
var FkRegex = regexp.MustCompile(`(fk):(.+)(\()(.+)(\))`)

Regex used for `fk:<table>(field)` tags.

View Source
var GetSQL = `` /* 296-byte string literal not displayed */
View Source
var IndexDDL = `` /* 141-byte string literal not displayed */
View Source
var IndexRegex = regexp.MustCompile(`(index)(\()(.+)(\))`)

Regex used for `index(group)` tags.

View Source
var InsertSQL = `` /* 196-byte string literal not displayed */

SQL templates.

View Source
var ListSQL = `` /* 834-byte string literal not displayed */

Shared logger.

DB driver cannot be used for concurrent writes. Model methods must use:

  • Insert()
  • Update()
  • Delete()

And, all transactions.

View Source
var NotFound = sql.ErrNoRows

Not found error.

View Source
var Settings = &settings.Settings

Application settings.

View Source
var TableDDL = `` /* 177-byte string literal not displayed */

DDL templates.

View Source
var UniqueRegex = regexp.MustCompile(`(unique)(\()(.+)(\))`)

Regex used for `unique(group)` tags.

View Source
var UpdateSQL = `` /* 292-byte string literal not displayed */

Functions

func Create

func Create() (*sql.DB, error)

Create the schema in the DB.

Types

type Backup

type Backup struct {
	Base
}

Backup model

func (Backup) Count

func (m Backup) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Backup) DecodeObject

func (m *Backup) DecodeObject() *velero.Backup

Decode the object.

func (*Backup) Delete

func (m *Backup) Delete(db DB) error

Delete the model in the DB.

func (*Backup) EncodeObject

func (m *Backup) EncodeObject(backup *velero.Backup)

Encode the object.

func (*Backup) Get

func (m *Backup) Get(db DB) error

Fetch the model from the DB.

func (*Backup) Insert

func (m *Backup) Insert(db DB) error

Insert the model into the DB.

func (Backup) List

func (m Backup) List(db DB, options ListOptions) ([]*Backup, error)

Fetch the model from the DB.

func (*Backup) Update

func (m *Backup) Update(db DB) error

Update the model in the DB.

func (*Backup) With

func (m *Backup) With(object *velero.Backup)

Update the model `with` a Backup.

type Base

type Base struct {
	// Primary key (digest).
	PK string `sql:"pk"`
	// The k8s resource UID.
	UID string `sql:"const,unique(a)"`
	// The k8s resourceVersion.
	Version string `sql:""`
	// The k8s resource namespace.
	Namespace string `sql:"const,unique(b),key"`
	// The k8s resource name.
	Name string `sql:"const,unique(b),key"`
	// The raw json-encoded k8s resource.
	Object string `sql:""`
	// The (optional) cluster foreign key.
	Cluster string `sql:"const,fk:Cluster(pk),unique(a),unique(b),key"`
	// contains filtered or unexported fields
}

Base Model

func (*Base) GetCluster

func (m *Base) GetCluster(db DB) (*Cluster, error)

Fetch referenced cluster.

func (*Base) Labels

func (m *Base) Labels() Labels

Get labels.

func (*Base) Meta

func (m *Base) Meta() *Meta

Get the meta-data.

func (*Base) Pk

func (m *Base) Pk() string

Get the primary key.

func (*Base) SetPk

func (m *Base) SetPk()

Set the primary key. The PK is calculated as the SHA1 of the:

  • cluster FK
  • k8s UID.

type CR

type CR struct {
	// Primary key (digest).
	PK string `sql:"pk"`
	// The k8s resource UID.
	UID string `sql:"const,unique(a)"`
	// The k8s resourceVersion.
	Version string `sql:""`
	// The k8s resource namespace.
	Namespace string `sql:"const,unique(b),key"`
	// The k8s resource name.
	Name string `sql:"const,unique(b),key"`
	// The raw json-encoded k8s resource.
	Object string `sql:""`
	// contains filtered or unexported fields
}

Custom Resource.

func (*CR) Labels

func (m *CR) Labels() Labels

Get associated labels.

func (*CR) Meta

func (m *CR) Meta() *Meta

Get the model meta-data.

func (*CR) Pk

func (m *CR) Pk() string

Get the primary key.

func (*CR) SetPk

func (m *CR) SetPk()

Set the primary key.

type Cluster

type Cluster struct {
	CR
}

Cluster model.

func (Cluster) Count

func (m Cluster) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Cluster) DecodeObject

func (m *Cluster) DecodeObject() *migapi.MigCluster

Decode the object.

func (*Cluster) Delete

func (m *Cluster) Delete(db DB) error

Delete the model in the DB.

func (*Cluster) EncodeObject

func (m *Cluster) EncodeObject(cluster *migapi.MigCluster)

Encode the object.

func (*Cluster) Get

func (m *Cluster) Get(db DB) error

Fetch the model from the DB.

func (*Cluster) Insert

func (m *Cluster) Insert(db DB) error

Insert the model into the DB.

func (Cluster) List

func (m Cluster) List(db DB, options ListOptions) ([]*Cluster, error)

Fetch the model from the DB.

func (*Cluster) Update

func (m *Cluster) Update(db DB) error

Update the model in the DB.

func (*Cluster) With

func (m *Cluster) With(object *migapi.MigCluster)

Update the model `with` a MigCluster.

type DB

type DB interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
}

Database interface. Support model methods taking either sql.DB or sql.Tx.

type DirectImageMigration

type DirectImageMigration struct {
	CR
}

DirectImageMigration model.

func (DirectImageMigration) Count

func (m DirectImageMigration) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*DirectImageMigration) DecodeObject

Decode the object.

func (*DirectImageMigration) Delete

func (m *DirectImageMigration) Delete(db DB) error

Delete the model in the DB.

func (*DirectImageMigration) EncodeObject

func (m *DirectImageMigration) EncodeObject(dim *migapi.DirectImageMigration)

Encode the object.

func (*DirectImageMigration) Get

func (m *DirectImageMigration) Get(db DB) error

Fetch the model from the DB.

func (*DirectImageMigration) Insert

func (m *DirectImageMigration) Insert(db DB) error

Insert the model into the DB.

func (DirectImageMigration) List

func (m DirectImageMigration) List(db DB, options ListOptions) ([]*DirectImageMigration, error)

Fetch the model from the DB.

func (*DirectImageMigration) Update

func (m *DirectImageMigration) Update(db DB) error

Update the model in the DB.

func (*DirectImageMigration) With

Update the model `with` a DirectImageMigration.

type DirectImageStreamMigration

type DirectImageStreamMigration struct {
	CR
}

DirectImageStreamMigration model.

func (DirectImageStreamMigration) Count

func (m DirectImageStreamMigration) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*DirectImageStreamMigration) DecodeObject

Decode the object.

func (*DirectImageStreamMigration) Delete

func (m *DirectImageStreamMigration) Delete(db DB) error

Delete the model in the DB.

func (*DirectImageStreamMigration) EncodeObject

Encode the object.

func (*DirectImageStreamMigration) Get

func (m *DirectImageStreamMigration) Get(db DB) error

Fetch the model from the DB.

func (*DirectImageStreamMigration) Insert

func (m *DirectImageStreamMigration) Insert(db DB) error

Insert the model into the DB.

func (DirectImageStreamMigration) List

Fetch the model from the DB.

func (*DirectImageStreamMigration) Update

func (m *DirectImageStreamMigration) Update(db DB) error

Update the model in the DB.

func (*DirectImageStreamMigration) With

Update the model `with` a DirectImageMigration.

type DirectVolumeMigration

type DirectVolumeMigration struct {
	CR
}

DirectVolumeMigration model.

func (DirectVolumeMigration) Count

func (m DirectVolumeMigration) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*DirectVolumeMigration) DecodeObject

Decode the object.

func (*DirectVolumeMigration) Delete

func (m *DirectVolumeMigration) Delete(db DB) error

Delete the model in the DB.

func (*DirectVolumeMigration) EncodeObject

func (m *DirectVolumeMigration) EncodeObject(dvm *migapi.DirectVolumeMigration)

Encode the object.

func (*DirectVolumeMigration) Get

func (m *DirectVolumeMigration) Get(db DB) error

Fetch the model from the DB.

func (*DirectVolumeMigration) Insert

func (m *DirectVolumeMigration) Insert(db DB) error

Insert the model into the DB.

func (DirectVolumeMigration) List

Fetch the model from the DB.

func (*DirectVolumeMigration) Update

func (m *DirectVolumeMigration) Update(db DB) error

Update the model in the DB.

func (*DirectVolumeMigration) With

Update the model `with` a DirectVolumeMigration.

type DirectVolumeMigrationProgress

type DirectVolumeMigrationProgress struct {
	CR
}

DirectVolumeMigrationProgress model.

func (DirectVolumeMigrationProgress) Count

func (m DirectVolumeMigrationProgress) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*DirectVolumeMigrationProgress) DecodeObject

Decode the object.

func (*DirectVolumeMigrationProgress) Delete

func (m *DirectVolumeMigrationProgress) Delete(db DB) error

Delete the model in the DB.

func (*DirectVolumeMigrationProgress) EncodeObject

Encode the object.

func (*DirectVolumeMigrationProgress) Get

Fetch the model from the DB.

func (*DirectVolumeMigrationProgress) Insert

func (m *DirectVolumeMigrationProgress) Insert(db DB) error

Insert the model into the DB.

func (DirectVolumeMigrationProgress) List

Fetch the model from the DB.

func (*DirectVolumeMigrationProgress) Update

func (m *DirectVolumeMigrationProgress) Update(db DB) error

Update the model in the DB.

func (*DirectVolumeMigrationProgress) With

Update the model `with` a DirectImageMigration.

type Event

type Event struct {
	Base
}

Event model.

func (Event) Count

func (m Event) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Event) DecodeObject

func (m *Event) DecodeObject() *corev1.Event

Encode the object.

func (*Event) Delete

func (m *Event) Delete(db DB) error

Delete the model in the DB.

func (*Event) EncodeObject

func (m *Event) EncodeObject(event *corev1.Event)

Encode the object.

func (*Event) Get

func (m *Event) Get(db DB) error

Fetch the model from the DB.

func (*Event) Insert

func (m *Event) Insert(db DB) error

Insert the model into the DB.

func (Event) List

func (m Event) List(db DB, options ListOptions) ([]*Event, error)

Fetch the from in the DB.

func (*Event) Update

func (m *Event) Update(db DB) error

Update the model in the DB.

func (*Event) With

func (m *Event) With(object *corev1.Event)

Update the model `with` a k8s Event.

type FK

type FK struct {
	// Table name.
	Table string
	// Field name.
	Field string
}

FK constraint.

func (*FK) DDL

func (f *FK) DDL(field *Field) string

Get DDL.

type Field

type Field struct {
	// reflect.Value of the field.
	Value *reflect.Value
	// Tags.
	Tag string
	// Field name.
	Name string
	// contains filtered or unexported fields
}

Model (struct) Field

func (*Field) DDL

func (f *Field) DDL() string

Column DDL.

func (*Field) Empty

func (f *Field) Empty() bool

Get whether field is empty.

func (*Field) Fk

func (f *Field) Fk() *FK

Get whether the field is a foreign key.

func (*Field) Index

func (f *Field) Index() []string

Get whether the field is part of a non-unique index.

func (*Field) Key

func (f *Field) Key() bool

Get whether field is a natural key.

func (*Field) Mutable

func (f *Field) Mutable() bool

Get whether field is mutable. Only mutable fields will be updated.

func (*Field) Param

func (f *Field) Param() string

Get as SQL param.

func (*Field) Pk

func (f *Field) Pk() bool

Get whether field is the primary key.

func (*Field) Ptr

func (f *Field) Ptr() interface{}

Pointer used for Scan().

func (*Field) Pull

func (f *Field) Pull() interface{}

Pull from model. Populate the appropriate `staging` field using the model field value.

func (*Field) Push

func (f *Field) Push()

Push to the model. Set the model field value using the `staging` field.

func (*Field) Unique

func (f *Field) Unique() []string

Get whether the field is unique.

func (*Field) Validate

func (f *Field) Validate() error

Validate.

type Hook

type Hook struct {
	CR
}

Hook model.

func (Hook) Count

func (m Hook) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Hook) DecodeObject

func (m *Hook) DecodeObject() *migapi.MigHook

Decode the object.

func (*Hook) Delete

func (m *Hook) Delete(db DB) error

Delete the model in the DB.

func (*Hook) EncodeObject

func (m *Hook) EncodeObject(dim *migapi.MigHook)

Encode the object.

func (*Hook) Get

func (m *Hook) Get(db DB) error

Fetch the model from the DB.

func (*Hook) Insert

func (m *Hook) Insert(db DB) error

Insert the model into the DB.

func (Hook) List

func (m Hook) List(db DB, options ListOptions) ([]*Hook, error)

Fetch the model from the DB.

func (*Hook) Update

func (m *Hook) Update(db DB) error

Update the model in the DB.

func (*Hook) With

func (m *Hook) With(object *migapi.MigHook)

Update the model `with` a Hook.

type Job

type Job struct {
	Base
}

Job model.

func (Job) Count

func (m Job) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Job) DecodeObject

func (m *Job) DecodeObject() *batchv1.Job

Encode the object.

func (*Job) Delete

func (m *Job) Delete(db DB) error

Delete the model in the DB.

func (*Job) EncodeObject

func (m *Job) EncodeObject(job *batchv1.Job)

Encode the object.

func (*Job) Get

func (m *Job) Get(db DB) error

Fetch the model from the DB.

func (*Job) Insert

func (m *Job) Insert(db DB) error

Insert the model into the DB.

func (Job) List

func (m Job) List(db DB, options ListOptions) ([]*Job, error)

Fetch the from in the DB.

func (*Job) Update

func (m *Job) Update(db DB) error

Update the model in the DB.

func (*Job) With

func (m *Job) With(object *batchv1.Job)

Update the model `with` a k8s Job.

type Label

type Label struct {
	Parent string `sql:"unique(a),key"`
	Kind   string `sql:"unique(a),key"`
	Name   string `sql:"unique(a)"`
	Value  string `sql:""`
}

type Labels

type Labels map[string]string

type ListOptions

type ListOptions struct {
	// Row count.
	Count bool
	// Labels.
	Labels Labels
	// Pagination.
	Page *Page
	// Sort by field position.
	Sort []int
}

List options.

type Meta

type Meta struct {
	// Primary key.
	PK string
	// The k8s resource UID.
	UID string
	// The k8s resourceVersion.
	Version uint64
	// The k8s resource namespace.
	Namespace string
	// The k8s resource name.
	Name string
}

Model meta-data.

type Migration

type Migration struct {
	CR
}

Migration model

func (Migration) Count

func (m Migration) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Migration) DecodeObject

func (m *Migration) DecodeObject() *migapi.MigMigration

Decode the object.

func (*Migration) Delete

func (m *Migration) Delete(db DB) error

Delete the model in the DB.

func (*Migration) EncodeObject

func (m *Migration) EncodeObject(migration *migapi.MigMigration)

Encode the object.

func (*Migration) Get

func (m *Migration) Get(db DB) error

Fetch the model from the DB.

func (*Migration) Insert

func (m *Migration) Insert(db DB) error

Insert the model into the DB.

func (Migration) List

func (m Migration) List(db DB, options ListOptions) ([]*Migration, error)

Fetch the model from the DB.

func (*Migration) Update

func (m *Migration) Update(db DB) error

Update the model in the DB.

func (*Migration) With

func (m *Migration) With(object *migapi.MigMigration)

Update the model `with` a MigMigration.

type Model

type Model interface {
	// Get the primary key.
	Pk() string
	// Set the primary key based on attributes.
	SetPk()
	// Get model meta-data.
	Meta() *Meta
	// Fetch the model from the DB and update the fields.
	// Returns error=`NotFound` when not found.
	Get(DB) error
	// Insert into the DB.
	Insert(DB) error
	// Update in the DB.
	Update(DB) error
	// Delete from the DB.
	Delete(DB) error
	// Get labels.
	Labels() Labels
}

Model Each model represents a table in the DB.

type Namespace

type Namespace struct {
	Base
}

Namespace model.

func (Namespace) Count

func (m Namespace) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Namespace) Delete

func (m *Namespace) Delete(db DB) error

Delete the model in the DB.

func (*Namespace) Get

func (m *Namespace) Get(db DB) error

Fetch the from in the DB.

func (*Namespace) Insert

func (m *Namespace) Insert(db DB) error

Insert the model into the DB.

func (Namespace) List

func (m Namespace) List(db DB, options ListOptions) ([]*Namespace, error)

Fetch the from in the DB.

func (*Namespace) Update

func (m *Namespace) Update(db DB) error

Update the model in the DB.

func (*Namespace) With

func (m *Namespace) With(object *v1.Namespace)

Update the model `with` a k8s Namespace.

type PV

type PV struct {
	Base
}

PV model.

func (PV) Count

func (m PV) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*PV) DecodeObject

func (m *PV) DecodeObject() *v1.PersistentVolume

Encode the object.

func (*PV) Delete

func (m *PV) Delete(db DB) error

Delete the model in the DB.

func (*PV) EncodeObject

func (m *PV) EncodeObject(pv *v1.PersistentVolume)

Encode the object.

func (*PV) Get

func (m *PV) Get(db DB) error

Fetch the model from the DB.

func (*PV) Insert

func (m *PV) Insert(db DB) error

Insert the model into the DB.

func (PV) List

func (m PV) List(db DB, options ListOptions) ([]*PV, error)

Fetch the from in the DB.

func (*PV) Update

func (m *PV) Update(db DB) error

Update the model in the DB.

func (*PV) With

func (m *PV) With(object *v1.PersistentVolume)

Update the model `with` a k8s PersistentVolume.

type PVC

type PVC struct {
	Base
}

PVC model.

func (PVC) Count

func (m PVC) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*PVC) DecodeObject

func (m *PVC) DecodeObject() *v1.PersistentVolumeClaim

Encode the object.

func (*PVC) Delete

func (m *PVC) Delete(db DB) error

Delete the model in the DB.

func (*PVC) EncodeObject

func (m *PVC) EncodeObject(pvc *v1.PersistentVolumeClaim)

Encode the object.

func (*PVC) Get

func (m *PVC) Get(db DB) error

Fetch the model from the DB.

func (*PVC) Insert

func (m *PVC) Insert(db DB) error

Insert the model into the DB.

func (PVC) List

func (m PVC) List(db DB, options ListOptions) ([]*PVC, error)

Fetch the from in the DB.

func (*PVC) Update

func (m *PVC) Update(db DB) error

Update the model in the DB.

func (*PVC) With

func (m *PVC) With(object *v1.PersistentVolumeClaim)

Update the model `with` a k8s PVC.

type Page

type Page struct {
	// The page offset.
	Offset int
	// The number of items per/page.
	Limit int
}

Page. Support pagination.

func (*Page) Slice

func (p *Page) Slice(collection interface{})

Slice the collection according to the page definition. The `collection` must be a pointer to a `Slice` which is modified as needed.

type Plan

type Plan struct {
	CR
}

Plan model

func (Plan) Count

func (m Plan) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Plan) DecodeObject

func (m *Plan) DecodeObject() *migapi.MigPlan

Decode the object.

func (*Plan) Delete

func (m *Plan) Delete(db DB) error

Delete the model in the DB.

func (*Plan) EncodeObject

func (m *Plan) EncodeObject(plan *migapi.MigPlan)

Encode the object.

func (*Plan) Get

func (m *Plan) Get(db DB) error

Fetch the model from the DB.

func (*Plan) Insert

func (m *Plan) Insert(db DB) error

Insert the model into the DB.

func (Plan) List

func (m Plan) List(db DB, options ListOptions) ([]*Plan, error)

Fetch the model from the DB.

func (*Plan) Update

func (m *Plan) Update(db DB) error

Update the model in the DB.

func (*Plan) With

func (m *Plan) With(object *migapi.MigPlan)

Update the model `with` a MigPlan.

type Pod

type Pod struct {
	Base
}

Pod model

func (Pod) Count

func (m Pod) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Pod) DecodeObject

func (m *Pod) DecodeObject() *v1.Pod

Decode the object.

func (*Pod) Delete

func (m *Pod) Delete(db DB) error

Delete the model in the DB.

func (*Pod) EncodeObject

func (m *Pod) EncodeObject(pod *v1.Pod)

Encode the object.

func (*Pod) Get

func (m *Pod) Get(db DB) error

Fetch the model from the DB.

func (*Pod) Insert

func (m *Pod) Insert(db DB) error

Insert the model into the DB.

func (Pod) List

func (m Pod) List(db DB, options ListOptions) ([]*Pod, error)

Fetch the model from in the DB.

func (*Pod) Update

func (m *Pod) Update(db DB) error

Update the model in the DB.

func (*Pod) With

func (m *Pod) With(object *v1.Pod)

Update the model `with` a k8s Pod.

type PodVolumeBackup

type PodVolumeBackup struct {
	Base
}

Backup model

func (PodVolumeBackup) Count

func (m PodVolumeBackup) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*PodVolumeBackup) DecodeObject

func (m *PodVolumeBackup) DecodeObject() *velero.PodVolumeBackup

Decode the object.

func (*PodVolumeBackup) Delete

func (m *PodVolumeBackup) Delete(db DB) error

Delete the model in the DB.

func (*PodVolumeBackup) EncodeObject

func (m *PodVolumeBackup) EncodeObject(backup *velero.PodVolumeBackup)

Encode the object.

func (*PodVolumeBackup) Get

func (m *PodVolumeBackup) Get(db DB) error

Fetch the model from the DB.

func (*PodVolumeBackup) Insert

func (m *PodVolumeBackup) Insert(db DB) error

Insert the model into the DB.

func (PodVolumeBackup) List

func (m PodVolumeBackup) List(db DB, options ListOptions) ([]*PodVolumeBackup, error)

Fetch the model from the DB.

func (*PodVolumeBackup) Update

func (m *PodVolumeBackup) Update(db DB) error

Update the model in the DB.

func (*PodVolumeBackup) With

func (m *PodVolumeBackup) With(object *velero.PodVolumeBackup)

Update the model `with` a Backup.

type PodVolumeRestore

type PodVolumeRestore struct {
	Base
}

Restore model

func (PodVolumeRestore) Count

func (m PodVolumeRestore) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*PodVolumeRestore) DecodeObject

func (m *PodVolumeRestore) DecodeObject() *velero.PodVolumeRestore

Decode the object.

func (*PodVolumeRestore) Delete

func (m *PodVolumeRestore) Delete(db DB) error

Delete the model in the DB.

func (*PodVolumeRestore) EncodeObject

func (m *PodVolumeRestore) EncodeObject(restore *velero.PodVolumeRestore)

Encode the object.

func (*PodVolumeRestore) Get

func (m *PodVolumeRestore) Get(db DB) error

Fetch the model from the DB.

func (*PodVolumeRestore) Insert

func (m *PodVolumeRestore) Insert(db DB) error

Insert the model into the DB.

func (PodVolumeRestore) List

func (m PodVolumeRestore) List(db DB, options ListOptions) ([]*PodVolumeRestore, error)

Fetch the model from the DB.

func (*PodVolumeRestore) Update

func (m *PodVolumeRestore) Update(db DB) error

Update the model in the DB.

func (*PodVolumeRestore) With

func (m *PodVolumeRestore) With(object *velero.PodVolumeRestore)

Update the model `with` a Restore.

type Restore

type Restore struct {
	Base
}

Restore model

func (Restore) Count

func (m Restore) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Restore) DecodeObject

func (m *Restore) DecodeObject() *velero.Restore

Decode the object.

func (*Restore) Delete

func (m *Restore) Delete(db DB) error

Delete the model in the DB.

func (*Restore) EncodeObject

func (m *Restore) EncodeObject(restore *velero.Restore)

Encode the object.

func (*Restore) Get

func (m *Restore) Get(db DB) error

Fetch the model from the DB.

func (*Restore) Insert

func (m *Restore) Insert(db DB) error

Insert the model into the DB.

func (Restore) List

func (m Restore) List(db DB, options ListOptions) ([]*Restore, error)

Fetch the model from the DB.

func (*Restore) Update

func (m *Restore) Update(db DB) error

Update the model in the DB.

func (*Restore) With

func (m *Restore) With(object *velero.Restore)

Update the model `with` a Restore.

type Route

type Route struct {
	Base
}

Route model

func (Route) Count

func (m Route) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Route) DecodeObject

func (m *Route) DecodeObject() *v1.Route

Decode the object.

func (*Route) Delete

func (m *Route) Delete(db DB) error

Delete the model in the DB.

func (*Route) EncodeObject

func (m *Route) EncodeObject(pod *v1.Route)

Encode the object.

func (*Route) Get

func (m *Route) Get(db DB) error

Fetch the model from the DB.

func (*Route) Insert

func (m *Route) Insert(db DB) error

Insert the model into the DB.

func (Route) List

func (m Route) List(db DB, options ListOptions) ([]*Route, error)

Fetch the model from in the DB.

func (*Route) Update

func (m *Route) Update(db DB) error

Update the model in the DB.

func (*Route) With

func (m *Route) With(object *v1.Route)

Update the model `with` a k8s Route.

type Row

type Row interface {
	Scan(...interface{}) error
}

Database interface. Support model `Scan` taking either sql.Row or sql.Rows.

type Service

type Service struct {
	Base
}

Service model.

func (Service) Count

func (m Service) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*Service) DecodeObject

func (m *Service) DecodeObject() *v1.Service

Encode the object.

func (*Service) Delete

func (m *Service) Delete(db DB) error

Delete the model in the DB.

func (*Service) EncodeObject

func (m *Service) EncodeObject(service *v1.Service)

Encode the object.

func (*Service) Get

func (m *Service) Get(db DB) error

Fetch the model from the DB.

func (*Service) Insert

func (m *Service) Insert(db DB) error

Insert the model into the DB.

func (Service) List

func (m Service) List(db DB, options ListOptions) ([]*Service, error)

Fetch the from in the DB.

func (*Service) Update

func (m *Service) Update(db DB) error

Update the model in the DB.

func (*Service) With

func (m *Service) With(object *v1.Service)

Update the model `with` a k8s Service.

type StorageClass

type StorageClass struct {
	Base
}

StorageClass model.

func (StorageClass) Count

func (m StorageClass) Count(db DB, options ListOptions) (int64, error)

Count in the DB.

func (*StorageClass) DecodeObject

func (m *StorageClass) DecodeObject() *v1.StorageClass

Encode the object.

func (*StorageClass) Delete

func (m *StorageClass) Delete(db DB) error

Delete the model in the DB.

func (*StorageClass) EncodeObject

func (m *StorageClass) EncodeObject(StorageClass *v1.StorageClass)

Encode the object.

func (*StorageClass) Get

func (m *StorageClass) Get(db DB) error

Fetch the model from the DB.

func (*StorageClass) Insert

func (m *StorageClass) Insert(db DB) error

Insert the model into the DB.

func (StorageClass) List

func (m StorageClass) List(db DB, options ListOptions) ([]*StorageClass, error)

Fetch the from in the DB.

func (*StorageClass) Update

func (m *StorageClass) Update(db DB) error

Update the model in the DB.

func (*StorageClass) With

func (m *StorageClass) With(object *v1.StorageClass)

Update the model `with` a k8s StorageClass.

type Table

type Table struct {
	// Database connection.
	Db DB
}

Represents a table in the DB. Using reflect, the model is inspected to determine the table name and columns. The column definition is specified using field tags:

pk - Primary key.
key - Natural key.
fk:<table>(field) - Foreign key.
unique(<group>) - Unique constraint collated by <group>.
index(<group>) - Non-unique indexed fields collated by <group>.
const - Not updated.

func (Table) Constraints

func (t Table) Constraints(fields []*Field) []string

Get constraint DDL.

func (Table) Count

func (t Table) Count(model interface{}, options ListOptions) (int64, error)

Count the models in the DB. Qualified by the model field values and list options. Expects natural keys to be set. Else, ALL models counted.

func (Table) DDL

func (t Table) DDL(model interface{}) ([]string, error)

Get table and index create DDL.

func (Table) Delete

func (t Table) Delete(model interface{}) error

Delete the model in the DB. Expects the primary key (PK) or natural keys to be set.

func (Table) DeleteLabels

func (t Table) DeleteLabels(model Model) error

Delete labels for a model in the DB.

func (Table) Fields

func (t Table) Fields(model interface{}) ([]*Field, error)

Get the `Fields` for the model.

func (Table) Get

func (t Table) Get(model interface{}) error

Get the model in the DB. Expects the primary key (PK) or natural keys to be set. Fetch the row and populate the fields in the model.

func (Table) Insert

func (t Table) Insert(model interface{}) error

Insert the model in the DB. Expects the primary key (PK) to be set.

func (Table) InsertLabels

func (t Table) InsertLabels(model Model) error

Insert labels for the model into the DB.

func (Table) KeyFields

func (t Table) KeyFields(fields []*Field) []*Field

Get the natural key `Fields` for the model.

func (Table) List

func (t Table) List(model interface{}, options ListOptions) ([]interface{}, error)

List the model in the DB. Qualified by the model field values and list options. Expects natural keys to be set. Else, ALL models fetched.

func (Table) MutableFields

func (t Table) MutableFields(fields []*Field) []*Field

Get the mutable `Fields` for the model.

func (Table) Name

func (t Table) Name(model interface{}) string

Get the table name for the model.

func (Table) NotEmptyFields

func (t Table) NotEmptyFields(fields []*Field) []*Field

Get the populated `Fields` for the model.

func (Table) Params

func (t Table) Params(fields []*Field) []interface{}

Get the `Fields` referenced as param in SQL.

func (Table) PkField

func (t Table) PkField(fields []*Field) *Field

Get the PK field.

func (Table) ReplaceLabels

func (t Table) ReplaceLabels(model Model) error

Replace labels.

func (Table) Update

func (t Table) Update(model interface{}) error

Update the model in the DB. Expects the primary key (PK) or natural keys to be set.

type TmplData

type TmplData struct {
	// Table name.
	Table string
	// Index name.
	Index string
	// Fields.
	Fields []*Field
	// Constraint DDL.
	Constraints []string
	// Natural key fields.
	Keys []*Field
	// Set (not empty) fields.
	NotEmpty []*Field
	// Primary key.
	Pk *Field
	// List options.
	Options ListOptions
	// Row count.
	Count bool
}

Template data.

func (TmplData) Labels

func (t TmplData) Labels() []Label

Labels list.

Jump to

Keyboard shortcuts

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