mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-23 06:32:28 +08:00
fix: some bugs
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
appname: eiblog
|
appname: eiblog
|
||||||
database:
|
database:
|
||||||
driver: mongodb
|
driver: postgres
|
||||||
source: mongodb://localhost:27017
|
source: host=localhost port=5432 user=postgres dbname=eiblog sslmode=disable password=MTI3LjAuMC4x
|
||||||
eshost: http://localhost:9200
|
eshost: http://localhost:9200
|
||||||
eiblogapp:
|
eiblogapp:
|
||||||
mode:
|
mode:
|
||||||
|
|||||||
2
pkg/cache/cache.go
vendored
2
pkg/cache/cache.go
vendored
@@ -419,7 +419,7 @@ func (c *Cache) loadOrInit() error {
|
|||||||
Author: blogapp.Account.Username,
|
Author: blogapp.Account.Username,
|
||||||
Title: "关于",
|
Title: "关于",
|
||||||
Slug: "about",
|
Slug: "about",
|
||||||
CreatedAt: time.Time{},
|
CreatedAt: time.Time{}.AddDate(0, 0, 1),
|
||||||
}
|
}
|
||||||
err = c.InsertArticle(context.Background(), about, ArticleStartID)
|
err = c.InsertArticle(context.Background(), about, ArticleStartID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
5
pkg/cache/store/mongodb.go
vendored
5
pkg/cache/store/mongodb.go
vendored
@@ -14,8 +14,9 @@ import (
|
|||||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
)
|
)
|
||||||
|
|
||||||
// driver: mongodb
|
// example:
|
||||||
// source: mongodb://localhost:27017
|
// driver: mongodb
|
||||||
|
// source: mongodb://localhost:27017
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mongoDBName = "eiblog"
|
mongoDBName = "eiblog"
|
||||||
|
|||||||
36
pkg/cache/store/rdbms.go
vendored
36
pkg/cache/store/rdbms.go
vendored
@@ -15,6 +15,22 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// example:
|
||||||
|
// driver: mysql
|
||||||
|
// source: user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local
|
||||||
|
//
|
||||||
|
// driver: postgres
|
||||||
|
// source: host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable
|
||||||
|
//
|
||||||
|
// driver: sqlite
|
||||||
|
// source: /path/gorm.db
|
||||||
|
//
|
||||||
|
// driver: sqlserver
|
||||||
|
// source: sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm
|
||||||
|
//
|
||||||
|
// driver: clickhouse
|
||||||
|
// source: tcp://localhost:9000?database=gorm&username=gorm&password=gorm&read_timeout=10&write_timeout=20
|
||||||
|
|
||||||
type rdbms struct {
|
type rdbms struct {
|
||||||
*gorm.DB
|
*gorm.DB
|
||||||
}
|
}
|
||||||
@@ -64,7 +80,8 @@ func (db *rdbms) LoadInsertBlogger(ctx context.Context, blogger *model.Blogger)
|
|||||||
|
|
||||||
// UpdateBlogger 更新博客
|
// UpdateBlogger 更新博客
|
||||||
func (db *rdbms) UpdateBlogger(ctx context.Context, fields map[string]interface{}) error {
|
func (db *rdbms) UpdateBlogger(ctx context.Context, fields map[string]interface{}) error {
|
||||||
return db.Model(model.Blogger{}).Updates(fields).Error
|
return db.Model(model.Blogger{}).Session(&gorm.Session{AllowGlobalUpdate: true}).
|
||||||
|
Updates(fields).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadInsertAccount 读取或创建账户
|
// LoadInsertAccount 读取或创建账户
|
||||||
@@ -102,7 +119,20 @@ func (db *rdbms) LoadAllSerie(ctx context.Context) (model.SortedSeries, error) {
|
|||||||
|
|
||||||
// InsertArticle 创建文章
|
// InsertArticle 创建文章
|
||||||
func (db *rdbms) InsertArticle(ctx context.Context, article *model.Article, startID int) error {
|
func (db *rdbms) InsertArticle(ctx context.Context, article *model.Article, startID int) error {
|
||||||
// TODO id stting
|
if article.ID == 0 {
|
||||||
|
// auto generate id
|
||||||
|
var id int
|
||||||
|
err := db.Model(model.Article{}).Select("MAX(id)").Row().Scan(&id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if id < startID {
|
||||||
|
id = startID
|
||||||
|
} else {
|
||||||
|
id += 1
|
||||||
|
}
|
||||||
|
article.ID = id
|
||||||
|
}
|
||||||
return db.Create(article).Error
|
return db.Create(article).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +184,7 @@ func (db *rdbms) LoadArticleList(ctx context.Context, search SearchArticles) (mo
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
var articles model.SortedArticles
|
var articles model.SortedArticles
|
||||||
err = db.Limit(search.Limit).
|
err = gormDB.Limit(search.Limit).
|
||||||
Offset((search.Page - 1) * search.Limit).
|
Offset((search.Page - 1) * search.Limit).
|
||||||
Order("created_at DESC").Find(&articles).Error
|
Order("created_at DESC").Find(&articles).Error
|
||||||
return articles, int(count), err
|
return articles, int(count), err
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ type Account struct {
|
|||||||
PhoneN string `gorm:"column:phone_n;not null" bson:"phone_n"` // 手机号
|
PhoneN string `gorm:"column:phone_n;not null" bson:"phone_n"` // 手机号
|
||||||
Address string `gorm:"column:address;not null" bson:"address"` // 地址信息
|
Address string `gorm:"column:address;not null" bson:"address"` // 地址信息
|
||||||
|
|
||||||
LogoutAt time.Time `gorm:"column:logout_at;default:null" bson:"logout_at"` // 登出时间
|
LogoutAt time.Time `gorm:"column:logout_at;not null" bson:"logout_at"` // 登出时间
|
||||||
LoginIP string `gorm:"column:login_ip;default:null" bson:"login_ip"` // 最近登录IP
|
LoginIP string `gorm:"column:login_ip;not null" bson:"login_ip"` // 最近登录IP
|
||||||
LoginUA string `gorm:"column:login_ua;default:null" bson:"login_ua"` // 最近登录IP
|
LoginUA string `gorm:"column:login_ua;not null" bson:"login_ua"` // 最近登录IP
|
||||||
LoginAt time.Time `gorm:"column:login_at;default:now()" bson:"login_at"` // 最近登录时间
|
LoginAt time.Time `gorm:"column:login_at;default:now()" bson:"login_at"` // 最近登录时间
|
||||||
CreatedAt time.Time `gorm:"column:created_at;default:now()" bson:"created_at"` // 创建时间
|
CreatedAt time.Time `gorm:"column:created_at;default:now()" bson:"created_at"` // 创建时间
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,17 +11,17 @@ import (
|
|||||||
|
|
||||||
// Article 文章
|
// Article 文章
|
||||||
type Article struct {
|
type Article struct {
|
||||||
ID int `gorm:"column:id;primaryKey" bson:"id"` // 自增ID
|
ID int `gorm:"column:id;primaryKey" bson:"id"` // ID, store自行控制
|
||||||
Author string `gorm:"column:author;not null" bson:"author"` // 作者名
|
Author string `gorm:"column:author;not null" bson:"author"` // 作者名
|
||||||
Slug string `gorm:"column:slug;not null;uniqueIndex" bson:"slug"` // 文章缩略名
|
Slug string `gorm:"column:slug;not null;uniqueIndex" bson:"slug"` // 文章缩略名
|
||||||
Title string `gorm:"column:title;not null" bson:"title"` // 标题
|
Title string `gorm:"column:title;not null" bson:"title"` // 标题
|
||||||
Count int `gorm:"column:count;not null" bson:"count"` // 评论数量
|
Count int `gorm:"column:count;not null" bson:"count"` // 评论数量
|
||||||
Content string `gorm:"column:content;not null" bson:"content"` // markdown内容
|
Content string `gorm:"column:content;not null" bson:"content"` // markdown内容
|
||||||
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
||||||
Tags pq.StringArray `gorm:"column:tags;type:text[];not null" bson:"tags"` // tags
|
Tags pq.StringArray `gorm:"column:tags;type:text[]" bson:"tags"` // tags
|
||||||
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
||||||
|
|
||||||
DeletedAt time.Time `gorm:"column:deleted_at;default:null" bson:"deleted_at"` // 删除时间
|
DeletedAt time.Time `gorm:"column:deleted_at;not null" bson:"deleted_at"` // 删除时间
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;default:now()" bson:"updated_at"` // 更新时间
|
UpdatedAt time.Time `gorm:"column:updated_at;default:now()" bson:"updated_at"` // 更新时间
|
||||||
CreatedAt time.Time `gorm:"column:created_at;default:now()" bson:"created_at"` // 创建时间
|
CreatedAt time.Time `gorm:"column:created_at;default:now()" bson:"created_at"` // 创建时间
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user