mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-07-04 17:06:49 +00:00
Convert db backend to use Gorm, with basis for support
for Mysql and Postgres in addition to existing Sqlite
This commit is contained in:
36
backend/internal/entity/lists.go
Normal file
36
backend/internal/entity/lists.go
Normal file
@ -0,0 +1,36 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"npm/internal/database"
|
||||
"npm/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// ListableModel is a interface for common use
|
||||
type ListableModel interface {
|
||||
TableName() string
|
||||
}
|
||||
|
||||
// ListResponse is the JSON response for users list
|
||||
type ListResponse struct {
|
||||
Total int64 `json:"total"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
Sort []model.Sort `json:"sort"`
|
||||
Filter []model.Filter `json:"filter,omitempty"`
|
||||
Items interface{} `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
// ListQueryBuilder is used to setup queries for lists
|
||||
func ListQueryBuilder(
|
||||
pageInfo *model.PageInfo,
|
||||
defaultSort model.Sort,
|
||||
filters []model.Filter,
|
||||
) *gorm.DB {
|
||||
scopes := make([]func(*gorm.DB) *gorm.DB, 0)
|
||||
scopes = append(scopes, ScopeOrderBy(pageInfo, defaultSort))
|
||||
scopes = append(scopes, ScopeOffsetLimit(pageInfo))
|
||||
// scopes = append(scopes, ScopeFilters(GetFilterMap(m)))
|
||||
return database.GetDB().Scopes(scopes...)
|
||||
}
|
Reference in New Issue
Block a user