datastore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dataSourceName string) (*sqlx.DB, error)

Open will open the database using the sqlite driver.

Types

type Listing

type Listing struct {
	DB *sqlx.DB
}

Listing will handle datastore interface for the subreddit listing data.

func (*Listing) Store

func (p *Listing) Store(ctx context.Context, listings []SubredditListing) error

Store will store the data listing from a subreddit

func (*Listing) SubredditPosts

func (p *Listing) SubredditPosts(ctx context.Context, subreddit string, limit int) ([]SubredditPost, error)

SubredditPosts will return the authors with the most posts for a given subreddit. The limit is optional and if none are provided, a default will be used.

func (*Listing) SubredditUps

func (p *Listing) SubredditUps(ctx context.Context, subreddit string, limit int) ([]SubredditListing, error)

SubredditUps will return the subreddit posts with the most ups (up votes). The limit is optional and if none are provided, a default will be used.

type Migration

type Migration struct {
	DB *sql.DB
}

Migration is to migrate the database to the table and index configuration.

func (*Migration) Apply

func (m *Migration) Apply(ctx context.Context) error

Apply will execute the queries to create tables and indexes.

type SubredditListing

type SubredditListing struct {
	Title               string  `db:"TITLE"`
	Downs               int     `db:"DOWNS"`
	UpvoteRatio         float64 `db:"UPVOTE_RATIO"`
	Ups                 int     `db:"UPS"`
	TotalAwardsReceived int     `db:"TOTAL_AWARDS"`
	Name                string  `db:"NAME"`
	Subreddit           string  `db:"SUBREDDIT"`
	ID                  string  `db:"ID"`
	Author              string  `db:"AUTHOR"`
	AuthorFullname      string  `db:"AUTHOR_FULLNAME"`
}

SubredditListing is the database model for the subreddit listing

type SubredditPost

type SubredditPost struct {
	Author         string `json:"author" db:"AUTHOR"`
	AuthorFullname string `json:"author_fullname" db:"AUTHOR_FULLNAME"`
	Posts          int    `json:"posts" db:"POSTS"`
}

SubredditPost is the database model for the author's subreddit posts

Jump to

Keyboard shortcuts

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