repository

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: Apache-2.0 Imports: 25 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dbType DBType, dsn string) *sqlRepository

New creates a new instance of the asset database repository.

Types

type Asset

type Asset struct {
	ID        uint64         `gorm:"primaryKey;autoIncrement:true"`                               // The unique identifier of the asset.
	CreatedAt time.Time      `gorm:"type:datetime;default:CURRENT_TIMESTAMP();column=created_at"` // The creation timestamp of the asset.
	LastSeen  time.Time      `gorm:"type:datetime;default:CURRENT_TIMESTAMP();column=last_seen"`  // The last seen timestamp of the asset.
	Type      string         // The type of the asset.
	Content   datatypes.JSON // The JSON-encoded content of the asset.
}

Asset represents an asset stored in the database.

func (*Asset) JSONQuery

func (a *Asset) JSONQuery() (*datatypes.JSONQueryExpression, error)

JSONQuery generates a JSON query expression based on the asset's content. It returns the generated JSON query expression and an error, if any.

func (*Asset) Parse

func (a *Asset) Parse() (oam.Asset, error)

Parse parses the content of the asset into the corresponding Open Asset Model (OAM) asset type. It returns the parsed asset and an error, if any.

type DBType

type DBType string

DBType represents the type of the database.

const (
	// Postgres represents the PostgreSQL database type.
	Postgres DBType = "postgres"
	// SQLite represents the SQLite database type.
	SQLite DBType = "sqlite"
)

type Relation

type Relation struct {
	ID          uint64    `gorm:"primaryKey;autoIncrement:true"`              // The unique identifier of the relation.
	CreatedAt   time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP();"` // The creation timestamp of the relation.
	LastSeen    time.Time `gorm:"type:datetime;default:CURRENT_TIMESTAMP();"` // The last seen timestamp of the relation.
	Type        string    // The type of the relation.
	FromAssetID uint64    // The ID of the asset from which the relation originates.
	ToAssetID   uint64    // The ID of the asset to which the relation points.
	FromAsset   Asset     // The asset from which the relation originates.
	ToAsset     Asset     // The asset to which the relation points.
}

Relation represents a relationship between two assets stored in the database.

type Repository

type Repository interface {
	GetDBType() string
	CreateAsset(asset oam.Asset) (*types.Asset, error)
	UpdateAssetLastSeen(id string) error
	DeleteAsset(id string) error
	DeleteRelation(id string) error
	FindAssetById(id string, since time.Time) (*types.Asset, error)
	FindAssetByContent(asset oam.Asset, since time.Time) ([]*types.Asset, error)
	FindAssetByType(atype oam.AssetType, since time.Time) ([]*types.Asset, error)
	FindAssetByScope(constraints []oam.Asset, since time.Time) ([]*types.Asset, error)
	Link(source *types.Asset, relation string, destination *types.Asset) (*types.Relation, error)
	IncomingRelations(asset *types.Asset, since time.Time, relationTypes ...string) ([]*types.Relation, error)
	OutgoingRelations(asset *types.Asset, since time.Time, relationTypes ...string) ([]*types.Relation, error)
	RawQuery(sqlstr string, results interface{}) error
	AssetQuery(constraints string) ([]*types.Asset, error)
	RelationQuery(constraints string) ([]*types.Relation, error)
	Close() error
}

Repository defines the methods for interacting with the asset database. It provides operations for creating, retrieving, and linking assets.

Jump to

Keyboard shortcuts

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