Version: v0.0.0-...-0feb2aa Latest Latest

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

Go to latest
Published: Jun 24, 2022 License: Apache-2.0 Imports: 21 Imported by: 420




View Source
const (
	// NonExistUserID : if a user does not exist, the ID of the user will be 0.
	NonExistUserID = 0


View Source
var ErrDupRows = errors.New("sql: duplicate row in DB")

ErrDupRows is returned by DAO when inserting failed with error "duplicate key value violates unique constraint"


func AddResourceLabel

func AddResourceLabel(rl *models.ResourceLabel) (int64, error)

AddResourceLabel add a label to a resource

func ArrayEqual

func ArrayEqual(arrayA, arrayB []int) bool

ArrayEqual ...

func ClearHTTPAuthProxyUsers

func ClearHTTPAuthProxyUsers() error

ClearHTTPAuthProxyUsers remove the records from harbor_users to delete all user imported via HTTP Auth Proxy

func ClearTable

func ClearTable(table string) error

ClearTable is the shortcut for test cases, it should be called only in test cases.

func DeleteLabelsOfResource

func DeleteLabelsOfResource(rType string, rIDOrName interface{}) error

DeleteLabelsOfResource removes all labels of the resource

func DeleteResourceLabel

func DeleteResourceLabel(id int64) error

DeleteResourceLabel ...

func DeleteResourceLabelByLabel

func DeleteResourceLabelByLabel(id int64) error

DeleteResourceLabelByLabel delete the mapping relationship by label ID

func ExecuteBatchSQL

func ExecuteBatchSQL(sqls []string)

ExecuteBatchSQL ...

func GetLabelsOfResource

func GetLabelsOfResource(rType string, rIDOrName interface{}) ([]*model.Label, error)

GetLabelsOfResource returns the label list of the resource Get the labels by ResourceID if rIDOrName is int, or get the labels by ResourceName

func GetOrmer

func GetOrmer() orm.Ormer

GetOrmer :set ormer singleton

func GetResourceLabel

func GetResourceLabel(rType string, rIDOrName interface{}, labelID int64) (*models.ResourceLabel, error)

GetResourceLabel specified by resource ID or name Get the ResourceLabel by ResourceID if rIDOrName is int Get the ResourceLabel by ResourceName if rIDOrName is string

func InitDatabase

func InitDatabase(database *models.Database) error

InitDatabase registers the database

func JoinNumberConditions

func JoinNumberConditions(ids []int) string

JoinNumberConditions - To join number condition into string,used in sql query

func ListResourceLabels

func ListResourceLabels(query ...*models.ResourceLabelQuery) ([]*models.ResourceLabel, error)

ListResourceLabels lists ResourceLabel according to the query conditions

func NewMigrator

func NewMigrator(database *models.PostGreSQL) (*migrate.Migrate, error)

NewMigrator creates a migrator base on the information

func PrepareTestData

func PrepareTestData(clearSqls []string, initSqls []string)

PrepareTestData -- Clean and Create data

func PrepareTestForMySQL

func PrepareTestForMySQL()

PrepareTestForMySQL is for test only.

func PrepareTestForPostgresSQL

func PrepareTestForPostgresSQL()

PrepareTestForPostgresSQL is for test only.

func PrepareTestForSQLite

func PrepareTestForSQLite()

PrepareTestForSQLite is for test only.

func UpgradeSchema

func UpgradeSchema(database *models.Database) error

UpgradeSchema will call the internal migrator to upgrade schema based on the setting of database.


type Database

type Database interface {
	// Name returns the name of database
	Name() string
	// String returns the details of database
	String() string
	// Register registers the database which will be used
	Register(alias ...string) error
	// UpgradeSchema upgrades the DB schema to the latest version
	UpgradeSchema() error

Database is an interface of different databases

func NewMySQL

func NewMySQL(host, port, usr, pwd, database string) Database

NewMySQL returns an instance of mysql

func NewPGSQL

func NewPGSQL(host string, port string, usr string, pwd string, database string, sslmode string, maxIdleConns int, maxOpenConns int) Database

NewPGSQL returns an instance of postgres

func NewSQLite

func NewSQLite(file string) Database

NewSQLite returns an instance of sqlite

Jump to

Keyboard shortcuts

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