dbclient

package
v0.104.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dbclient provides mechanisms for interacting with a database directly

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresClient

type PostgresClient struct {
	DB sqlx.DB
}

PostgresClient is a postgres client based on sqlx

func NewPostgresClient

func NewPostgresClient(host, database, user, password string, port int, use_ssl bool) (*PostgresClient, error)

func NewPostgresClientFromViper

func NewPostgresClientFromViper() (*PostgresClient, error)

func (*PostgresClient) CreateAssets

func (d *PostgresClient) CreateAssets(assets []models.Asset) ([]models.Asset, error)

func (*PostgresClient) CreateAttributes

func (d *PostgresClient) CreateAttributes(attributes []models.Attribute) ([]models.Attribute, error)

func (*PostgresClient) CreateEvent

func (d *PostgresClient) CreateEvent(content string) error

CreateEvent allows inserting into events when an asset or a tag is modified or deleted.

func (*PostgresClient) CreateTags

func (d *PostgresClient) CreateTags(tags []models.Tag) (tagsInserted []models.TagDetailed, err error)

func (*PostgresClient) DeleteAsset

func (d *PostgresClient) DeleteAsset(asset_id int64) (models.Asset, []int64, error)

DeleteAsset deletes one asset identified by asset_id, returning the deleted asset as well as the ids of any asset that was affected by the deletion, and any error encountered.

func (*PostgresClient) DeleteAssetStatus

func (d *PostgresClient) DeleteAssetStatus(assetID int64) (resultAssetID int64, err error)

func (*PostgresClient) DeleteAssetTarget

func (d *PostgresClient) DeleteAssetTarget(assetID int64) (resultAssetID int64, err error)

func (*PostgresClient) DeleteAssets

func (d *PostgresClient) DeleteAssets(assetIDs []int64) ([]models.Asset, []int64, error)

DeleteAssets is a wrapper around DeleteAsset to loop over multiple assetIDs

TODO Move to sql-based logic for more efficiency

func (*PostgresClient) DeleteAttribute

func (d *PostgresClient) DeleteAttribute(attributeID int64) (deletedID int64, err error)

func (*PostgresClient) DeleteAttributes

func (d *PostgresClient) DeleteAttributes(attributeIDs []int64) (deletedIDs []int64, err error)

func (*PostgresClient) DeleteTag

func (d *PostgresClient) DeleteTag(tagID int64) (tag models.Tag, err error)

func (*PostgresClient) DeleteTags

func (d *PostgresClient) DeleteTags(tagIDs []int64) (ids []int64, err error)

DeleteTags attempts to restore the assets identified with assetIDs

It returns all modified asset's IDs and any error enountered.

func (*PostgresClient) Export

func (d *PostgresClient) Export() (assets []models.Asset, attributes []models.Attribute, tags []models.Tag, err error)

func (*PostgresClient) GetAllAssets

func (d *PostgresClient) GetAllAssets(pageSize, page int) ([]models.Asset, error)

func (*PostgresClient) GetAsset

func (d *PostgresClient) GetAsset(id int64) (models.Asset, error)

func (*PostgresClient) GetAssetDescription

func (d *PostgresClient) GetAssetDescription(assetID int64) (resultAssetID int64, description string, err error)

func (*PostgresClient) GetAssetStatus

func (d *PostgresClient) GetAssetStatus(assetID int64) (resultAssetID int64, status string, err error)

func (*PostgresClient) GetAssetTarget

func (d *PostgresClient) GetAssetTarget(assetID int64) (resultAssetID int64, target int64, err error)

func (*PostgresClient) GetAssets

func (d *PostgresClient) GetAssets(deleted bool, pageSize, page int) ([]models.Asset, error)

func (*PostgresClient) GetAssetsDetailed

func (d *PostgresClient) GetAssetsDetailed(deleted bool, page, pageSize int) (assetsDetailed []models.AssetDetailed, err error)

GetAssetsDetailed returns a paginated amount of assets and their tags (asset-attributes)

TODO: Add tags value

func (*PostgresClient) GetAssetsWithAttribute

func (d *PostgresClient) GetAssetsWithAttribute(attributeID int64) ([]models.AssetWithAttributes, error)

GetAssetsWithAttribute returns all assets that have a specific attribute registered

func (*PostgresClient) GetAttribute

func (d *PostgresClient) GetAttribute(attributeID int64) (attribute models.Attribute, err error)

func (*PostgresClient) GetAttributeAllowEmptyValue

func (d *PostgresClient) GetAttributeAllowEmptyValue(attributeID int64) (allowEmptyValue bool, err error)

func (*PostgresClient) GetAttributeKey

func (d *PostgresClient) GetAttributeKey(attributeID int64) (key string, err error)

func (*PostgresClient) GetAttributes

func (d *PostgresClient) GetAttributes() (attributes []models.Attribute, err error)

func (*PostgresClient) GetAttributesAsKeyValuesForAsset

func (d *PostgresClient) GetAttributesAsKeyValuesForAsset(assetID int64) (keyValues []models.KeyValue, err error)

func (*PostgresClient) GetEvents

func (d *PostgresClient) GetEvents(descending bool) (events []models.Event, err error)

func (*PostgresClient) GetTag

func (d *PostgresClient) GetTag(tagID int64) (tag models.Tag, err error)

func (*PostgresClient) GetTagAttribute

func (d *PostgresClient) GetTagAttribute(tagID int64) (attribute models.Attribute, err error)

func (*PostgresClient) GetTagDetailed

func (d *PostgresClient) GetTagDetailed(tagID int64) (tagDetailed models.TagDetailed, err error)

func (*PostgresClient) GetTagValue

func (d *PostgresClient) GetTagValue(tagID int64) (value string, err error)

func (*PostgresClient) GetTags

func (d *PostgresClient) GetTags() (tags []models.Tag, err error)

func (*PostgresClient) Import

func (d *PostgresClient) Import(assets []models.Asset, attributes []models.Attribute, tags []models.Tag) (newAssetsCount, newAttributesCount, newTagsCount uint, err error)

func (*PostgresClient) RestoreAsset

func (d *PostgresClient) RestoreAsset(asset_id int64) (models.Asset, error)

func (*PostgresClient) RestoreAssets

func (d *PostgresClient) RestoreAssets(assetIDs []int64) (ids []int64, err error)

RestoreAssets attempts to restore the assets identified with assetIDs

It returns all modified asset's IDs and any error enountered.

func (*PostgresClient) RestoreAttribute

func (d *PostgresClient) RestoreAttribute(attribute_id int64) (models.Attribute, error)

func (*PostgresClient) Seed

func (d *PostgresClient) Seed() (result sql.Result, err error)

Seed executes the schema defined in models.Scema.

It will add any tables that do not exist, but will not update the fields of existing ones.

func (*PostgresClient) UpdateAssetDescription

func (d *PostgresClient) UpdateAssetDescription(assetID int64, description string) (int64, string, error)

func (*PostgresClient) UpdateAssetStatus

func (d *PostgresClient) UpdateAssetStatus(assetID int64, status string) (resultAssetID int64, resultStatus string, err error)

func (*PostgresClient) UpdateAssetTarget

func (d *PostgresClient) UpdateAssetTarget(assetID, target int64) (int64, int64, error)

func (*PostgresClient) UpdateAttributeAllowEmptyValue

func (d *PostgresClient) UpdateAttributeAllowEmptyValue(attributeID int64, allowEmptyValue bool) (attribute models.Attribute, err error)

func (*PostgresClient) UpdateAttributeKey

func (d *PostgresClient) UpdateAttributeKey(attributeID int64, key string) (attribute models.Attribute, err error)

func (*PostgresClient) UpdateTagValue

func (d *PostgresClient) UpdateTagValue(tagID int64, value string) (models.Tag, error)

Jump to

Keyboard shortcuts

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