feat: for save

pull/376/head
textworld 1 year ago
parent 949ab17986
commit 97d95406ee

@ -56,7 +56,8 @@ func main() {
g.GenerateModel("tag"),
g.GenerateModel("theme_setting"),
g.GenerateModel("user", gen.FieldType("mfa_type", "consts.MFAType")),
g.GenerateModel("application_password"),
//g.GenerateModel("application_password"),
g.GenerateModel("scrap_page"),
)
// apply diy interfaces on structs or table models

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -17,7 +17,6 @@ import (
var (
Q = new(Query)
ApplicationPassword *applicationPassword
Attachment *attachment
Category *category
Comment *comment
@ -32,6 +31,7 @@ var (
Post *post
PostCategory *postCategory
PostTag *postTag
ScrapPage *scrapPage
Tag *tag
ThemeSetting *themeSetting
User *user
@ -39,7 +39,6 @@ var (
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
ApplicationPassword = &Q.ApplicationPassword
Attachment = &Q.Attachment
Category = &Q.Category
Comment = &Q.Comment
@ -54,6 +53,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
Post = &Q.Post
PostCategory = &Q.PostCategory
PostTag = &Q.PostTag
ScrapPage = &Q.ScrapPage
Tag = &Q.Tag
ThemeSetting = &Q.ThemeSetting
User = &Q.User
@ -62,7 +62,6 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
ApplicationPassword: newApplicationPassword(db, opts...),
Attachment: newAttachment(db, opts...),
Category: newCategory(db, opts...),
Comment: newComment(db, opts...),
@ -77,6 +76,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
Post: newPost(db, opts...),
PostCategory: newPostCategory(db, opts...),
PostTag: newPostTag(db, opts...),
ScrapPage: newScrapPage(db, opts...),
Tag: newTag(db, opts...),
ThemeSetting: newThemeSetting(db, opts...),
User: newUser(db, opts...),
@ -86,7 +86,6 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
type Query struct {
db *gorm.DB
ApplicationPassword applicationPassword
Attachment attachment
Category category
Comment comment
@ -101,6 +100,7 @@ type Query struct {
Post post
PostCategory postCategory
PostTag postTag
ScrapPage scrapPage
Tag tag
ThemeSetting themeSetting
User user
@ -111,7 +111,6 @@ func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
ApplicationPassword: q.ApplicationPassword.clone(db),
Attachment: q.Attachment.clone(db),
Category: q.Category.clone(db),
Comment: q.Comment.clone(db),
@ -126,6 +125,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
Post: q.Post.clone(db),
PostCategory: q.PostCategory.clone(db),
PostTag: q.PostTag.clone(db),
ScrapPage: q.ScrapPage.clone(db),
Tag: q.Tag.clone(db),
ThemeSetting: q.ThemeSetting.clone(db),
User: q.User.clone(db),
@ -143,7 +143,6 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
ApplicationPassword: q.ApplicationPassword.replaceDB(db),
Attachment: q.Attachment.replaceDB(db),
Category: q.Category.replaceDB(db),
Comment: q.Comment.replaceDB(db),
@ -158,6 +157,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
Post: q.Post.replaceDB(db),
PostCategory: q.PostCategory.replaceDB(db),
PostTag: q.PostTag.replaceDB(db),
ScrapPage: q.ScrapPage.replaceDB(db),
Tag: q.Tag.replaceDB(db),
ThemeSetting: q.ThemeSetting.replaceDB(db),
User: q.User.replaceDB(db),
@ -165,7 +165,6 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
}
type queryCtx struct {
ApplicationPassword *applicationPasswordDo
Attachment *attachmentDo
Category *categoryDo
Comment *commentDo
@ -180,6 +179,7 @@ type queryCtx struct {
Post *postDo
PostCategory *postCategoryDo
PostTag *postTagDo
ScrapPage *scrapPageDo
Tag *tagDo
ThemeSetting *themeSettingDo
User *userDo
@ -187,7 +187,6 @@ type queryCtx struct {
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
ApplicationPassword: q.ApplicationPassword.WithContext(ctx),
Attachment: q.Attachment.WithContext(ctx),
Category: q.Category.WithContext(ctx),
Comment: q.Comment.WithContext(ctx),
@ -202,6 +201,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
Post: q.Post.WithContext(ctx),
PostCategory: q.PostCategory.WithContext(ctx),
PostTag: q.PostTag.WithContext(ctx),
ScrapPage: q.ScrapPage.WithContext(ctx),
Tag: q.Tag.WithContext(ctx),
ThemeSetting: q.ThemeSetting.WithContext(ctx),
User: q.User.WithContext(ctx),

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -0,0 +1,361 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dal
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"
)
func newScrapPage(db *gorm.DB, opts ...gen.DOOption) scrapPage {
_scrapPage := scrapPage{}
_scrapPage.scrapPageDo.UseDB(db, opts...)
_scrapPage.scrapPageDo.UseModel(&entity.ScrapPage{})
tableName := _scrapPage.scrapPageDo.TableName()
_scrapPage.ALL = field.NewAsterisk(tableName)
_scrapPage.ID = field.NewInt32(tableName, "id")
_scrapPage.Title = field.NewString(tableName, "title")
_scrapPage.Md5 = field.NewString(tableName, "md5")
_scrapPage.URL = field.NewString(tableName, "url")
_scrapPage.Content = field.NewString(tableName, "content")
_scrapPage.Summary = field.NewString(tableName, "summary")
_scrapPage.CreateAt = field.NewInt64(tableName, "create_at")
_scrapPage.Domain = field.NewString(tableName, "domain")
_scrapPage.Resource = field.NewString(tableName, "resource")
_scrapPage.fillFieldMap()
return _scrapPage
}
type scrapPage struct {
scrapPageDo scrapPageDo
ALL field.Asterisk
ID field.Int32
Title field.String
Md5 field.String
URL field.String
Content field.String
Summary field.String
CreateAt field.Int64
Domain field.String
Resource field.String
fieldMap map[string]field.Expr
}
func (s scrapPage) Table(newTableName string) *scrapPage {
s.scrapPageDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s scrapPage) As(alias string) *scrapPage {
s.scrapPageDo.DO = *(s.scrapPageDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *scrapPage) updateTableName(table string) *scrapPage {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewInt32(table, "id")
s.Title = field.NewString(table, "title")
s.Md5 = field.NewString(table, "md5")
s.URL = field.NewString(table, "url")
s.Content = field.NewString(table, "content")
s.Summary = field.NewString(table, "summary")
s.CreateAt = field.NewInt64(table, "create_at")
s.Domain = field.NewString(table, "domain")
s.Resource = field.NewString(table, "resource")
s.fillFieldMap()
return s
}
func (s *scrapPage) WithContext(ctx context.Context) *scrapPageDo {
return s.scrapPageDo.WithContext(ctx)
}
func (s scrapPage) TableName() string { return s.scrapPageDo.TableName() }
func (s scrapPage) Alias() string { return s.scrapPageDo.Alias() }
func (s scrapPage) Columns(cols ...field.Expr) gen.Columns { return s.scrapPageDo.Columns(cols...) }
func (s *scrapPage) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *scrapPage) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 9)
s.fieldMap["id"] = s.ID
s.fieldMap["title"] = s.Title
s.fieldMap["md5"] = s.Md5
s.fieldMap["url"] = s.URL
s.fieldMap["content"] = s.Content
s.fieldMap["summary"] = s.Summary
s.fieldMap["create_at"] = s.CreateAt
s.fieldMap["domain"] = s.Domain
s.fieldMap["resource"] = s.Resource
}
func (s scrapPage) clone(db *gorm.DB) scrapPage {
s.scrapPageDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s scrapPage) replaceDB(db *gorm.DB) scrapPage {
s.scrapPageDo.ReplaceDB(db)
return s
}
type scrapPageDo struct{ gen.DO }
func (s scrapPageDo) Debug() *scrapPageDo {
return s.withDO(s.DO.Debug())
}
func (s scrapPageDo) WithContext(ctx context.Context) *scrapPageDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s scrapPageDo) ReadDB() *scrapPageDo {
return s.Clauses(dbresolver.Read)
}
func (s scrapPageDo) WriteDB() *scrapPageDo {
return s.Clauses(dbresolver.Write)
}
func (s scrapPageDo) Session(config *gorm.Session) *scrapPageDo {
return s.withDO(s.DO.Session(config))
}
func (s scrapPageDo) Clauses(conds ...clause.Expression) *scrapPageDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s scrapPageDo) Returning(value interface{}, columns ...string) *scrapPageDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s scrapPageDo) Not(conds ...gen.Condition) *scrapPageDo {
return s.withDO(s.DO.Not(conds...))
}
func (s scrapPageDo) Or(conds ...gen.Condition) *scrapPageDo {
return s.withDO(s.DO.Or(conds...))
}
func (s scrapPageDo) Select(conds ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Select(conds...))
}
func (s scrapPageDo) Where(conds ...gen.Condition) *scrapPageDo {
return s.withDO(s.DO.Where(conds...))
}
func (s scrapPageDo) Order(conds ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Order(conds...))
}
func (s scrapPageDo) Distinct(cols ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s scrapPageDo) Omit(cols ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s scrapPageDo) Join(table schema.Tabler, on ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s scrapPageDo) LeftJoin(table schema.Tabler, on ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s scrapPageDo) RightJoin(table schema.Tabler, on ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s scrapPageDo) Group(cols ...field.Expr) *scrapPageDo {
return s.withDO(s.DO.Group(cols...))
}
func (s scrapPageDo) Having(conds ...gen.Condition) *scrapPageDo {
return s.withDO(s.DO.Having(conds...))
}
func (s scrapPageDo) Limit(limit int) *scrapPageDo {
return s.withDO(s.DO.Limit(limit))
}
func (s scrapPageDo) Offset(offset int) *scrapPageDo {
return s.withDO(s.DO.Offset(offset))
}
func (s scrapPageDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *scrapPageDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s scrapPageDo) Unscoped() *scrapPageDo {
return s.withDO(s.DO.Unscoped())
}
func (s scrapPageDo) Create(values ...*entity.ScrapPage) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s scrapPageDo) CreateInBatches(values []*entity.ScrapPage, batchSize int) error {
return s.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (s scrapPageDo) Save(values ...*entity.ScrapPage) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s scrapPageDo) First() (*entity.ScrapPage, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*entity.ScrapPage), nil
}
}
func (s scrapPageDo) Take() (*entity.ScrapPage, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*entity.ScrapPage), nil
}
}
func (s scrapPageDo) Last() (*entity.ScrapPage, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*entity.ScrapPage), nil
}
}
func (s scrapPageDo) Find() ([]*entity.ScrapPage, error) {
result, err := s.DO.Find()
return result.([]*entity.ScrapPage), err
}
func (s scrapPageDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.ScrapPage, err error) {
buf := make([]*entity.ScrapPage, 0, batchSize)
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (s scrapPageDo) FindInBatches(result *[]*entity.ScrapPage, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s scrapPageDo) Attrs(attrs ...field.AssignExpr) *scrapPageDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s scrapPageDo) Assign(attrs ...field.AssignExpr) *scrapPageDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s scrapPageDo) Joins(fields ...field.RelationField) *scrapPageDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s scrapPageDo) Preload(fields ...field.RelationField) *scrapPageDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s scrapPageDo) FirstOrInit() (*entity.ScrapPage, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*entity.ScrapPage), nil
}
}
func (s scrapPageDo) FirstOrCreate() (*entity.ScrapPage, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*entity.ScrapPage), nil
}
}
func (s scrapPageDo) FindByPage(offset int, limit int) (result []*entity.ScrapPage, count int64, err error) {
result, err = s.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = s.Offset(-1).Limit(-1).Count()
return
}
func (s scrapPageDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s scrapPageDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s scrapPageDo) Delete(models ...*entity.ScrapPage) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *scrapPageDo) withDO(do gen.Dao) *scrapPageDo {
s.DO = *do.(*gen.DO)
return s
}

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -7,11 +7,13 @@ package dal
import (
"context"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"github.com/go-sonic/sonic/model/entity"

@ -0,0 +1,24 @@
package admin
import (
"github.com/gin-gonic/gin"
"github.com/go-sonic/sonic/service"
)
type ScrapPageHandler struct {
ScrapService service.ScrapService
}
func NewScrapPageHandler(scrapService service.ScrapService) *ScrapPageHandler {
return &ScrapPageHandler{
ScrapService: scrapService,
}
}
func (handler *ScrapPageHandler) QueryMd5List(ctx *gin.Context) (interface{}, error) {
return handler.ScrapService.QueryMd5List(ctx)
}
func (handler *ScrapPageHandler) Create(ctx *gin.Context) (interface{}, error) {
}

@ -14,19 +14,19 @@ const TableNameAttachment = "attachment"
// Attachment mapped from table <attachment>
type Attachment struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null;index:attachment_create_time,priority:1" json:"create_time"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
FileKey string `gorm:"column:file_key;type:varchar(2047);not null" json:"file_key"`
Height int32 `gorm:"column:height;type:int;not null" json:"height"`
MediaType string `gorm:"column:media_type;type:varchar(127);not null;index:attachment_media_type,priority:1" json:"media_type"`
Height int32 `gorm:"column:height;type:integer;not null" json:"height"`
MediaType string `gorm:"column:media_type;type:varchar(127);not null" json:"media_type"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`
Path string `gorm:"column:path;type:varchar(1023);not null" json:"path"`
Size int64 `gorm:"column:size;type:bigint;not null" json:"size"`
Suffix string `gorm:"column:suffix;type:varchar(50);not null" json:"suffix"`
ThumbPath string `gorm:"column:thumb_path;type:varchar(1023);not null" json:"thumb_path"`
Type consts.AttachmentType `gorm:"column:type;type:bigint;not null" json:"type"`
Width int32 `gorm:"column:width;type:int;not null" json:"width"`
Width int32 `gorm:"column:width;type:integer;not null" json:"width"`
}
// TableName Attachment's table name

@ -14,17 +14,17 @@ const TableNameCategory = "category"
// Category mapped from table <category>
type Category struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Description string `gorm:"column:description;type:varchar(100);not null" json:"description"`
Type consts.CategoryType `gorm:"column:type;type:tinyint;not null" json:"type"`
Name string `gorm:"column:name;type:varchar(255);not null;index:category_name,priority:1" json:"name"`
ParentID int32 `gorm:"column:parent_id;type:int;not null;index:category_parent_id,priority:1" json:"parent_id"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`
ParentID int32 `gorm:"column:parent_id;type:integer;not null" json:"parent_id"`
Password string `gorm:"column:password;type:varchar(255);not null" json:"password"`
Slug string `gorm:"column:slug;type:varchar(255);not null;uniqueIndex:uniq_category_slug,priority:1" json:"slug"`
Slug string `gorm:"column:slug;type:varchar(255);not null" json:"slug"`
Thumbnail string `gorm:"column:thumbnail;type:varchar(1023);not null" json:"thumbnail"`
Priority int32 `gorm:"column:priority;type:int;not null" json:"priority"`
Priority int32 `gorm:"column:priority;type:integer;not null" json:"priority"`
}
// TableName Category's table name

@ -14,11 +14,11 @@ const TableNameComment = "comment"
// Comment mapped from table <comment>
type Comment struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
Type consts.CommentType `gorm:"column:type;type:bigint;not null;index:comment_type_status,priority:1" json:"type"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.CommentType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
AllowNotification bool `gorm:"column:allow_notification;type:tinyint(1);not null;default:1" json:"allow_notification"`
AllowNotification bool `gorm:"column:allow_notification;type:tinyint(1);not null;default:true" json:"allow_notification"`
Author string `gorm:"column:author;type:varchar(50);not null" json:"author"`
AuthorURL string `gorm:"column:author_url;type:varchar(511);not null" json:"author_url"`
Content string `gorm:"column:content;type:varchar(1023);not null" json:"content"`
@ -26,10 +26,10 @@ type Comment struct {
GravatarMd5 string `gorm:"column:gravatar_md5;type:varchar(127);not null" json:"gravatar_md5"`
IPAddress string `gorm:"column:ip_address;type:varchar(127);not null" json:"ip_address"`
IsAdmin bool `gorm:"column:is_admin;type:tinyint(1);not null" json:"is_admin"`
ParentID int32 `gorm:"column:parent_id;type:int;not null;index:comment_parent_id,priority:1" json:"parent_id"`
PostID int32 `gorm:"column:post_id;type:int;not null;index:comment_post_id,priority:1" json:"post_id"`
Status consts.CommentStatus `gorm:"column:status;type:bigint;not null;index:comment_type_status,priority:2" json:"status"`
TopPriority int32 `gorm:"column:top_priority;type:int;not null" json:"top_priority"`
ParentID int32 `gorm:"column:parent_id;type:integer;not null" json:"parent_id"`
PostID int32 `gorm:"column:post_id;type:integer;not null" json:"post_id"`
Status consts.CommentStatus `gorm:"column:status;type:bigint;not null" json:"status"`
TopPriority int32 `gorm:"column:top_priority;type:integer;not null" json:"top_priority"`
UserAgent string `gorm:"column:user_agent;type:varchar(511);not null" json:"user_agent"`
}

@ -12,7 +12,7 @@ const TableNameCommentBlack = "comment_black"
// CommentBlack mapped from table <comment_black>
type CommentBlack struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
BanTime time.Time `gorm:"column:ban_time;type:datetime;not null" json:"ban_time"`

@ -14,7 +14,7 @@ const TableNameJournal = "journal"
// Journal mapped from table <journal>
type Journal struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Content string `gorm:"column:content;type:text;not null" json:"content"`

@ -12,13 +12,13 @@ const TableNameLink = "link"
// Link mapped from table <link>
type Link struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Description string `gorm:"column:description;type:varchar(255);not null" json:"description"`
Logo string `gorm:"column:logo;type:varchar(1023);not null" json:"logo"`
Name string `gorm:"column:name;type:varchar(255);not null;index:link_name,priority:1" json:"name"`
Priority int32 `gorm:"column:priority;type:int;not null" json:"priority"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`
Priority int32 `gorm:"column:priority;type:integer;not null" json:"priority"`
Team string `gorm:"column:team;type:varchar(255);not null" json:"team"`
URL string `gorm:"column:url;type:varchar(1023);not null" json:"url"`
}

@ -14,8 +14,8 @@ const TableNameLog = "log"
// Log mapped from table <log>
type Log struct {
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null;index:log_create_time,priority:1" json:"create_time"`
ID *int64 `gorm:"column:id;type:bigint;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Content string `gorm:"column:content;type:varchar(1023);not null" json:"content"`
IPAddress string `gorm:"column:ip_address;type:varchar(127);not null" json:"ip_address"`

@ -12,13 +12,13 @@ const TableNameMenu = "menu"
// Menu mapped from table <menu>
type Menu struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Icon string `gorm:"column:icon;type:varchar(50);not null" json:"icon"`
Name string `gorm:"column:name;type:varchar(50);not null;index:menu_name,priority:1" json:"name"`
ParentID int32 `gorm:"column:parent_id;type:int;not null;index:menu_parent_id,priority:1" json:"parent_id"`
Priority int32 `gorm:"column:priority;type:int;not null" json:"priority"`
Name string `gorm:"column:name;type:varchar(50);not null" json:"name"`
ParentID int32 `gorm:"column:parent_id;type:integer;not null" json:"parent_id"`
Priority int32 `gorm:"column:priority;type:integer;not null" json:"priority"`
Target string `gorm:"column:target;type:varchar(20);not null;default:_self" json:"target"`
Team string `gorm:"column:team;type:varchar(255);not null" json:"team"`
URL string `gorm:"column:url;type:varchar(1023);not null" json:"url"`

@ -14,12 +14,12 @@ const TableNameMeta = "meta"
// Meta mapped from table <meta>
type Meta struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.MetaType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
MetaKey string `gorm:"column:meta_key;type:varchar(255);not null" json:"meta_key"`
PostID int32 `gorm:"column:post_id;type:int;not null" json:"post_id"`
PostID int32 `gorm:"column:post_id;type:integer;not null" json:"post_id"`
MetaValue string `gorm:"column:meta_value;type:varchar(1023);not null" json:"meta_value"`
}

@ -14,7 +14,7 @@ const TableNameOption = "option"
// Option mapped from table <option>
type Option struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
OptionKey string `gorm:"column:option_key;type:varchar(100);not null" json:"option_key"`

@ -12,14 +12,14 @@ const TableNamePhoto = "photo"
// Photo mapped from table <photo>
type Photo struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null;index:photo_create_time,priority:1" json:"create_time"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Description string `gorm:"column:description;type:varchar(255);not null" json:"description"`
Location string `gorm:"column:location;type:varchar(255);not null" json:"location"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`
TakeTime *time.Time `gorm:"column:take_time;type:datetime" json:"take_time"`
Team string `gorm:"column:team;type:varchar(255);not null;index:photo_team,priority:1" json:"team"`
Team string `gorm:"column:team;type:varchar(255);not null" json:"team"`
Thumbnail string `gorm:"column:thumbnail;type:varchar(1023);not null" json:"thumbnail"`
URL string `gorm:"column:url;type:varchar(1023);not null" json:"url"`
Likes int64 `gorm:"column:likes;type:bigint;not null" json:"likes"`

@ -14,9 +14,9 @@ const TableNamePost = "post"
// Post mapped from table <post>
type Post struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
Type consts.PostType `gorm:"column:type;type:bigint;not null;index:post_type_status,priority:1" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null;index:post_create_time,priority:1" json:"create_time"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.PostType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
DisallowComment bool `gorm:"column:disallow_comment;type:tinyint(1);not null" json:"disallow_comment"`
EditTime *time.Time `gorm:"column:edit_time;type:datetime" json:"edit_time"`
@ -27,13 +27,13 @@ type Post struct {
MetaKeywords string `gorm:"column:meta_keywords;type:varchar(511);not null" json:"meta_keywords"`
OriginalContent string `gorm:"column:original_content;type:longtext;not null" json:"original_content"`
Password string `gorm:"column:password;type:varchar(255);not null" json:"password"`
Slug string `gorm:"column:slug;type:varchar(255);not null;uniqueIndex:uniq_post_slug,priority:1" json:"slug"`
Status consts.PostStatus `gorm:"column:status;type:bigint;not null;index:post_type_status,priority:2;default:1" json:"status"`
Slug string `gorm:"column:slug;type:varchar(255);not null" json:"slug"`
Status consts.PostStatus `gorm:"column:status;type:bigint;not null;default:1" json:"status"`
Summary string `gorm:"column:summary;type:longtext;not null" json:"summary"`
Template string `gorm:"column:template;type:varchar(255);not null" json:"template"`
Thumbnail string `gorm:"column:thumbnail;type:varchar(1023);not null" json:"thumbnail"`
Title string `gorm:"column:title;type:varchar(255);not null" json:"title"`
TopPriority int32 `gorm:"column:top_priority;type:int;not null" json:"top_priority"`
TopPriority int32 `gorm:"column:top_priority;type:integer;not null" json:"top_priority"`
Visits int64 `gorm:"column:visits;type:bigint;not null" json:"visits"`
WordCount int64 `gorm:"column:word_count;type:bigint;not null" json:"word_count"`
}

@ -12,11 +12,11 @@ const TableNamePostCategory = "post_category"
// PostCategory mapped from table <post_category>
type PostCategory struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
CategoryID int32 `gorm:"column:category_id;type:int;not null;index:post_category_category_id,priority:1" json:"category_id"`
PostID int32 `gorm:"column:post_id;type:int;not null;index:post_category_post_id,priority:1" json:"post_id"`
CategoryID int32 `gorm:"column:category_id;type:integer;not null" json:"category_id"`
PostID int32 `gorm:"column:post_id;type:integer;not null" json:"post_id"`
}
// TableName PostCategory's table name

@ -12,11 +12,11 @@ const TableNamePostTag = "post_tag"
// PostTag mapped from table <post_tag>
type PostTag struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
PostID int32 `gorm:"column:post_id;type:int;not null;index:post_tag_post_id,priority:1" json:"post_id"`
TagID int32 `gorm:"column:tag_id;type:int;not null;index:post_tag_tag_id,priority:1" json:"tag_id"`
PostID int32 `gorm:"column:post_id;type:integer;not null" json:"post_id"`
TagID int32 `gorm:"column:tag_id;type:integer;not null" json:"tag_id"`
}
// TableName PostTag's table name

@ -0,0 +1,25 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package entity
const TableNameScrapPage = "scrap_page"
// ScrapPage mapped from table <scrap_page>
type ScrapPage struct {
ID *int32 `gorm:"column:id;type:INTEGER" json:"id"`
Title *string `gorm:"column:title;type:varchar(128)" json:"title"`
Md5 *string `gorm:"column:md5;type:varchar(128)" json:"md5"`
URL *string `gorm:"column:url;type:text" json:"url"`
Content *string `gorm:"column:content;type:text" json:"content"`
Summary *string `gorm:"column:summary;type:text" json:"summary"`
CreateAt *int64 `gorm:"column:create_at;type:bigint" json:"create_at"`
Domain *string `gorm:"column:domain;type:varchar(128)" json:"domain"`
Resource *string `gorm:"column:resource;type:text" json:"resource"`
}
// TableName ScrapPage's table name
func (*ScrapPage) TableName() string {
return TableNameScrapPage
}

@ -12,11 +12,11 @@ const TableNameTag = "tag"
// Tag mapped from table <tag>
type Tag struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Name string `gorm:"column:name;type:varchar(255);not null;index:tag_name,priority:1" json:"name"`
Slug string `gorm:"column:slug;type:varchar(50);not null;uniqueIndex:uniq_tag_slug,priority:1" json:"slug"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`
Slug string `gorm:"column:slug;type:varchar(50);not null" json:"slug"`
Thumbnail string `gorm:"column:thumbnail;type:varchar(1023);not null" json:"thumbnail"`
Color string `gorm:"column:color;type:varchar(25);not null" json:"color"`
}

@ -12,11 +12,11 @@ const TableNameThemeSetting = "theme_setting"
// ThemeSetting mapped from table <theme_setting>
type ThemeSetting struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
SettingKey string `gorm:"column:setting_key;type:varchar(255);not null;index:theme_setting_setting_key,priority:1" json:"setting_key"`
ThemeID string `gorm:"column:theme_id;type:varchar(255);not null;index:theme_setting_theme_id,priority:1" json:"theme_id"`
SettingKey string `gorm:"column:setting_key;type:varchar(255);not null" json:"setting_key"`
ThemeID string `gorm:"column:theme_id;type:varchar(255);not null" json:"theme_id"`
SettingValue string `gorm:"column:setting_value;type:longtext;not null" json:"setting_value"`
}

@ -14,7 +14,7 @@ const TableNameUser = "user"
// User mapped from table <user>
type User struct {
ID int32 `gorm:"column:id;type:int;primaryKey;autoIncrement:true" json:"id"`
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Avatar string `gorm:"column:avatar;type:varchar(1023);not null" json:"avatar"`

@ -0,0 +1,11 @@
package param
type ScrapPage struct {
Title string `json:"title"`
Summary string `json:"summary"`
URL string `json:"url"`
OriginURL string `json:"origin_url"`
AddAt int64 `json:"add_at"`
Md5 string `json:"md_5"`
Content string `json:"content"`
}

@ -0,0 +1,49 @@
package impl
import (
"context"
"github.com/go-sonic/sonic/dal"
"github.com/go-sonic/sonic/model/entity"
"github.com/go-sonic/sonic/model/param"
"github.com/go-sonic/sonic/service"
)
type scrapServiceImpl struct{}
func NewScrapService() service.ScrapService {
return &scrapServiceImpl{}
}
func (impl *scrapServiceImpl) QueryMd5List(ctx context.Context) ([]string, error) {
scrapPageDAL := dal.GetQueryByCtx(ctx).ScrapPage
entities, err := scrapPageDAL.WithContext(ctx).Select(dal.ScrapPage.Md5).Find()
if err != nil {
return nil, WrapDBErr(err)
}
md5List := make([]string, len(entities))
for _, v := range entities {
md5List = append(md5List, *v.Md5)
}
return md5List, nil
}
func (impl *scrapServiceImpl) Create(ctx context.Context, pageParam *param.ScrapPage) error {
}
func convertToModel(pageParam *param.ScrapPage) *entity.ScrapPage {
pageModel := &entity.ScrapPage{
ID: nil,
Title: pageParam.Title,
Md5: pageParam.Md5,
URL: pageParam.URL,
Content: pageParam.Content,
Summary: pageParam.Summary,
CreateAt: ,
Domain: nil,
Resource: nil,
}
}

@ -0,0 +1,7 @@
package service
import "context"
type ScrapService interface {
QueryMd5List(ctx context.Context) ([]string, error)
}
Loading…
Cancel
Save