db

package
v0.0.0-...-c0f13c9 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckUserQuota

func CheckUserQuota(ctx context.Context, userID int, fileSize int64) (bool, error)

CheckUserQuota checks if a user has enough space for a file of given size

func CleanupExpiredUploadSessions

func CleanupExpiredUploadSessions(ctx context.Context) error

func Close

func Close() error

func CountUsers

func CountUsers(ctx context.Context) (int, error)

func CreateFile

func CreateFile(ctx context.Context, file *model.FileObject) error

CreateFile creates a new file record in the database

func CreateRepository

func CreateRepository(ctx context.Context, mo *model.Repository) error

func CreateShare

func CreateShare(ctx context.Context, mo *model.Share) error

func CreateUploadChunk

func CreateUploadChunk(ctx context.Context, chunk *model.UploadChunk) error

func CreateUploadSession

func CreateUploadSession(ctx context.Context, session *model.UploadSession) error

func CreateUser

func CreateUser(ctx context.Context, user *model.User) error

CreateUser creates a new user in the database

func DeleteFile

func DeleteFile(ctx context.Context, id int) error

DeleteFile deletes a file with the given ID

func DeleteFileByPath

func DeleteFileByPath(ctx context.Context, repoID int, path string) error

DeleteFileByPath marks a file as deleted by path and user

func DeleteShareByID

func DeleteShareByID(ctx context.Context, id int) error

func DeleteUploadSession

func DeleteUploadSession(ctx context.Context, uploadID string) error

func DeleteUser

func DeleteUser(ctx context.Context, id int) error

DeleteUser marks a user as inactive (soft delete)

func GetChangesSince

func GetChangesSince(ctx context.Context, repoID int, sinceVersion string, limit int) ([]*model.ChangeLog, error)

func GetChildFiles

func GetChildFiles(ctx context.Context, parentID int) ([]*model.FileObject, error)

func GetCurrentVersion

func GetCurrentVersion(ctx context.Context, repoID int) (*model.RepositoryVersion, error)

func GetDB

func GetDB() *bun.DB

func GetFile

func GetFile(ctx context.Context, reposID int, path string) (*model.FileObject, error)

GetFile retrieves a file by repository ID and path

func GetFileByID

func GetFileByID(ctx context.Context, id int) (*model.FileObject, error)

GetFileByID retrieves a file by ID

func GetFilesByUserAndPathPrefix

func GetFilesByUserAndPathPrefix(ctx context.Context, userID int, pathPrefix string) ([]*model.FileObject, error)

GetFilesByUserAndPathPrefix retrieves files under a specific path for a user

func GetRepositoryByID

func GetRepositoryByID(ctx context.Context, id int) (*model.Repository, error)

func GetRepositoryByName

func GetRepositoryByName(ctx context.Context, name string) (*model.Repository, error)

func GetRepositoryByNameAndOwner

func GetRepositoryByNameAndOwner(ctx context.Context, name string, userID int) (*model.Repository, error)

func GetShareByID

func GetShareByID(ctx context.Context, id int) (*model.Share, error)

func GetShareForObject

func GetShareForObject(ctx context.Context, userID int, res *model.Resource) (*model.Share, error)

func GetSharesByUserID

func GetSharesByUserID(ctx context.Context, userID int) ([]*model.Share, error)

func GetUploadChunk

func GetUploadChunk(ctx context.Context, uploadID string, chunkIndex int) (*model.UploadChunk, error)

func GetUploadSession

func GetUploadSession(ctx context.Context, uploadID string) (*model.UploadSession, error)

func GetUploadedChunks

func GetUploadedChunks(ctx context.Context, uploadID string) ([]*model.UploadChunk, error)

func GetUserByEmail

func GetUserByEmail(ctx context.Context, email string) (*model.User, error)

GetUserByEmail retrieves a user by email

func GetUserByID

func GetUserByID(ctx context.Context, id int) (*model.User, error)

GetUserByID retrieves a user by ID

func GetUserByUsername

func GetUserByUsername(ctx context.Context, username string) (*model.User, error)

GetUserByUsername retrieves a user by username

func GetUserQuotaUsage

func GetUserQuotaUsage(ctx context.Context, userID int) (int64, error)

GetUserQuotaUsage returns the used bytes for a user

func IncrementUploadedChunks

func IncrementUploadedChunks(ctx context.Context, uploadID string) error

func Init

func Init(ctx context.Context, dsn string)

func ListRepositories

func ListRepositories(ctx context.Context, userID int) ([]*model.Repository, error)

func RecordChange

func RecordChange(ctx context.Context, change *model.ChangeLog) error

func UpdateContentType

func UpdateContentType(ctx context.Context, objects []*model.FileObject) error

UpdateContentType updates content type of specified objects in database.

func UpdateFile

func UpdateFile(ctx context.Context, id int, update *FileUpdate) error

UpdateFile updates a file in the database

func UpdateUploadSessionStatus

func UpdateUploadSessionStatus(ctx context.Context, uploadID string, status string) error

func UpdateUser

func UpdateUser(ctx context.Context, id int, update *UserUpdate) error

UpdateUser updates a user in the database

func UpdateUserHA1

func UpdateUserHA1(ctx context.Context, id int, ha1 string) error

UpdateUserHA1 updates a user's HA1 hash and realm

func UpdateUserQuota

func UpdateUserQuota(ctx context.Context, userID int, totalQuotaBytes int64) error

UpdateUserQuota updates the storage quota for a user

func UpdateVersion

func UpdateVersion(ctx context.Context, repoID int, newVersion string, versionVector string) error

func UpsertFile

func UpsertFile(ctx context.Context, file *model.FileObject) error

UpsertFile creates a new file or updates an existing file in the database using PostgreSQL's UPSERT functionality based on repo_id and path

Types

type ChangeLogModel

type ChangeLogModel struct {
	bun.BaseModel `bun:"table:change_log"`
	*model.ChangeLog
}

type FileModel

type FileModel struct {
	bun.BaseModel `bun:"table:files"`
	*model.FileObject
}

FileModel represents a file object for database operations

func GetFilesByUser

func GetFilesByUser(ctx context.Context, userID int) ([]*FileModel, error)

GetFilesByUser retrieves all files for a specific user

type FileUpdate

type FileUpdate struct {
	MimeType  *string    `json:"mime_type,omitempty"`
	Size      *int64     `json:"size,omitempty"`
	Checksum  *string    `json:"checksum,omitempty"`
	UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

FileUpdate contains fields that can be updated for a file

type ReposModel

type ReposModel struct {
	bun.BaseModel `bun:"table:repositories"`
	*model.Repository
}

type RepositoryVersionModel

type RepositoryVersionModel struct {
	bun.BaseModel `bun:"table:repository_versions"`
	*model.RepositoryVersion
}

type ShareModel

type ShareModel struct {
	bun.BaseModel `bun:"table:shares"`
	*model.Share
}

ShareModel represents a share object for database operations

type UploadChunkModel

type UploadChunkModel struct {
	bun.BaseModel `bun:"table:upload_chunks"`
	*model.UploadChunk
}

type UploadSessionModel

type UploadSessionModel struct {
	bun.BaseModel `bun:"table:upload_sessions"`
	*model.UploadSession
}

type UserModel

type UserModel struct {
	bun.BaseModel `bun:"table:users"`
	*model.User
}

UserModel represents a user in the system

type UserQuotaModel

type UserQuotaModel struct {
	bun.BaseModel `bun:"table:user_quota"`
	*model.UserQuota
}

UserQuotaModel represents storage quota for a user

func GetUserQuota

func GetUserQuota(ctx context.Context, userID int) (*UserQuotaModel, error)

GetUserQuota retrieves the storage quota for a user

type UserUpdate

type UserUpdate struct {
	FirstName *string    `json:"first_name,omitempty"`
	LastName  *string    `json:"last_name,omitempty"`
	LastLogin *time.Time `json:"last_login,omitempty"`
	IsActive  *bool      `json:"is_active,omitempty"`
	IsAdmin   *bool      `json:"is_admin,omitempty"`
}

UserUpdate contains fields that can be updated for a user

Jump to

Keyboard shortcuts

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