db

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentVersion = "0.0.2"

Variables

This section is empty.

Functions

func AddAdmin

func AddAdmin(u *model.User) error

func AddAdminByID

func AddAdminByID(userID string) error

func AddRoot

func AddRoot(u *model.User) error

func AddRootByID

func AddRootByID(userID string) error

func AddUserPermission

func AddUserPermission(roomID string, userID string, permission model.RoomUserPermission) error

func BanUser

func BanUser(u *model.User) error

func BanUserByID

func BanUserByID(userID string) error

func BindProvider

func BindProvider(uid string, p provider.OAuth2Provider, puid string) error

func Close

func Close()

func CreateMovie

func CreateMovie(movie *model.Movie) error

func CreateMovies

func CreateMovies(movies []*model.Movie) error

func CreateOrLoadUser

func CreateOrLoadUser(username string, password string, conf ...CreateUserConfig) (*model.User, error)

func CreateOrLoadUserWithHashedPassword

func CreateOrLoadUserWithHashedPassword(username string, hashedPassword []byte, conf ...CreateUserConfig) (*model.User, error)

func CreateOrLoadUserWithProvider

func CreateOrLoadUserWithProvider(username, password string, p provider.OAuth2Provider, puid string, conf ...CreateUserConfig) (*model.User, error)

只有当provider和puid没有找到对应的user时才会创建

func CreateOrSaveAlistVendor added in v0.3.1

func CreateOrSaveAlistVendor(vendorInfo *model.AlistVendor) (*model.AlistVendor, error)

func CreateOrSaveBilibiliVendor added in v0.3.1

func CreateOrSaveBilibiliVendor(vendorInfo *model.BilibiliVendor) (*model.BilibiliVendor, error)

func CreateOrSaveEmbyVendor added in v0.3.1

func CreateOrSaveEmbyVendor(vendorInfo *model.EmbyVendor) (*model.EmbyVendor, error)

func CreateOrSaveVendorBackend added in v0.3.1

func CreateOrSaveVendorBackend(backend *model.VendorBackend) (*model.VendorBackend, error)

func CreateRoom

func CreateRoom(name, password string, maxCount int64, conf ...CreateRoomConfig) (*model.Room, error)

if maxCount is 0, it will be ignored

func CreateUser

func CreateUser(username string, password string, conf ...CreateUserConfig) (*model.User, error)

func CreateUserWithHashedPassword

func CreateUserWithHashedPassword(username string, hashedPassword []byte, conf ...CreateUserConfig) (*model.User, error)

func CreateVendorBackend added in v0.3.1

func CreateVendorBackend(backend *model.VendorBackend) error

func DB

func DB() *gorm.DB

func DeleteAlistVendor added in v0.3.1

func DeleteAlistVendor(userID, serverID string) error

func DeleteBilibiliVendor added in v0.3.1

func DeleteBilibiliVendor(userID string) error

func DeleteEmbyVendor added in v0.3.1

func DeleteEmbyVendor(userID, serverID string) error

func DeleteMovieByID

func DeleteMovieByID(roomID, id string) error

func DeleteMoviesByRoomID

func DeleteMoviesByRoomID(roomID string) error

func DeleteRoomByID

func DeleteRoomByID(roomID string) error

func DeleteSettingItem

func DeleteSettingItem(item *model.Setting) error

func DeleteSettingItemByName

func DeleteSettingItemByName(name string) error

func DeleteUserByID

func DeleteUserByID(userID string) error

func DeleteVendorBackend added in v0.3.1

func DeleteVendorBackend(endpoint string) error

func DeleteVendorBackends added in v0.3.1

func DeleteVendorBackends(endpoints []string) error

func DisableVendorBackend added in v0.3.1

func DisableVendorBackend(endpoint string) error

func DisableVendorBackends added in v0.3.1

func DisableVendorBackends(endpoints []string) error

func EnableVendorBackend added in v0.3.1

func EnableVendorBackend(endpoint string) error

func EnableVendorBackends added in v0.3.1

func EnableVendorBackends(endpoints []string) error

func FirstOrCreateRoomUserRelation

func FirstOrCreateRoomUserRelation(roomID, userID string, conf ...CreateRoomUserRelationConfig) (*model.RoomUserRelation, error)

func FirstOrCreateSettingItemValue

func FirstOrCreateSettingItemValue(s *model.Setting) error

func GerUsersIDByIDLike

func GerUsersIDByIDLike(id string, scopes ...func(*gorm.DB) *gorm.DB) []string

func GerUsersIDByUsernameLike

func GerUsersIDByUsernameLike(username string, scopes ...func(*gorm.DB) *gorm.DB) []string

func GetAdmins

func GetAdmins() []*model.User

func GetAlistVendor added in v0.3.1

func GetAlistVendor(userID, serverID string) (*model.AlistVendor, error)

func GetAlistVendors added in v0.3.2

func GetAlistVendors(userID string, scopes ...func(*gorm.DB) *gorm.DB) ([]*model.AlistVendor, error)

func GetAlistVendorsCount added in v0.3.2

func GetAlistVendorsCount(userID string, scopes ...func(*gorm.DB) *gorm.DB) (int64, error)

func GetAllMoviesByRoomID

func GetAllMoviesByRoomID(roomID string) []*model.Movie

func GetAllRoomUsersRelation

func GetAllRoomUsersRelation(roomID string, scopes ...func(*gorm.DB) *gorm.DB) []*model.RoomUserRelation

func GetAllRoomUsersRelationCount

func GetAllRoomUsersRelationCount(roomID string, scopes ...func(*gorm.DB) *gorm.DB) int64

func GetAllRooms

func GetAllRooms(scopes ...func(*gorm.DB) *gorm.DB) []*model.Room

func GetAllRoomsAndCreator

func GetAllRoomsAndCreator(scopes ...func(*gorm.DB) *gorm.DB) []*model.Room

func GetAllRoomsByUserID

func GetAllRoomsByUserID(userID string) []*model.Room

func GetAllRoomsCount

func GetAllRoomsCount(scopes ...func(*gorm.DB) *gorm.DB) int64

func GetAllUserCount

func GetAllUserCount(scopes ...func(*gorm.DB) *gorm.DB) int64

func GetAllUsers

func GetAllUsers(scopes ...func(*gorm.DB) *gorm.DB) []*model.User

func GetAllVendorBackend added in v0.3.1

func GetAllVendorBackend() ([]*model.VendorBackend, error)

func GetBilibiliVendor added in v0.3.1

func GetBilibiliVendor(userID string) (*model.BilibiliVendor, error)

func GetBindProviders

func GetBindProviders(uid string) ([]*model.UserProvider, error)

func GetEmbyFirstVendor added in v0.3.2

func GetEmbyFirstVendor(userID string) (*model.EmbyVendor, error)

func GetEmbyVendor added in v0.3.1

func GetEmbyVendor(userID, serverID string) (*model.EmbyVendor, error)

func GetEmbyVendors added in v0.3.2

func GetEmbyVendors(userID string, scopes ...func(*gorm.DB) *gorm.DB) ([]*model.EmbyVendor, error)

func GetEmbyVendorsCount added in v0.3.2

func GetEmbyVendorsCount(userID string, scopes ...func(*gorm.DB) *gorm.DB) (int64, error)

func GetProviderUserID

func GetProviderUserID(p provider.OAuth2Provider, puid string) (string, error)

func GetRoomByID

func GetRoomByID(id string) (*model.Room, error)

func GetRoomUserRelation

func GetRoomUserRelation(roomID, userID string) (*model.RoomUserRelation, error)

func GetRoots

func GetRoots() []*model.User

func GetSettingItemByName

func GetSettingItemByName(name string) (*model.Setting, error)

func GetSettingItemValue

func GetSettingItemValue(name string) (string, error)

func GetSettingItems

func GetSettingItems() ([]*model.Setting, error)

func GetSettingItemsToMap added in v0.3.2

func GetSettingItemsToMap() (map[string]*model.Setting, error)

func GetUserByID

func GetUserByID(id string) (*model.User, error)

func GetUserByIDOrUsernameLike

func GetUserByIDOrUsernameLike(idOrUsername string, scopes ...func(*gorm.DB) *gorm.DB) ([]*model.User, error)

func GetUserByProvider

func GetUserByProvider(p provider.OAuth2Provider, puid string) (*model.User, error)

func GetUserByUsername

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

func GetUserByUsernameLike

func GetUserByUsernameLike(username string, scopes ...func(*gorm.DB) *gorm.DB) []*model.User

func GetVendorBackend added in v0.3.1

func GetVendorBackend(endpoint string) (*model.VendorBackend, error)

func HandleNotFound added in v0.3.1

func HandleNotFound(err error, errMsg ...string) error

func Init

func Init(d *gorm.DB, t conf.DatabaseType) error

func LoadAndDeleteMovieByID

func LoadAndDeleteMovieByID(roomID, id string, columns ...clause.Column) (*model.Movie, error)

func LoadAndDeleteMoviesByRoomID

func LoadAndDeleteMoviesByRoomID(roomID string, columns ...clause.Column) ([]*model.Movie, error)

func LoadAndDeleteUserByID

func LoadAndDeleteUserByID(userID string, columns ...clause.Column) (*model.User, error)

func OrderByAsc

func OrderByAsc(column string) func(db *gorm.DB) *gorm.DB

func OrderByCreatedAtAsc

func OrderByCreatedAtAsc(db *gorm.DB) *gorm.DB

func OrderByCreatedAtDesc

func OrderByCreatedAtDesc(db *gorm.DB) *gorm.DB

func OrderByDesc

func OrderByDesc(column string) func(db *gorm.DB) *gorm.DB

func OrderByIDAsc

func OrderByIDAsc(db *gorm.DB) *gorm.DB

func OrderByIDDesc

func OrderByIDDesc(db *gorm.DB) *gorm.DB

func Paginate

func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB

func PreloadRoomUserRelations

func PreloadRoomUserRelations(scopes ...func(*gorm.DB) *gorm.DB) func(db *gorm.DB) *gorm.DB

func PreloadUserProviders

func PreloadUserProviders(scopes ...func(*gorm.DB) *gorm.DB) func(db *gorm.DB) *gorm.DB

func RemoveAdmin

func RemoveAdmin(u *model.User) error

func RemoveAdminByID

func RemoveAdminByID(userID string) error

func RemoveRoot

func RemoveRoot(u *model.User) error

func RemoveRootByID

func RemoveRootByID(userID string) error

func RemoveUserPermission

func RemoveUserPermission(roomID string, userID string, permission model.RoomUserPermission) error

func SaveMovie

func SaveMovie(movie *model.Movie, columns ...clause.Column) error

func SaveRoomSettings

func SaveRoomSettings(roomID string, setting model.RoomSettings) error

func SaveSettingItem

func SaveSettingItem(item *model.Setting) error

func SaveUser

func SaveUser(u *model.User) error

func SaveVendorBackend added in v0.3.1

func SaveVendorBackend(backend *model.VendorBackend) error

func Select

func Select(columns ...string) func(db *gorm.DB) *gorm.DB

func SetRole

func SetRole(u *model.User, role model.Role) error

func SetRoleByID

func SetRoleByID(userID string, role model.Role) error

func SetRoomHashedPassword

func SetRoomHashedPassword(roomID string, hashedPassword []byte) error

func SetRoomPassword

func SetRoomPassword(roomID, password string) error

func SetRoomStatus

func SetRoomStatus(roomID string, status model.RoomStatus) error

func SetRoomStatusByCreator

func SetRoomStatusByCreator(userID string, status model.RoomStatus) error

func SetRoomUserStatus

func SetRoomUserStatus(roomID string, userID string, status model.RoomUserStatus) error

func SetUserHashedPassword

func SetUserHashedPassword(id string, hashedPassword []byte) error

func SetUserPermission

func SetUserPermission(roomID string, userID string, permission model.RoomUserPermission) error

func SetUsernameByID

func SetUsernameByID(userID string, username string) error

func SwapMoviePositions

func SwapMoviePositions(roomID, movie1ID, movie2ID string) (err error)

func Transactional added in v0.3.1

func Transactional(txFunc func(*gorm.DB) error) (err error)

func UnBindProvider

func UnBindProvider(uid string, p provider.OAuth2Provider) error

当用户是通过provider注册的时候,则最少保留一个provider,否则禁止解除绑定

func UnbanUser

func UnbanUser(u *model.User) error

func UnbanUserByID

func UnbanUserByID(userID string) error

func UpdateMovie

func UpdateMovie(movie *model.Movie, columns ...clause.Column) error

func UpdateSettingItemValue

func UpdateSettingItemValue(name, value string) error

func UpgradeDatabase added in v0.3.2

func UpgradeDatabase() error

func WhereCreatorID

func WhereCreatorID(creatorID string) func(db *gorm.DB) *gorm.DB

func WhereCreatorIDIn

func WhereCreatorIDIn(ids []string) func(db *gorm.DB) *gorm.DB

func WhereEqual

func WhereEqual(column string, value interface{}) func(db *gorm.DB) *gorm.DB

column cannot be a user parameter

func WhereIDIn

func WhereIDIn(ids []string) func(db *gorm.DB) *gorm.DB

func WhereIDLike

func WhereIDLike(id string) func(db *gorm.DB) *gorm.DB

func WhereLike

func WhereLike(column string, value string) func(db *gorm.DB) *gorm.DB

column cannot be a user parameter

func WhereRole

func WhereRole(role model.Role) func(db *gorm.DB) *gorm.DB

func WhereRoomID

func WhereRoomID(roomID string) func(db *gorm.DB) *gorm.DB

func WhereRoomNameLike

func WhereRoomNameLike(name string) func(db *gorm.DB) *gorm.DB

func WhereRoomNameLikeOrCreatorInOrIDLike

func WhereRoomNameLikeOrCreatorInOrIDLike(name string, ids []string, id string) func(db *gorm.DB) *gorm.DB

func WhereRoomNameLikeOrIDLike

func WhereRoomNameLikeOrIDLike(name string, id string) func(db *gorm.DB) *gorm.DB

func WhereRoomSettingHidden

func WhereRoomSettingHidden() func(db *gorm.DB) *gorm.DB

func WhereRoomSettingWithoutHidden

func WhereRoomSettingWithoutHidden() func(db *gorm.DB) *gorm.DB

func WhereRoomUserStatus

func WhereRoomUserStatus(status model.RoomUserStatus) func(db *gorm.DB) *gorm.DB

func WhereStatus

func WhereStatus(status model.RoomStatus) func(db *gorm.DB) *gorm.DB

func WhereUserID

func WhereUserID(userID string) func(db *gorm.DB) *gorm.DB

func WhereUsernameLike

func WhereUsernameLike(name string) func(db *gorm.DB) *gorm.DB

func WhereUsernameLikeOrIDIn

func WhereUsernameLikeOrIDIn(name string, ids []string) func(db *gorm.DB) *gorm.DB

func WithUser

func WithUser(db *gorm.DB) *gorm.DB

Types

type CreateRoomConfig

type CreateRoomConfig func(r *model.Room)

func WithCreator

func WithCreator(creator *model.User) CreateRoomConfig

func WithRelations

func WithRelations(relations []model.RoomUserRelation) CreateRoomConfig

func WithSetting

func WithSetting(setting model.RoomSettings) CreateRoomConfig

func WithStatus

func WithStatus(status model.RoomStatus) CreateRoomConfig

type CreateRoomUserRelationConfig

type CreateRoomUserRelationConfig func(r *model.RoomUserRelation)

func WithRoomUserRelationPermissions

func WithRoomUserRelationPermissions(permissions model.RoomUserPermission) CreateRoomUserRelationConfig

func WithRoomUserRelationStatus

func WithRoomUserRelationStatus(status model.RoomUserStatus) CreateRoomUserRelationConfig

type CreateUserConfig

type CreateUserConfig func(u *model.User)

func WithAppendProvider

func WithAppendProvider(p provider.OAuth2Provider, puid string) CreateUserConfig

func WithAppendProviders

func WithAppendProviders(providers []model.UserProvider) CreateUserConfig

func WithRegisteredByProvider

func WithRegisteredByProvider(b bool) CreateUserConfig

func WithRole

func WithRole(role model.Role) CreateUserConfig

func WithSetProvider

func WithSetProvider(p provider.OAuth2Provider, puid string) CreateUserConfig

func WithSetProviders

func WithSetProviders(providers []model.UserProvider) CreateUserConfig

type ErrNotFound added in v0.3.1

type ErrNotFound string

func (ErrNotFound) Error added in v0.3.1

func (e ErrNotFound) Error() string

Jump to

Keyboard shortcuts

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