entities

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: ISC Imports: 8 Imported by: 5

Documentation

Overview

This entities package covers basic model and database functionnality. * Entities should generally not be directly created/retrieved/etc. except for testing purposes. Attempting to do so will result in an error. * Notice that the methods use the interface 'orm.DB', which accepts either a pg.DB or pg.Tx. This will typically be a Tx (as entity-row changes should be coordinated with other row changes in a transaction).

Index

Constants

This section is empty.

Variables

View Source
var ArchiveOp = &stateOp{
	func(q *orm.Query) (orm.Result, error) { return q.Delete() },
	`archive`,
}
View Source
var CreateOp = &stateOp{
	func(q *orm.Query) (orm.Result, error) { return q.Insert() },
	`create`,
}
View Source
var DeleteOp = &stateOp{
	func(q *orm.Query) (orm.Result, error) { return q.ForceDelete() },
	`delete`,
}
View Source
var EntityFields = []string{
	`resource_name`,
	`name`,
	`description`,
	`owner_id`,
	`publicly_readable`,
	`created_at`,
	`last_updated`,
	`deleted_at`,
}
View Source
var ListOp = &retrieveOp{
	func(q *orm.Query) (int, error) { return q.SelectAndCount() },
	`list`,
}
View Source
var MustRetrieveOp = &retrieveOp{
	func(q *orm.Query) (int, error) {
		if err := q.Select(); err != nil {
			if err == pg.ErrNoRows {
				return 0, err
			} else {
				return -1, err
			}
		}
		return 1, nil
	},
	`must retrieve`,
}
View Source
var RetrieveOp = &retrieveOp{
	func(q *orm.Query) (int, error) {
		if err := q.Select(); err != nil {
			if err == pg.ErrNoRows {
				return 0, nil
			} else {
				return -1, err
			}
		}
		return 1, nil
	},
	`retrieve`,
}
View Source
var UpdateOp = &stateOp{
	func(q *orm.Query) (orm.Result, error) { return q.Update() },
	`update`,
}

Functions

func RunRetrieveOp

func RunRetrieveOp(q *orm.Query, op *retrieveOp) (int, error)

func RunStateQueries

func RunStateQueries(qs []*orm.Query, op *stateOp) error

Types

type EID

type EID string

EID is the 'Entity ID' type.

type Entity

type Entity struct {

	// Note, the ID is for internal use only and may or may not be set depending
	// in the source of the item (client or backend).
	ID               EID          `json:"id" pg:",pk"`
	ResourceName     ResourceName `json:"resourceName"`
	Name             string       `json:"name"`
	Description      string       `json:"description"`
	OwnerID          EID          `json:"ownerPubId"`
	PubliclyReadable bool         `json:"publiclyReadable" pg:",notnull"`
	CreatedAt        time.Time    `json:"createdAt"`
	LastUpdated      time.Time    `json:"lastUpdated"`
	DeletedAt        time.Time    `json:"deletedAt" pg:",soft_delete"`
	// contains filtered or unexported fields
}

Entity is the base type for all independent entities in the Liquid Code model. Any item which is directly retrievable, an authorization target, or authorization subject must embed the Entity type. An Entity should be considered an "abstract" type and never created directly, but only as part of a concrete, final type.

func NewEntity

func NewEntity(
	resourceName ResourceName,
	name string,
	description string,
	ownerID EID,
	publiclyReadable bool) *Entity

func (*Entity) ArchiveQueries

func (e *Entity) ArchiveQueries(db orm.DB) []*orm.Query

func (*Entity) Clone

func (e *Entity) Clone() *Entity

func (*Entity) CloneNew

func (e *Entity) CloneNew() *Entity

func (*Entity) CreateQueries

func (e *Entity) CreateQueries(db orm.DB) []*orm.Query

func (*Entity) DeleteQueries

func (e *Entity) DeleteQueries(db orm.DB) []*orm.Query

func (*Entity) GetCreatedAt

func (e *Entity) GetCreatedAt() time.Time

func (*Entity) GetDeletedAt

func (e *Entity) GetDeletedAt() time.Time

func (*Entity) GetDescription

func (e *Entity) GetDescription() string

func (*Entity) GetEntity

func (e *Entity) GetEntity() *Entity

func (*Entity) GetID

func (e *Entity) GetID() EID

func (*Entity) GetLastUpdated

func (e *Entity) GetLastUpdated() time.Time

func (*Entity) GetName

func (e *Entity) GetName() string

func (*Entity) GetOwnerID

func (e *Entity) GetOwnerID() EID

func (*Entity) GetResourceName

func (e *Entity) GetResourceName() ResourceName

func (*Entity) IsConcrete

func (e *Entity) IsConcrete() bool

func (*Entity) IsPubliclyReadable

func (e *Entity) IsPubliclyReadable() bool

func (*Entity) RetrieveByIDQueries

func (e *Entity) RetrieveByIDQueries(id EID, db orm.DB) *orm.Query

func (*Entity) SetDescription

func (e *Entity) SetDescription(d string)

func (*Entity) SetName

func (e *Entity) SetName(n string)

func (*Entity) SetOwnerID

func (e *Entity) SetOwnerID(pid EID)

func (*Entity) SetPubliclyReadable

func (e *Entity) SetPubliclyReadable(r bool)

func (*Entity) UpdateQueries

func (e *Entity) UpdateQueries(db orm.DB) []*orm.Query

type ItemManager

type ItemManager struct {
	AllowUnsafeStateChange bool
	// contains filtered or unexported fields
}

func ConnectItemManager

func ConnectItemManager() *ItemManager

func ConnectItemManagerWithContext

func ConnectItemManagerWithContext(ctx context.Context) *ItemManager

func (*ItemManager) ArchiveRaw

func (im *ItemManager) ArchiveRaw(item archivable) error

func (*ItemManager) Begin

func (im *ItemManager) Begin() (*pg.Tx, error)

func (*ItemManager) BeginIfNecessary

func (im *ItemManager) BeginIfNecessary() (*pg.Tx, error)

func (*ItemManager) Commit

func (im *ItemManager) Commit() error

func (*ItemManager) CreateRaw

func (im *ItemManager) CreateRaw(item creatable) error

func (*ItemManager) DeleteRaw

func (im *ItemManager) DeleteRaw(item deletable) error

func (*ItemManager) GetDB

func (im *ItemManager) GetDB() orm.DB

func (*ItemManager) Rollback

func (im *ItemManager) Rollback() error

func (*ItemManager) UpdateRaw

func (im *ItemManager) UpdateRaw(item updatable) error

type ResourceName

type ResourceName string

Jump to

Keyboard shortcuts

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