models

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserTwitterSource   = "user"
	SearchTwitterSource = "search"
)

Variables

This section is empty.

Functions

func GetAllModels

func GetAllModels() []interface{}

GetAllModels returns all GORM models, that is, a slice of pointers to zero-valued structs.

func MigrateDB

func MigrateDB(db *gorm.DB) error

MigrateDB performs an automatic migration of all GORM models.

func OpenDB

func OpenDB(dsn string, logger zerolog.Logger) (*gorm.DB, error)

OpenDB initializes a database session.

Types

type Feed

type Feed struct {
	Model
	DeletedAt gorm.DeletedAt `gorm:"index"`
	// URL is the unique URL of the feed.
	URL string `gorm:"not null;uniqueIndex"`
	// LastRetrievedAt is the date and time when this feed was last visited
	// to successfully retrieve and process its content.
	LastRetrievedAt sql.NullTime `gorm:"index"`
	FailuresCount   int          `gorm:"not null"`
	// FeedItems is the has-many relation with FeedItem models.
	FeedItems []FeedItem `gorm:"constraint:OnDelete:CASCADE"`
}

Feed is a model representing an RSS or Atom feed.

func FindFeed

func FindFeed(db *gorm.DB, id uint) (*Feed, error)

FindFeed returns the feed by its id. It returns nil if the item is not found.

type FeedItem

type FeedItem struct {
	Model
	// FeedID is the association to the Feed this item belongs to.
	FeedID uint `gorm:"not null"`
	// WebResourceID allows the has-one relation with a WebResource.
	WebResourceID uint `gorm:"not null;uniqueIndex;constraint:OnDelete:CASCADE"`
	Title         string
	Description   sql.NullString
	Content       sql.NullString
	Language      string `gorm:"not null"`
	PublishedAt   sql.NullTime
}

FeedItem extends a WebResource which is the item of a Feed.

type GDELTEvent

type GDELTEvent struct {
	Model
	// WebResourceID allows the has-one relation with a WebResource.
	WebResourceID uint `gorm:"not null;uniqueIndex;constraint:OnDelete:CASCADE"`
	// GlobalEventID is the globally unique identifier in GDELT master dataset.
	GlobalEventID uint `gorm:"not null;uniqueIndex"`
	// DateAdded is the date the event was added to the master database.
	DateAdded time.Time `gorm:"not null"`
	// LocationType specifies the geographic resolution of the match type.
	LocationType sql.NullString
	// LocationName is the full human-readable name of the matched location.
	LocationName sql.NullString
	// CountryCode is the ISO 3166-1 alpha2 country code for the location.
	CountryCode sql.NullString
	// Coordinates provides the centroid Longitude (X) and Latitude (Y) of the landmark for mapping.
	Coordinates pgtype.Point `gorm:"type:point"`
	// EventCategories provides one or more CAMEO event codes at different
	// levels.
	EventCategories pgtype.VarcharArray `gorm:"type:varchar(4)[];not null"`
}

GDELTEvent represents a GDELT Event, and it extends a WebResource which contains the URL of the first recognized news report for this event.

type Model

type Model struct {
	ID        uint      `gorm:"primaryKey"`
	CreatedAt time.Time `gorm:"not null"`
	UpdatedAt time.Time `gorm:"not null"`
}

Model is the basic struct embedded into all GORM models.

type Payload

type Payload map[string]interface{}

Payload is a generic payload for a WebArticle.

func (*Payload) Get

func (p *Payload) Get(key string, nestedKeys ...string) (interface{}, bool)

Get gets a value from the given key. If multiple keys are given, the method attempts to match a series of nested maps. If a value is not found, or the search in nested maps fails, the returned value is nil, and the flag is false.

func (*Payload) GetString

func (p *Payload) GetString(key string, nestedKeys ...string) (string, bool)

GetString gets the value with Get and enforces it to be a string. If no value is found, or the value is not a string, the method returns an empty string and a false flag.

func (*Payload) Scan

func (p *Payload) Scan(src interface{}) error

func (*Payload) Set

func (p *Payload) Set(key string, value interface{})

Set sets a key/value pair in the Payload. It initializes the payload, if necessary. If a value already exists for the given key, it is overwritten.

func (*Payload) Value

func (p *Payload) Value() (driver.Value, error)

type Tweet added in v0.3.0

type Tweet struct {
	Model
	// TwitterSourceID is the association to the TwitterSource this item belongs to.
	TwitterSourceID uint `gorm:"not null"`
	// WebResourceID allows the has-one relation with a WebResource.
	WebResourceID uint `gorm:"not null;uniqueIndex;constraint:OnDelete:CASCADE"`

	UpstreamID  string    `gorm:"not null;uniqueIndex"`
	Text        string    `gorm:"not null"`
	PublishedAt time.Time `gorm:"not null"`
	Username    string    `gorm:"not null;index"`
	UserID      string    `gorm:"not null;index"`
}

Tweet extends a WebResource which is the item of a TwitterSource.

type TwitterSource added in v0.3.0

type TwitterSource struct {
	Model
	// Type is either "user" or "search".
	Type string `gorm:"not null;index:type_value,unique"`
	// Value is a username or a search term, depending on the Type.
	Value string `gorm:"not null;index:type_value,unique"`
	// LastRetrievedAt is the date and time when this Twitter source was last
	// visited to successfully retrieve and process its content.
	LastRetrievedAt sql.NullTime `gorm:"index"`
	// Tweet is the has-many relation with Tweet models.
	Tweets []Tweet `gorm:"constraint:OnDelete:CASCADE"`
}

TwitterSource is a model representing a Twitter user or search phrase.

func FindTwitterSource added in v0.3.0

func FindTwitterSource(db *gorm.DB, id uint) (*TwitterSource, error)

FindTwitterSource returns a TwitterSource by its id. It returns nil if the item is not found.

type WebArticle

type WebArticle struct {
	Model
	// WebResourceID allows the has-one relation with a WebResource.
	WebResourceID         uint   `gorm:"not null;uniqueIndex;constraint:OnDelete:CASCADE"`
	Title                 string `gorm:"not null;index"`
	TitleUnmodified       string
	CleanedText           string
	CanonicalLink         string
	TopImage              string
	FinalURL              string
	ScrapedPublishDate    sql.NullTime
	Language              string    `gorm:"not null"`
	PublishDate           time.Time `gorm:"not null"`
	RelatedToWebArticleID *uint
	RelatedToWebArticle   *WebArticle
	RelatedScore          sql.NullFloat64
	Payload               Payload      `gorm:"type:JSONB"`
	Vector                pgtype.Bytea `gorm:"type:bytea"`
}

WebArticle represents the scraped content of a WebResource.

func FindWebArticle

func FindWebArticle(tx *gorm.DB, id uint) (*WebArticle, error)

FindWebArticle returns the web article by its id. It returns nil if the item is not found.

type WebResource

type WebResource struct {
	Model
	// URL is the unique URL of the web resource.
	URL string `gorm:"not null;uniqueIndex"`
	// WebArticle represents the scraped content of this WebResource.
	WebArticle WebArticle
	// FeedItem allows the has-one relation with a models.FeedItem.
	FeedItem FeedItem
	// GDELTEvent allows the has-one relation with a models.GDELTEvent.
	GDELTEvent GDELTEvent
	// Tweet allows the has-one relation with a models.Tweet.
	Tweet Tweet
}

WebResource represents a web resource, usually a web page, accessible via a URL.

func FindWebResourceByURL

func FindWebResourceByURL(tx *gorm.DB, url string) (*WebResource, error)

FindWebResourceByURL returns the web resource associated to a url. It returns nil if the item is not found.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL