-
Notifications
You must be signed in to change notification settings - Fork 7
/
feed_item.go
68 lines (61 loc) · 1.7 KB
/
feed_item.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package schema
import (
"time"
"github.com/tuihub/librarian/internal/model"
"github.com/tuihub/librarian/internal/model/modelfeed"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// FeedItem holds the schema definition for the FeedItem entity.
type FeedItem struct {
ent.Schema
}
// Fields of the FeedItem.
func (FeedItem) Fields() []ent.Field {
return []ent.Field{
defaultPrimaryKey(),
field.Int64("feed_id").
Immutable().
GoType(model.InternalID(0)),
field.String("title").Optional(),
field.JSON("authors", []*modelfeed.Person{}).Optional(),
field.String("description").Optional(),
field.String("content").Optional(),
field.String("guid").Immutable(),
field.String("link").Optional(),
field.JSON("image", new(modelfeed.Image)).Optional(),
field.String("published").Optional(),
field.Time("published_parsed"),
field.String("updated").Optional(),
field.Time("updated_parsed").Optional().Nillable(),
field.JSON("enclosures", []*modelfeed.Enclosure{}).Optional(),
field.String("publish_platform").Optional(),
field.Int64("read_count").Default(0),
field.String("digest_description").Optional(),
field.JSON("digest_images", []*modelfeed.Image{}).Optional(),
field.Time("updated_at").
Default(time.Now).UpdateDefault(time.Now),
field.Time("created_at").
Default(time.Now),
}
}
func (FeedItem) Indexes() []ent.Index {
return []ent.Index{
index.Fields("feed_id", "guid").
Unique(),
index.Fields("publish_platform"),
}
}
// Edges of the FeedItem.
func (FeedItem) Edges() []ent.Edge {
return []ent.Edge{
edge.From("feed", Feed.Type).
Ref("item").
Field("feed_id").
Unique().
Immutable().
Required(),
}
}