db

package
v4.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package db provides database connectivity and operations for OpenList

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDatabaseNotInitialized is returned when a database operation is attempted before initialization
	ErrDatabaseNotInitialized = errors.New("database not initialized")
)

Error definitions

Functions

func AutoMigrate

func AutoMigrate(models ...any) error

AutoMigrate performs database schema migrations for the given models Applies special options for MySQL databases to ensure proper charset and engine Parameters:

  • models: list of model structs to migrate

Returns:

  • error if migration fails

func BatchCreateSearchNodes

func BatchCreateSearchNodes(nodes *[]model.SearchNode) error

func ClearSearchNodes

func ClearSearchNodes() error

func Close

func Close()

Close properly closes the database connection Should be called when the application is shutting down

func CreateMeta

func CreateMeta(u *model.Meta) error

func CreateSSHPublicKey

func CreateSSHPublicKey(k *model.SSHPublicKey) error

func CreateSearchNode

func CreateSearchNode(node *model.SearchNode) error

func CreateStorage

func CreateStorage(storage *model.Storage) error

CreateStorage just insert storage to database

func CreateTaskData

func CreateTaskData(t *model.TaskItem) error

func CreateUser

func CreateUser(u *model.User) error

func DeleteMetaById

func DeleteMetaById(id uint) error

func DeleteSSHPublicKeyById

func DeleteSSHPublicKeyById(id uint) error

func DeleteSearchNodesByParent

func DeleteSearchNodesByParent(path string) error

func DeleteSettingItemByKey

func DeleteSettingItemByKey(key string) error

func DeleteStorageById

func DeleteStorageById(id uint) error

DeleteStorageById just delete storage from database by id

func DeleteUserById

func DeleteUserById(id uint) error

func GetDB

func GetDB() *gorm.DB

GetDB returns the current database connection Can be used to perform custom database operations Returns nil if the database has not been initialized

func GetEnabledStorages

func GetEnabledStorages() ([]model.Storage, error)

func GetMetaById

func GetMetaById(id uint) (*model.Meta, error)

func GetMetaByPath

func GetMetaByPath(path string) (*model.Meta, error)

func GetMetas

func GetMetas(pageIndex, pageSize int) (metas []model.Meta, count int64, err error)

func GetPublicSettingItems

func GetPublicSettingItems() ([]model.SettingItem, error)

func GetSSHPublicKeyById

func GetSSHPublicKeyById(id uint) (*model.SSHPublicKey, error)

func GetSSHPublicKeyByUserId

func GetSSHPublicKeyByUserId(userId uint, pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)

func GetSSHPublicKeyByUserTitle

func GetSSHPublicKeyByUserTitle(userId uint, title string) (*model.SSHPublicKey, error)

func GetSSHPublicKeys

func GetSSHPublicKeys(pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)

func GetSearchNodesByParent

func GetSearchNodesByParent(parent string) ([]model.SearchNode, error)

func GetSettingItemByKey

func GetSettingItemByKey(key string) (*model.SettingItem, error)

func GetSettingItems

func GetSettingItems() ([]model.SettingItem, error)

func GetSettingItemsByGroup

func GetSettingItemsByGroup(group int) ([]model.SettingItem, error)

func GetSettingItemsInGroups

func GetSettingItemsInGroups(groups []int) ([]model.SettingItem, error)

func GetStorageById

func GetStorageById(id uint) (*model.Storage, error)

GetStorageById Get Storage by id, used to update storage usually

func GetStorageByMountPath

func GetStorageByMountPath(mountPath string) (*model.Storage, error)

GetStorageByMountPath Get Storage by mountPath, used to update storage usually

func GetStorages

func GetStorages(pageIndex, pageSize int) ([]model.Storage, int64, error)

GetStorages Get all storages from database order by index

func GetTaskDataByType

func GetTaskDataByType(type_s string) (*model.TaskItem, error)

func GetTaskDataFunc

func GetTaskDataFunc(type_s string, enabled bool) func() ([]byte, error)

func GetUserById

func GetUserById(id uint) (*model.User, error)

func GetUserByName

func GetUserByName(username string) (*model.User, error)

func GetUserByRole

func GetUserByRole(role int) (*model.User, error)

func GetUserBySSOID

func GetUserBySSOID(ssoID string) (*model.User, error)

func GetUsers

func GetUsers(pageIndex, pageSize int) (users []model.User, count int64, err error)

func Init

func Init(d *gorm.DB)

Init initializes the database connection and performs schema migrations Parameters:

  • d: database connection instance

The function will terminate the application if migrations fail

func RegisterAuthn

func RegisterAuthn(u *model.User, credential *webauthn.Credential) error

func RemoveAuthn

func RemoveAuthn(u *model.User, id string) error

func SaveSettingItem

func SaveSettingItem(item *model.SettingItem) error

func SaveSettingItems

func SaveSettingItems(items []model.SettingItem) (err error)

func SearchNode

func SearchNode(req model.SearchReq, useFullText bool) ([]model.SearchNode, int64, error)

func UpdateAuthn

func UpdateAuthn(userID uint, authn string) error

func UpdateMeta

func UpdateMeta(u *model.Meta) error

func UpdateSSHPublicKey

func UpdateSSHPublicKey(k *model.SSHPublicKey) error

func UpdateStorage

func UpdateStorage(storage *model.Storage) error

UpdateStorage just update storage in database

func UpdateTaskData

func UpdateTaskData(t *model.TaskItem) error

func UpdateTaskDataFunc

func UpdateTaskDataFunc(type_s string, enabled bool) func([]byte) error

func UpdateUser

func UpdateUser(u *model.User) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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