pg

package
v0.0.0-...-9b45353 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

A DB is responsible for all interactions with postgres

func NewDB

func NewDB(dsn string, autoExplain bool) (*DB, error)

NewDB returns a new database

func (*DB) ActivateLoginToken

func (db *DB) ActivateLoginToken(ctx context.Context, token string) (string, error)

ActivateLoginToken activates the given LoginToken and returns the user the token was for

func (*DB) AddFeed

func (db *DB) AddFeed(ctx context.Context, sessionKey, folderID, title, plugin, feedURL string, initialConfig *discollect.Config) (string, error)

AddFeed adds the given URL to the users default folder and links it across feed_folder

func (*DB) AddFolder

func (db *DB) AddFolder(ctx context.Context, sessionKey, name string) (string, error)

AddFolder creates a new folder

func (*DB) CheckIfFeedExists

func (db *DB) CheckIfFeedExists(ctx context.Context, sessionKey, folderID, plugin, url string) (*hydrocarbon.Feed, bool, error)

CheckIfFeedExists checks if a given feed exists in the DB already, and if it does, adds it to the folder specified

func (*DB) Close

func (db *DB) Close() error

Close implements io.Closer for pg.DB

func (*DB) CreateLoginToken

func (db *DB) CreateLoginToken(ctx context.Context, userID, userAgent, ip string) (string, error)

CreateLoginToken creates a new one-time-use login token

func (*DB) CreateOrGetUser

func (db *DB) CreateOrGetUser(ctx context.Context, email string) (string, bool, error)

CreateOrGetUser creates a new user and returns the users ID

func (*DB) CreateSession

func (db *DB) CreateSession(ctx context.Context, userID, userAgent, ip string) (email string, key string, err error)

CreateSession creates a new session for the user ID and returns the session key

func (*DB) DeactivateSession

func (db *DB) DeactivateSession(ctx context.Context, key string) error

DeactivateSession invalidates the current session

func (*DB) EndScrape

func (db *DB) EndScrape(ctx context.Context, id uuid.UUID, datums, retries, tasks int) error

EndScrape marks a scrape as SUCCESS and records the number of datums and tasks returned

func (*DB) ErrorScrape

func (db *DB) ErrorScrape(ctx context.Context, id uuid.UUID, err error) error

ErrorScrape marks a scrape as ERRORED and adds the error to its list

func (*DB) FindMissingSchedules

func (db *DB) FindMissingSchedules(ctx context.Context, limit int) ([]*discollect.ScheduleRequest, error)

FindMissingSchedules pulls info to ask a plugin to create a schedule

func (*DB) GetFeedPosts

func (db *DB) GetFeedPosts(ctx context.Context, sessionKey, feedID string, limit, offset int) (*hydrocarbon.Feed, error)

GetFeedPosts returns a single feed

func (*DB) GetFoldersWithFeeds

func (db *DB) GetFoldersWithFeeds(ctx context.Context, sessionKey string) ([]*hydrocarbon.Folder, error)

GetFolders returns all of the folders for a user - if there are none it creates a default folder

func (*DB) GetPost

func (db *DB) GetPost(ctx context.Context, sessionKey, postID string) (*hydrocarbon.Post, error)

func (*DB) InsertSchedule

func (db *DB) InsertSchedule(ctx context.Context, sr *discollect.ScheduleRequest, ss []*discollect.ScrapeSchedule) error

InsertSchedule inserts all the schedules

func (*DB) ListScrapes

func (db *DB) ListScrapes(ctx context.Context, stateFilter string, limit, offset int) ([]*discollect.Scrape, error)

ListScrapes is used to list and filter scrapes, for both session resumption and UI purposes

func (*DB) ListSessions

func (db *DB) ListSessions(ctx context.Context, key string, page int) ([]*hydrocarbon.Session, error)

ListSessions lists all sessions a user has

func (*DB) MarkRead

func (db *DB) MarkRead(ctx context.Context, sessionKey, postID string) error

func (*DB) RemoveFeed

func (db *DB) RemoveFeed(ctx context.Context, sessionKey, folderID, feedID string) error

RemoveFeed removes the given feed ID from the user

func (*DB) SetStripeIDs

func (db *DB) SetStripeIDs(ctx context.Context, userID, customerID, subID string) error

SetStripeIDs sets a users stripe IDs

func (*DB) StartScrapes

func (db *DB) StartScrapes(ctx context.Context, limit int) (ss []*discollect.Scrape, err error)

StartScrapes selects a subset of scrapes that should currently be running, but are not yet.

func (*DB) VerifyKey

func (db *DB) VerifyKey(ctx context.Context, key string) error

VerifyKey checks that the session exists in the database

func (*DB) Write

func (db *DB) Write(ctx context.Context, scrapeID uuid.UUID, f interface{}) error

Write saves off the post to the db

Jump to

Keyboard shortcuts

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