Documentation
¶
Index ¶
- Constants
- Variables
- func GetOrderByQuery(f *CommonFilters) (string, error)
- func PageDelete(id int, query string, db *sql.DB) error
- func PageGetLatestPageCount(ctx context.Context, baseurl *url.URL, markedURL string, cutoffDate time.Time, ...) (int, error)
- func PageInsert(m *Page, query string, db *sql.DB) error
- func URLDelete(id int, query string, db *sql.DB) error
- func URLInsert(m *URL, query string, db *sql.DB) error
- func URLUpdate(m *URL, query string, db *sql.DB) error
- func ValidOrderBy(orderBy string, validFields []string) bool
- func ValidateCommonFilters(v *internal.Validator, f CommonFilters)
- func ValidateURL(v *internal.Validator, u *URL)
- type CommonFilters
- type Models
- type Page
- type PageContent
- type PageModel
- type URL
- func NewURL(url string, lastChecked, lastSaved time.Time, isMonitored bool) *URL
- func URLGetAll(uf URLFilter, cf CommonFilters, query string, db *sql.DB, ...) ([]*URL, error)
- func URLGetById(id int, query string, db *sql.DB) (*URL, error)
- func URLGetByURL(urlStr string, query string, db *sql.DB) (*URL, error)
- type URLFilter
- type URLModel
Constants ¶
const ( QuerySelectPage = "SELECT id, url_id, added_at, content FROM pages" QueryGetPageById = QuerySelectPage + " WHERE id = __ARG__" QueryGetAllPageByURL = "SELECT id, url_id, added_at FROM pages WHERE url_id = __ARG__" QueryInsertPage = `INSERT INTO pages (url_id, content) VALUES (__ARG__, __ARG__) RETURNING id, added_at` QueryDeletePage = `DELETE from pages WHERE id = __ARG__` QueryGetLatestPagesCount = `` /* 352-byte string literal not displayed */ QueryGetLatestPagesPaginated = `` /* 397-byte string literal not displayed */ )
Queries related to pages table
const ( QuerySelectURL = "SELECT id, url, first_encountered, last_checked, last_saved, is_monitored, is_alive, version FROM urls " QueryGetURLById = QuerySelectURL + "WHERE id = __ARG__" QueryGetURLByURL = QuerySelectURL + "WHERE url = __ARG__" QueryInsertURL = `` /* 151-byte string literal not displayed */ QueryUpdateURL = `` /* 191-byte string literal not displayed */ QueryDeleteURL = `DELETE from urls WHERE id = __ARG__` QueryGetAllURL = QuerySelectURL + "WHERE url LIKE __ARG__ " QueryGetAllMonitoredURL = QuerySelectURL + ` WHERE is_monitored = true AND is_alive = true ORDER BY __ARG__` )
Queries related to urls table
const QueryArgStr = "__ARG__"
QueryArgStr is the substring used in sql queries as placeholder for query arguments
Variables ¶
var ( ErrRecordNotFound = errors.New("models: record not found") ErrNullURL = errors.New("models: url cannot be empty or null") ErrEditConflict = errors.New("models: edit conflict") ErrInvalidOrderBy = errors.New("models: invalid order by") )
var DefaultDBTimeout = 5 * time.Second
DefaultDBTimeout for sql queries
var PageColumns = []string{"id", "url_id", "added_at", "content"}
var URLColumns = []string{
"id", "url", "first_encountered", "last_checked",
"last_saved", "is_monitored", "is_alive", "version",
}
Functions ¶
func GetOrderByQuery ¶ added in v0.9.0
func GetOrderByQuery(f *CommonFilters) (string, error)
GetOrderByQuery returns ORDER BY sub query as per CommonFilters
func PageDelete ¶
PageDelete delete page row by id
func PageGetLatestPageCount ¶
func PageGetLatestPageCount( ctx context.Context, baseurl *url.URL, markedURL string, cutoffDate time.Time, query string, db *sql.DB, ) (int, error)
PageGetLatestPageCount returns count of the latest pages filtered by baseurl, markedURL and by cutoff date
func PageInsert ¶
PageInsert writes a page to pages table
func URLUpdate ¶
URLUpdate updates a url with provided values. Optimistic locking enabled: if version change detected return ErrEditConflict
func ValidOrderBy ¶
ValidOrderBy tells if the orderBy is present in validFields
func ValidateCommonFilters ¶ added in v0.9.0
func ValidateCommonFilters(v *internal.Validator, f CommonFilters)
func ValidateURL ¶ added in v0.9.0
Types ¶
type CommonFilters ¶ added in v0.9.0
func (CommonFilters) Limit ¶ added in v0.9.0
func (c CommonFilters) Limit() int
func (CommonFilters) Offset ¶ added in v0.9.0
func (c CommonFilters) Offset() int
type Page ¶
type Page struct {
ID uint `json:"id"`
URLID uint `json:"url_id"`
AddedAt time.Time `json:"added_at"`
Content string `json:"content,omitempty"`
}
Page type holds the information of URL content saved in model
type PageContent ¶
type PageContent struct {
URL string
AddedAt time.Time
Content string
// contains filtered or unexported fields
}
PageContent type contains feilds required for saving page contents to disk
func PageGetLatestPagesPaginated ¶
func PageGetLatestPagesPaginated( ctx context.Context, baseurl *url.URL, markedURL string, cutoffDate time.Time, pageNum int, pageSize int, query string, db *sql.DB, ) ([]*PageContent, error)
PageGetLatestPagesPaginated returns PageContent of the latest pages filtered by baseurl, markedURL and by cutoff date
type PageModel ¶
type PageModel interface {
GetById(id int) (*Page, error)
GetAllByURL(urlId uint, cf CommonFilters) ([]*Page, error)
GetLatestPageCount(
ctx context.Context,
baseURL *url.URL,
markedURL string,
cutoffDate time.Time,
) (int, error)
GetLatestPagesPaginated(
ctx context.Context,
baseURL *url.URL,
markedURL string,
cutoffDate time.Time,
pageNum int,
pageSize int,
) ([]*PageContent, error)
Insert(*Page) error
// Update method is not required, yet
// Update(*Page) error
Delete(id int) error
}
type URL ¶
type URL struct {
ID uint `json:"id"`
URL string `json:"url"`
FirstEncountered time.Time `json:"first_seen"`
LastChecked time.Time `json:"last_checked"`
LastSaved time.Time `json:"last_saved"`
IsMonitored bool `json:"is_monitored"`
IsAlive bool `json:"is_alive"`
Version uint `json:"version"`
}
URL type holds the information of URL saved in model
func URLGetAll ¶
func URLGetAll( uf URLFilter, cf CommonFilters, query string, db *sql.DB, queryTransformFn func(string) string, ) ([]*URL, error)
URLGetAll fetches all rows from urls table as per filters
func URLGetById ¶
URLGetById fetches a row from urls table by id