models

package
v0.0.0-...-49c1208 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 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"`
}

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
}

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