Documentation ¶
Overview ¶
nolint
nolint
nolint
Index ¶
- Constants
- Variables
- type DB
- func (db DB) CopyHashesFromSTDIN(tx *pg.Tx, r io.Reader) (int, error)
- func (db DB) CreateTempHashesTable(ctx context.Context, tx *pg.Tx) error
- func (db *DB) RunInLock(ctx context.Context, lockName string, fns ...func(*pg.Tx) error) error
- func (db DB) UpsertHashesTable(ctx context.Context, tx *pg.Tx) (int, time.Duration, error)
- func (db *DB) Version() (string, error)
- type Filter
- type OpFunc
- type Pager
- type Searcher
- type SortDirection
- type SortField
- type VfsFile
- type VfsFileParams
- type VfsFileSearch
- type VfsFolder
- type VfsFolderSearch
- type VfsHash
- type VfsHashSearch
- type VfsRepo
- func (vr VfsRepo) AddVfsFile(ctx context.Context, vfsFile *VfsFile, ops ...OpFunc) (*VfsFile, error)
- func (vr VfsRepo) AddVfsFolder(ctx context.Context, vfsFolder *VfsFolder, ops ...OpFunc) (*VfsFolder, error)
- func (vr VfsRepo) AddVfsHash(ctx context.Context, vfsHash *VfsHash, ops ...OpFunc) (*VfsHash, error)
- func (vr VfsRepo) CountVfsFiles(ctx context.Context, search *VfsFileSearch, ops ...OpFunc) (int, error)
- func (vr VfsRepo) CountVfsFolders(ctx context.Context, search *VfsFolderSearch, ops ...OpFunc) (int, error)
- func (vr VfsRepo) CountVfsHashes(ctx context.Context, search *VfsHashSearch, ops ...OpFunc) (int, error)
- func (vr VfsRepo) DefaultVfsFileSort() OpFunc
- func (vr VfsRepo) DefaultVfsFolderSort() OpFunc
- func (vr VfsRepo) DefaultVfsHashSort() OpFunc
- func (vr VfsRepo) DeleteVfsFile(ctx context.Context, id int) (deleted bool, err error)
- func (vr VfsRepo) DeleteVfsFiles(ctx context.Context, fileIDs []int64) (bool, error)
- func (vr VfsRepo) DeleteVfsFolder(ctx context.Context, id int) (deleted bool, err error)
- func (vr VfsRepo) DeleteVfsHash(ctx context.Context, hash string, namespace string) (deleted bool, err error)
- func (vr VfsRepo) FolderBranch(ctx context.Context, folderId int) (list []VfsFolder, err error)
- func (vr VfsRepo) FullVfsFile() OpFunc
- func (vr VfsRepo) FullVfsFolder() OpFunc
- func (vr VfsRepo) FullVfsHash() OpFunc
- func (vr VfsRepo) HashesForUpdate(ctx context.Context, limit uint64) (list []VfsHash, err error)
- func (vr VfsRepo) NextFileID() (int, error)
- func (vr VfsRepo) OneVfsFile(ctx context.Context, search *VfsFileSearch, ops ...OpFunc) (*VfsFile, error)
- func (vr VfsRepo) OneVfsFolder(ctx context.Context, search *VfsFolderSearch, ops ...OpFunc) (*VfsFolder, error)
- func (vr VfsRepo) OneVfsHash(ctx context.Context, search *VfsHashSearch, ops ...OpFunc) (*VfsHash, error)
- func (vr VfsRepo) SaveVfsHash(ctx context.Context, hash *VfsHash) (err error)
- func (vr VfsRepo) UpdateFilesFolder(ctx context.Context, fileIDs []int64, newFolderId int) (bool, error)
- func (vr VfsRepo) UpdateVfsFile(ctx context.Context, vfsFile *VfsFile, ops ...OpFunc) (bool, error)
- func (vr VfsRepo) UpdateVfsFolder(ctx context.Context, vfsFolder *VfsFolder, ops ...OpFunc) (bool, error)
- func (vr VfsRepo) UpdateVfsHash(ctx context.Context, vfsHash *VfsHash, ops ...OpFunc) (bool, error)
- func (vr VfsRepo) VfsFileByID(ctx context.Context, id int, ops ...OpFunc) (*VfsFile, error)
- func (vr VfsRepo) VfsFilesByFilters(ctx context.Context, search *VfsFileSearch, pager Pager, ops ...OpFunc) (vfsFiles []VfsFile, err error)
- func (vr VfsRepo) VfsFolderByID(ctx context.Context, id int, ops ...OpFunc) (*VfsFolder, error)
- func (vr VfsRepo) VfsFoldersByFilters(ctx context.Context, search *VfsFolderSearch, pager Pager, ops ...OpFunc) (vfsFolders []VfsFolder, err error)
- func (vr VfsRepo) VfsHashByID(ctx context.Context, hash string, namespace string, ops ...OpFunc) (*VfsHash, error)
- func (vr VfsRepo) VfsHashesByFilters(ctx context.Context, search *VfsHashSearch, pager Pager, ops ...OpFunc) (vfsHashes []VfsHash, err error)
- func (vr VfsRepo) WithEnabledOnly() VfsRepo
- func (vr VfsRepo) WithTransaction(tx *pg.Tx) VfsRepo
Constants ¶
const ( SearchTypeEquals = iota SearchTypeNull SearchTypeGE SearchTypeLE SearchTypeGreater SearchTypeLess SearchTypeLike SearchTypeILike SearchTypeArray SearchTypeArrayContains SearchTypeArrayContained SearchTypeArrayIntersect SearchTypeJsonbPath )
const ( ErrEmptyValue = "empty" ErrMaxLength = "len" ErrWrongValue = "value" )
const ( // common statuses StatusEnabled = 1 StatusDisabled = 2 StatusDeleted = 3 )
const TableColumns = "t.*"
const TablePrefix = "t"
Variables ¶
var ( StatusFilter = Filter{Field: "statusId", Value: []int{StatusEnabled, StatusDisabled}, SearchType: SearchTypeArray} StatusEnabledFilter = Filter{Field: "statusId", Value: []int{StatusEnabled}, SearchType: SearchTypeArray} )
var ( PagerDefault = Pager{PageSize: defaultMaxLimit} PagerNoLimit = Pager{PageSize: defaultNoLimit} PagerOne = Pager{PageSize: 1} PagerTwo = Pager{PageSize: 2} )
var Columns = struct { VfsFile struct { ID, FolderID, Title, Path, Params, IsFavorite, MimeType, FileSize, FileExists, CreatedAt, StatusID string Folder string } VfsFolder struct { ID, ParentFolderID, Title, IsFavorite, CreatedAt, StatusID string ParentFolder string } VfsHash struct { Hash, Namespace, Extension, FileSize, Width, Height, Blurhash, CreatedAt, IndexedAt, Error string } }{ VfsFile: struct { ID, FolderID, Title, Path, Params, IsFavorite, MimeType, FileSize, FileExists, CreatedAt, StatusID string Folder string }{ ID: "fileId", FolderID: "folderId", Title: "title", Path: "path", Params: "params", IsFavorite: "isFavorite", MimeType: "mimeType", FileSize: "fileSize", FileExists: "fileExists", CreatedAt: "createdAt", StatusID: "statusId", Folder: "Folder", }, VfsFolder: struct { ID, ParentFolderID, Title, IsFavorite, CreatedAt, StatusID string ParentFolder string }{ ID: "folderId", ParentFolderID: "parentFolderId", Title: "title", IsFavorite: "isFavorite", CreatedAt: "createdAt", StatusID: "statusId", ParentFolder: "ParentFolder", }, VfsHash: struct { Hash, Namespace, Extension, FileSize, Width, Height, Blurhash, CreatedAt, IndexedAt, Error string }{ Hash: "hash", Namespace: "namespace", Extension: "extension", FileSize: "fileSize", Width: "width", Height: "height", Blurhash: "blurhash", CreatedAt: "createdAt", IndexedAt: "indexedAt", Error: "error", }, }
var Tables = struct { VfsFile struct { Name, Alias string } VfsFolder struct { Name, Alias string } VfsHash struct { Name, Alias string } }{ VfsFile: struct { Name, Alias string }{ Name: "vfsFiles", Alias: "t", }, VfsFolder: struct { Name, Alias string }{ Name: "vfsFolders", Alias: "t", }, VfsHash: struct { Name, Alias string }{ Name: "vfsHashes", Alias: "t", }, }
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct { *pg.DB // contains filtered or unexported fields }
DB stores db connection
func New ¶
func New(db *pg.DB) DB
New is a function that returns DB as wrapper on postgres connection.
func (DB) CopyHashesFromSTDIN ¶
CopyHashesFromSTDIN fills temporary hashes table with CSV data
func (DB) CreateTempHashesTable ¶
CreateTempHashesTable creates a temporary table for hashes.
func (DB) UpsertHashesTable ¶
UpsertHashesTable upserts data from tempTable into vfsHashes.
type Filter ¶
type Filter struct { Field string `json:"field"` //search field Value interface{} `json:"value,omitempty"` //search value SearchType int `json:"type,omitempty"` //search type. see db/filter.go Exclude bool `json:"exclude,omitempty"` //is this filter should exclude }
type OpFunc ¶
OpFunc is a function that applies different options to query.
func EnabledOnly ¶
func EnabledOnly() OpFunc
EnabledOnly is a function that adds "statusId"=1 filter to query.
func WithColumns ¶
WithColumns is a function that adds user specific columns to query.
func WithJoinedIDs ¶
WithJoinedIDs adds join VALUES statement for given table and column.
func WithRelations ¶
WithRelations is a function that adds user specific relations to query.
type Pager ¶
type Searcher ¶
type Searcher interface { Apply(query *orm.Query) *orm.Query Q() applier With(condition string, params ...interface{}) WithApply(a applier) }
Searcher is interface for every generated filter
type SortDirection ¶
type SortDirection string
const ( SortAsc SortDirection = "asc" SortAscNullsFirst SortDirection = "asc nulls first" SortAscNullsLast SortDirection = "asc nulls last" SortDesc SortDirection = "desc" SortDescNullsFirst SortDirection = "desc nulls first" SortDescNullsLast SortDirection = "desc nulls last" )
type SortField ¶
type SortField struct { Column string Direction SortDirection }
func NewSortField ¶
type VfsFile ¶
type VfsFile struct { ID int `pg:"fileId,pk"` FolderID int `pg:"folderId,use_zero"` Title string `pg:"title,use_zero"` Path string `pg:"path,use_zero"` Params *VfsFileParams `pg:"params"` IsFavorite *bool `pg:"isFavorite"` MimeType string `pg:"mimeType,use_zero"` FileSize *int `pg:"fileSize"` FileExists bool `pg:"fileExists,use_zero"` CreatedAt time.Time `pg:"createdAt,use_zero"` StatusID int `pg:"statusId,use_zero"` Folder *VfsFolder `pg:"fk:folderId,rel:has-one"` // contains filtered or unexported fields }
type VfsFileParams ¶
type VfsFileSearch ¶
type VfsFileSearch struct { ID *int FolderID *int Title *string Path *string Params *VfsFileParams IsFavorite *bool MimeType *string FileSize *int FileExists *bool CreatedAt *time.Time StatusID *int IDs []int TitleILike *string PathILike *string MimeTypeILike *string // contains filtered or unexported fields }
func (*VfsFileSearch) Q ¶
func (vfs *VfsFileSearch) Q() applier
func (*VfsFileSearch) WithQuery ¶
func (vfs *VfsFileSearch) WithQuery(query *string) *VfsFileSearch
type VfsFolder ¶
type VfsFolder struct { ID int `pg:"folderId,pk"` ParentFolderID *int `pg:"parentFolderId"` Title string `pg:"title,use_zero"` IsFavorite *bool `pg:"isFavorite"` CreatedAt time.Time `pg:"createdAt,use_zero"` StatusID int `pg:"statusId,use_zero"` ParentFolder *VfsFolder `pg:"fk:parentFolderId,rel:has-one"` // contains filtered or unexported fields }
type VfsFolderSearch ¶
type VfsFolderSearch struct { ID *int ParentFolderID *int Title *string IsFavorite *bool CreatedAt *time.Time StatusID *int IDs []int TitleILike *string // contains filtered or unexported fields }
func (*VfsFolderSearch) Q ¶
func (vfs *VfsFolderSearch) Q() applier
type VfsHash ¶
type VfsHash struct { Hash string `pg:"hash,pk"` Namespace string `pg:"namespace,pk"` Extension string `pg:"extension,use_zero"` FileSize int `pg:"fileSize,use_zero"` Width int `pg:"width,use_zero"` Height int `pg:"height,use_zero"` Blurhash *string `pg:"blurhash"` CreatedAt time.Time `pg:"createdAt,use_zero"` IndexedAt *time.Time `pg:"indexedAt"` Error string `pg:"error,use_zero"` // contains filtered or unexported fields }
type VfsHashSearch ¶
type VfsHashSearch struct { Hash *string Namespace *string Extension *string FileSize *int Width *int Height *int Blurhash *string CreatedAt *time.Time IndexedAt *time.Time Error *string Hashes []string HashILike *string Namespaces []string NamespaceILike *string ExtensionILike *string BlurhashILike *string ErrorILike *string // contains filtered or unexported fields }
func (*VfsHashSearch) Q ¶
func (vhs *VfsHashSearch) Q() applier
type VfsRepo ¶
type VfsRepo struct {
// contains filtered or unexported fields
}
func (VfsRepo) AddVfsFile ¶
func (vr VfsRepo) AddVfsFile(ctx context.Context, vfsFile *VfsFile, ops ...OpFunc) (*VfsFile, error)
AddVfsFile adds VfsFile to DB.
func (VfsRepo) AddVfsFolder ¶
func (vr VfsRepo) AddVfsFolder(ctx context.Context, vfsFolder *VfsFolder, ops ...OpFunc) (*VfsFolder, error)
AddVfsFolder adds VfsFolder to DB.
func (VfsRepo) AddVfsHash ¶
func (vr VfsRepo) AddVfsHash(ctx context.Context, vfsHash *VfsHash, ops ...OpFunc) (*VfsHash, error)
AddVfsHash adds VfsHash to DB.
func (VfsRepo) CountVfsFiles ¶
func (vr VfsRepo) CountVfsFiles(ctx context.Context, search *VfsFileSearch, ops ...OpFunc) (int, error)
CountVfsFiles returns count
func (VfsRepo) CountVfsFolders ¶
func (vr VfsRepo) CountVfsFolders(ctx context.Context, search *VfsFolderSearch, ops ...OpFunc) (int, error)
CountVfsFolders returns count
func (VfsRepo) CountVfsHashes ¶
func (vr VfsRepo) CountVfsHashes(ctx context.Context, search *VfsHashSearch, ops ...OpFunc) (int, error)
CountVfsHashes returns count
func (VfsRepo) DefaultVfsFileSort ¶
DefaultVfsFileSort returns default sort.
func (VfsRepo) DefaultVfsFolderSort ¶
DefaultVfsFolderSort returns default sort.
func (VfsRepo) DefaultVfsHashSort ¶
DefaultVfsHashSort returns default sort.
func (VfsRepo) DeleteVfsFile ¶
DeleteVfsFile set statusId to deleted in DB.
func (VfsRepo) DeleteVfsFiles ¶
func (VfsRepo) DeleteVfsFolder ¶
DeleteVfsFolder set statusId to deleted in DB.
func (VfsRepo) DeleteVfsHash ¶
func (vr VfsRepo) DeleteVfsHash(ctx context.Context, hash string, namespace string) (deleted bool, err error)
DeleteVfsHash deletes VfsHash from DB.
func (VfsRepo) FolderBranch ¶
func (VfsRepo) FullVfsFile ¶
FullVfsFile returns full joins with all columns
func (VfsRepo) FullVfsFolder ¶
FullVfsFolder returns full joins with all columns
func (VfsRepo) FullVfsHash ¶
FullVfsHash returns full joins with all columns
func (VfsRepo) HashesForUpdate ¶
func (VfsRepo) NextFileID ¶
func (VfsRepo) OneVfsFile ¶
func (vr VfsRepo) OneVfsFile(ctx context.Context, search *VfsFileSearch, ops ...OpFunc) (*VfsFile, error)
OneVfsFile is a function that returns one VfsFile by filters. It could return pg.ErrMultiRows.
func (VfsRepo) OneVfsFolder ¶
func (vr VfsRepo) OneVfsFolder(ctx context.Context, search *VfsFolderSearch, ops ...OpFunc) (*VfsFolder, error)
OneVfsFolder is a function that returns one VfsFolder by filters. It could return pg.ErrMultiRows.
func (VfsRepo) OneVfsHash ¶
func (vr VfsRepo) OneVfsHash(ctx context.Context, search *VfsHashSearch, ops ...OpFunc) (*VfsHash, error)
OneVfsHash is a function that returns one VfsHash by filters. It could return pg.ErrMultiRows.
func (VfsRepo) SaveVfsHash ¶
SaveVfsHash checks hash in DB and adds it if hash was not found.
func (VfsRepo) UpdateFilesFolder ¶
func (VfsRepo) UpdateVfsFile ¶
UpdateVfsFile updates VfsFile in DB.
func (VfsRepo) UpdateVfsFolder ¶
func (vr VfsRepo) UpdateVfsFolder(ctx context.Context, vfsFolder *VfsFolder, ops ...OpFunc) (bool, error)
UpdateVfsFolder updates VfsFolder in DB.
func (VfsRepo) UpdateVfsHash ¶
UpdateVfsHash updates VfsHash in DB.
func (VfsRepo) VfsFileByID ¶
VfsFileByID is a function that returns VfsFile by ID(s) or nil.
func (VfsRepo) VfsFilesByFilters ¶
func (vr VfsRepo) VfsFilesByFilters(ctx context.Context, search *VfsFileSearch, pager Pager, ops ...OpFunc) (vfsFiles []VfsFile, err error)
VfsFilesByFilters returns VfsFile list.
func (VfsRepo) VfsFolderByID ¶
VfsFolderByID is a function that returns VfsFolder by ID(s) or nil.
func (VfsRepo) VfsFoldersByFilters ¶
func (vr VfsRepo) VfsFoldersByFilters(ctx context.Context, search *VfsFolderSearch, pager Pager, ops ...OpFunc) (vfsFolders []VfsFolder, err error)
VfsFoldersByFilters returns VfsFolder list.
func (VfsRepo) VfsHashByID ¶
func (vr VfsRepo) VfsHashByID(ctx context.Context, hash string, namespace string, ops ...OpFunc) (*VfsHash, error)
VfsHashByID is a function that returns VfsHash by ID(s) or nil.
func (VfsRepo) VfsHashesByFilters ¶
func (vr VfsRepo) VfsHashesByFilters(ctx context.Context, search *VfsHashSearch, pager Pager, ops ...OpFunc) (vfsHashes []VfsHash, err error)
VfsHashesByFilters returns VfsHash list.
func (VfsRepo) WithEnabledOnly ¶
WithEnabledOnly is a function that adds "statusId"=1 as base filter.
func (VfsRepo) WithTransaction ¶
WithTransaction is a function that wraps VfsRepo with pg.Tx transaction.