db

package
v0.0.0-...-8401909 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package db contains asset related CRUD functionality.

Index

Constants

View Source
const (
	DocType = "asset"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	NewAsset
	ID  string `json:"_id,omitempty"`
	Rev string `json:"_rev,omitempty"`
}

type NewAsset

type NewAsset struct {
	ID *string `json:"_id"`
	models.Asset
	DocType string `json:"doc_type"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(log *zap.SugaredLogger, couchClient *kivik.Client, dbName string) Store

NewStore constructs an asset store for api access.

func (Store) AddAsset

func (s Store) AddAsset(ctx context.Context, asset models.Asset) (string, string, error)

AddAsset adds an asset to CouchDB. It receives the models.Asset object and transform it into an Asset document object and then insert it into the global CouchDB table.

func (Store) AddAssets

func (s Store) AddAssets(ctx context.Context, assets []models.Asset) (bool, error)

AddAssets bulk-adds assets to CouchDB. It receives the []models.Asset object and transform them into Asset document objects and then insert them into the global CouchDB table.

func (Store) GetAsset

func (s Store) GetAsset(ctx context.Context, assetID string) (models.Asset, error)

GetAsset retrieves a asset record from CouchDB based upon the asset ID given.

func (Store) GetAssetCountBtnKeys

func (s Store) GetAssetCountBtnKeys(ctx context.Context, startKey, endKey string) (int64, error)

GetAssetCountBtnKeys retrieves the number of keys between two keys. References:

https://stackoverflow.com/questions/11284383/couchdb-count-unique-document-field
https://stackoverflow.com/questions/12944294/using-a-couchdb-view-can-i-count-groups-and-filter-by-key-range-at-the-same-tim

func (Store) GetAssetsPagination

func (s Store) GetAssetsPagination(ctx context.Context, latestAssetID string, order string, pageNo, limit int64) ([]Asset, int64, int64, error)

func (Store) GetEarliestAssetID

func (s Store) GetEarliestAssetID(ctx context.Context) (string, error)

func (Store) GetLatestAssetID

func (s Store) GetLatestAssetID(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

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