postgres

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_MAX_RESULT_SIZE = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetModel

type AssetModel struct {
	ID          string    `db:"id"`
	URN         string    `db:"urn"`
	Type        string    `db:"type"`
	Name        string    `db:"name"`
	Service     string    `db:"service"`
	Description string    `db:"description"`
	Data        JSONMap   `db:"data"`
	URL         string    `db:"url"`
	Labels      JSONMap   `db:"labels"`
	Version     string    `db:"version"`
	UpdatedBy   UserModel `db:"updated_by"`
	CreatedAt   time.Time `db:"created_at"`
	UpdatedAt   time.Time `db:"updated_at"`
	// version specific information
	Changelog types.JSONText `db:"changelog"`
	Owners    types.JSONText `db:"owners"`
}

type AssetProbeModel

type AssetProbeModel struct {
	ID           string    `db:"id"`
	AssetURN     string    `db:"asset_urn"`
	Status       string    `db:"status"`
	StatusReason string    `db:"status_reason"`
	Metadata     JSONMap   `db:"metadata"`
	Timestamp    time.Time `db:"timestamp"`
	CreatedAt    time.Time `db:"created_at"`
}

type AssetRepository

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

AssetRepository is a type that manages user operation to the primary database

func NewAssetRepository

func NewAssetRepository(c *Client, userRepo *UserRepository, defaultGetMaxSize int, defaultUserProvider string) (*AssetRepository, error)

NewAssetRepository initializes user repository clients

func (*AssetRepository) AddProbe

func (r *AssetRepository) AddProbe(ctx context.Context, assetURN string, probe *asset.Probe) error

func (*AssetRepository) BuildFilterQuery

func (r *AssetRepository) BuildFilterQuery(builder sq.SelectBuilder, flt asset.Filter) sq.SelectBuilder

BuildFilterQuery retrieves the sql query based on applied filter in the queryString

func (*AssetRepository) DeleteByID

func (r *AssetRepository) DeleteByID(ctx context.Context, id string) error

DeleteByID removes asset using its ID

func (*AssetRepository) DeleteByURN

func (r *AssetRepository) DeleteByURN(ctx context.Context, urn string) error

func (*AssetRepository) GetAll

func (r *AssetRepository) GetAll(ctx context.Context, flt asset.Filter) ([]asset.Asset, error)

GetAll retrieves list of assets with filters

func (*AssetRepository) GetByID

func (r *AssetRepository) GetByID(ctx context.Context, id string) (asset.Asset, error)

GetByID retrieves asset by its ID

func (*AssetRepository) GetByURN

func (r *AssetRepository) GetByURN(ctx context.Context, urn string) (asset.Asset, error)

func (*AssetRepository) GetByVersionWithID

func (r *AssetRepository) GetByVersionWithID(ctx context.Context, id, version string) (asset.Asset, error)

GetByVersionWithID retrieves the specific asset version

func (*AssetRepository) GetByVersionWithURN

func (r *AssetRepository) GetByVersionWithURN(ctx context.Context, urn, version string) (asset.Asset, error)

func (*AssetRepository) GetCount

func (r *AssetRepository) GetCount(ctx context.Context, flt asset.Filter) (int, error)

GetCount retrieves number of assets for every type

func (*AssetRepository) GetProbes

func (r *AssetRepository) GetProbes(ctx context.Context, assetURN string) ([]asset.Probe, error)

func (*AssetRepository) GetProbesWithFilter

func (r *AssetRepository) GetProbesWithFilter(ctx context.Context, flt asset.ProbesFilter) (map[string][]asset.Probe, error)

func (*AssetRepository) GetTypes

func (r *AssetRepository) GetTypes(ctx context.Context, flt asset.Filter) (map[asset.Type]int, error)

GetTypes fetches types with assets count for all available types and returns them as a map[typeName]count

func (*AssetRepository) GetVersionHistory

func (r *AssetRepository) GetVersionHistory(ctx context.Context, flt asset.Filter, id string) ([]asset.Asset, error)

GetVersionHistory retrieves the versions of an asset

func (*AssetRepository) Upsert

func (r *AssetRepository) Upsert(ctx context.Context, ast *asset.Asset) (string, error)

Upsert creates a new asset if it does not exist yet. It updates if asset does exist. Checking existence is done using "urn", "type", and "service" fields.

type Client

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

func NewClient

func NewClient(ctx context.Context, cfg Config) (*Client, error)

NewClient initializes database connection

func NewClientWithDB added in v0.6.0

func NewClientWithDB(db *sql.DB) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) ExecQueries

func (c *Client) ExecQueries(ctx context.Context, queries []string) error

ExecQueries is used for executing list of db query

func (*Client) Migrate

func (c *Client) Migrate() (err error)

func (*Client) RunWithinTx

func (c *Client) RunWithinTx(ctx context.Context, f func(tx *sqlx.Tx) error) error

type Config

type Config struct {
	Host     string `mapstructure:"host" default:"localhost"`
	Port     int    `mapstructure:"port" default:"5432"`
	Name     string `mapstructure:"name" default:"postgres"`
	User     string `mapstructure:"user" default:"root"`
	Password string `mapstructure:"password" default:""`
	SSLMode  string `mapstructure:"sslmode" default:"disable"`
}

func (*Config) ConnectionURL

func (c *Config) ConnectionURL() *url.URL

ConnectionURL

type DiscussionModel

type DiscussionModel struct {
	ID        string         `db:"id"`
	Title     string         `db:"title"`
	Body      string         `db:"body"`
	Type      string         `db:"type"`
	State     string         `db:"state"`
	Owner     UserModel      `db:"owner"`
	Labels    pq.StringArray `db:"labels"`
	Assets    pq.StringArray `db:"assets"`
	Assignees pq.StringArray `db:"assignees"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
}

type DiscussionRepository

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

DiscussionRepository is a type that manages discussion operation to the primary database

func NewDiscussionRepository

func NewDiscussionRepository(c *Client, defaultGetMaxSize int) (*DiscussionRepository, error)

NewDiscussionRepository initializes discussion repository clients

func (*DiscussionRepository) Create

Create inserts a new discussion data

func (*DiscussionRepository) CreateComment

func (r *DiscussionRepository) CreateComment(ctx context.Context, cmt *discussion.Comment) (string, error)

Create adds a new comment to a specific discussion

func (*DiscussionRepository) DeleteComment

func (r *DiscussionRepository) DeleteComment(ctx context.Context, cid, did string) error

Delete removes a comment

func (*DiscussionRepository) Get

Get returns a specific discussion by id

func (*DiscussionRepository) GetAll

GetAll fetchs all discussion data

func (*DiscussionRepository) GetAllComments

func (r *DiscussionRepository) GetAllComments(ctx context.Context, did string, flt discussion.Filter) ([]discussion.Comment, error)

GetAll fetches all comments of a specific discussion

func (*DiscussionRepository) GetComment

func (r *DiscussionRepository) GetComment(ctx context.Context, cid, did string) (discussion.Comment, error)

Get fetchs a comment

func (*DiscussionRepository) Patch

Patch will update a field in discussion

func (*DiscussionRepository) UpdateComment

func (r *DiscussionRepository) UpdateComment(ctx context.Context, cmt *discussion.Comment) error

Update updates a comment

type JSONMap

type JSONMap map[string]interface{}

func (JSONMap) MarshalJSON

func (m JSONMap) MarshalJSON() ([]byte, error)

MarshalJSON to output non base64 encoded []byte

func (*JSONMap) Scan

func (m *JSONMap) Scan(value interface{}) error

func (*JSONMap) UnmarshalJSON

func (m *JSONMap) UnmarshalJSON(b []byte) error

UnmarshalJSON to deserialize []byte

func (JSONMap) Value

func (m JSONMap) Value() (driver.Value, error)

type LineageEdgeModel

type LineageEdgeModel struct {
	Source string  `db:"source"`
	Target string  `db:"target"`
	Prop   JSONMap `db:"prop"`
}

type LineageGraphModel

type LineageGraphModel []LineageEdgeModel

type LineageRepository

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

func NewLineageRepository

func NewLineageRepository(client *Client) (*LineageRepository, error)

NewLineageRepository initializes lineage repository

func (*LineageRepository) DeleteByURN added in v0.5.3

func (repo *LineageRepository) DeleteByURN(ctx context.Context, urn string) error

func (*LineageRepository) GetGraph

func (repo *LineageRepository) GetGraph(ctx context.Context, urn string, query asset.LineageQuery) (asset.LineageGraph, error)

GetGraph returns a graph that contains list of relations of a given node

func (*LineageRepository) Upsert

func (repo *LineageRepository) Upsert(ctx context.Context, urn string, upstreams, downstreams []string) error

Upsert insert or delete connections of a given node by comparing them with current state

type StarClauses

type StarClauses struct {
	Limit            int
	Offset           int
	SortKey          string
	SortDirectionKey string
}

type StarRepository

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

StarRepository is a type that manages star operation to the primary database

func NewStarRepository

func NewStarRepository(c *Client) (*StarRepository, error)

NewStarRepository initializes star repository clients

func (*StarRepository) Create

func (r *StarRepository) Create(ctx context.Context, userID, assetID string) (string, error)

Create insert a new record in the stars table

func (*StarRepository) Delete

func (r *StarRepository) Delete(ctx context.Context, userID, assetID string) error

Delete will delete/unstar a starred asset for a user id

func (*StarRepository) GetAllAssetsByUserID

func (r *StarRepository) GetAllAssetsByUserID(ctx context.Context, flt star.Filter, userID string) ([]asset.Asset, error)

GetAllAssetsByUserID fetch list of assets starred by a user

func (*StarRepository) GetAssetByUserID

func (r *StarRepository) GetAssetByUserID(ctx context.Context, userID, assetID string) (asset.Asset, error)

GetAssetByUserID fetch a specific starred asset by user id

func (*StarRepository) GetStargazers

func (r *StarRepository) GetStargazers(ctx context.Context, flt star.Filter, assetID string) ([]user.User, error)

GetStargazers fetch list of user IDs that star an asset

type TagJoinTemplateFieldModel

type TagJoinTemplateFieldModel struct {
	Template TagTemplateModel      `db:"tag_templates"`
	Field    TagTemplateFieldModel `db:"tag_template_fields"`
}

TagJoinTemplateFieldModel is a placeholder for joined template and field

type TagJoinTemplateFieldModels

type TagJoinTemplateFieldModels []TagJoinTemplateFieldModel

TagJoinTemplateFieldModels is a slice of placeholder for joined template and field

type TagJoinTemplateTagFieldModel

type TagJoinTemplateTagFieldModel struct {
	Template TagTemplateModel      `db:"tag_templates"`
	Tag      TagModel              `db:"tags"`
	Field    TagTemplateFieldModel `db:"tag_template_fields"`
}

TemplateField is a placeholder for joined template, tag, and field

type TagJoinTemplateTagFieldModels

type TagJoinTemplateTagFieldModels []TagJoinTemplateTagFieldModel

TagJoinTemplateTagFieldModels is a slice of placeholder for joined template, tag, and field

type TagModel

type TagModel struct {
	ID        uint                  `db:"id"`
	Value     string                `db:"value"`
	AssetID   string                `db:"asset_id"`
	FieldID   uint                  `db:"field_id"`
	CreatedAt time.Time             `db:"created_at"`
	UpdatedAt time.Time             `db:"updated_at"`
	Field     TagTemplateFieldModel `db:"-"`
}

TagModel is a model for tag value in database table

type TagModels

type TagModels []TagModel

type TagRepository

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

TagRepository is a type that manages tag operation ot the primary database

func NewTagRepository

func NewTagRepository(client *Client) (*TagRepository, error)

NewTagRepository initializes tag repository all methods in tag repository uses passed by reference which will mutate the reference variable in method's argument

func (*TagRepository) Create

func (r *TagRepository) Create(ctx context.Context, domainTag *tag.Tag) error

Create inserts tag to database

func (*TagRepository) Delete

func (r *TagRepository) Delete(ctx context.Context, domainTag tag.Tag) error

Delete deletes tags from database

func (*TagRepository) Read

func (r *TagRepository) Read(ctx context.Context, filter tag.Tag) ([]tag.Tag, error)

Read reads tags grouped by its template

func (*TagRepository) Update

func (r *TagRepository) Update(ctx context.Context, domainTag *tag.Tag) error

Update updates tags in the database

type TagTemplateFieldModel

type TagTemplateFieldModel struct {
	ID          uint             `db:"id"`
	URN         string           `db:"urn"`
	DisplayName string           `db:"display_name"`
	Description string           `db:"description"`
	DataType    string           `db:"data_type"`
	Options     *string          `db:"options"`
	Required    bool             `db:"required"`
	TemplateURN string           `db:"template_urn"`
	CreatedAt   time.Time        `db:"created_at"`
	UpdatedAt   time.Time        `db:"updated_at"`
	Template    TagTemplateModel `db:"-"`
}

TagTemplateFieldModel is a model for field tag in database table

type TagTemplateFieldModels

type TagTemplateFieldModels []TagTemplateFieldModel

type TagTemplateModel

type TagTemplateModel struct {
	URN         string                 `db:"urn"`
	DisplayName string                 `db:"display_name"`
	Description string                 `db:"description"`
	CreatedAt   time.Time              `db:"created_at"`
	UpdatedAt   time.Time              `db:"updated_at"`
	Fields      TagTemplateFieldModels `db:"-"`
}

TagTemplateModel is a model for template database table

type TagTemplateModels

type TagTemplateModels []TagTemplateModel

type TagTemplateRepository

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

TagTemplateRepository is a type that manages template operation to the primary database

func NewTagTemplateRepository

func NewTagTemplateRepository(c *Client) (*TagTemplateRepository, error)

NewTagTemplateRepository initializes template repository clients all methods in template repository uses passed by reference which will mutate the reference variable in method's argument

func (*TagTemplateRepository) Create

func (r *TagTemplateRepository) Create(ctx context.Context, templateDomain *tag.Template) error

Create inserts template to database

func (*TagTemplateRepository) Delete

func (r *TagTemplateRepository) Delete(ctx context.Context, templateURN string) error

Delete deletes template and its fields from database

func (*TagTemplateRepository) Read

func (r *TagTemplateRepository) Read(ctx context.Context, templateURN string) ([]tag.Template, error)

Read reads template from database by URN

func (*TagTemplateRepository) ReadAll

func (r *TagTemplateRepository) ReadAll(ctx context.Context) ([]tag.Template, error)

Read reads all template from database

func (*TagTemplateRepository) Update

func (r *TagTemplateRepository) Update(ctx context.Context, targetURN string, templateDomain *tag.Template) error

Update updates template into database

type UserModel

type UserModel struct {
	ID        sql.NullString `db:"id"`
	UUID      sql.NullString `db:"uuid"`
	Email     sql.NullString `db:"email"`
	Provider  sql.NullString `db:"provider"`
	CreatedAt sql.NullTime   `db:"created_at"`
	UpdatedAt sql.NullTime   `db:"updated_at"`
}

type UserModels

type UserModels []UserModel

type UserRepository

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

UserRepository is a type that manages user operation to the primary database

func NewUserRepository

func NewUserRepository(c *Client) (*UserRepository, error)

NewUserRepository initializes user repository clients

func (*UserRepository) Create

func (r *UserRepository) Create(ctx context.Context, ud *user.User) (string, error)

Create insert a user to the database a new data is still inserted if either uuid or email is empty but returns error if both uuid and email are empty

func (*UserRepository) CreateWithTx

func (r *UserRepository) CreateWithTx(ctx context.Context, tx *sqlx.Tx, ud *user.User) (string, error)

Create insert a user to the database using given transaction as client

func (*UserRepository) GetByEmail

func (r *UserRepository) GetByEmail(ctx context.Context, email string) (user.User, error)

GetUUID retrieves user UUID given the email

func (*UserRepository) GetByEmailWithTx added in v0.5.2

func (r *UserRepository) GetByEmailWithTx(ctx context.Context, querier sqlx.QueryerContext, email string) (user.User, error)

func (*UserRepository) GetByUUID

func (r *UserRepository) GetByUUID(ctx context.Context, uuid string) (user.User, error)

GetbyUUID retrieves user given the uuid

func (*UserRepository) GetByUUIDWithTx added in v0.5.2

func (r *UserRepository) GetByUUIDWithTx(ctx context.Context, querier sqlx.QueryerContext, uuid string) (user.User, error)

func (*UserRepository) UpsertByEmail

func (r *UserRepository) UpsertByEmail(ctx context.Context, ud *user.User) (string, error)

UpsertByEmail updates a row if email match and uuid is empty if email not found, insert a new row

Jump to

Keyboard shortcuts

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