mirror of
https://github.com/HChaZZY/alist.git
synced 2025-12-17 23:56:25 +08:00
feat: adapt postgres (close #740)
This commit is contained in:
@@ -159,7 +159,7 @@ func GetAccountById(id uint) (*Account, error) {
|
|||||||
func GetAccountFiles() ([]File, error) {
|
func GetAccountFiles() ([]File, error) {
|
||||||
files := make([]File, 0)
|
files := make([]File, 0)
|
||||||
var accounts []Account
|
var accounts []Account
|
||||||
if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil {
|
if err := conf.DB.Order(columnName("index")).Find(&accounts).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, v := range accounts {
|
for _, v := range accounts {
|
||||||
@@ -179,7 +179,7 @@ func GetAccountFiles() ([]File, error) {
|
|||||||
|
|
||||||
func GetAccounts() ([]Account, error) {
|
func GetAccounts() ([]Account, error) {
|
||||||
var accounts []Account
|
var accounts []Account
|
||||||
if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil {
|
if err := conf.DB.Order(columnName("index")).Find(&accounts).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func SaveSetting(item SettingItem) error {
|
|||||||
|
|
||||||
func GetSettingsPublic() ([]SettingItem, error) {
|
func GetSettingsPublic() ([]SettingItem, error) {
|
||||||
var items []SettingItem
|
var items []SettingItem
|
||||||
if err := conf.DB.Where("`access` <> ?", 1).Find(&items).Error; err != nil {
|
if err := conf.DB.Where(fmt.Sprintf("%s <> ?", columnName("access")), 1).Find(&items).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return items, nil
|
return items, nil
|
||||||
@@ -58,7 +58,7 @@ func GetSettingsPublic() ([]SettingItem, error) {
|
|||||||
|
|
||||||
func GetSettingsByGroup(group int) ([]SettingItem, error) {
|
func GetSettingsByGroup(group int) ([]SettingItem, error) {
|
||||||
var items []SettingItem
|
var items []SettingItem
|
||||||
if err := conf.DB.Where("`group` = ?", group).Find(&items).Error; err != nil {
|
if err := conf.DB.Where(fmt.Sprintf("%s = ?", columnName("group")), group).Find(&items).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
items = append([]SettingItem{Version}, items...)
|
items = append([]SettingItem{Version}, items...)
|
||||||
@@ -82,7 +82,7 @@ func DeleteSetting(key string) error {
|
|||||||
|
|
||||||
func GetSettingByKey(key string) (*SettingItem, error) {
|
func GetSettingByKey(key string) (*SettingItem, error) {
|
||||||
var items SettingItem
|
var items SettingItem
|
||||||
if err := conf.DB.Where("`key` = ?", key).First(&items).Error; err != nil {
|
if err := conf.DB.Where(fmt.Sprintf("%s = ?", columnName("key")), key).First(&items).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &items, nil
|
return &items, nil
|
||||||
|
|||||||
13
model/util.go
Normal file
13
model/util.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func columnName(name string) string {
|
||||||
|
if conf.Conf.Database.Type == "postgres" {
|
||||||
|
return fmt.Sprintf(`"%s"`, name)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("`%s`", name)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user