feedstore

package module
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Feed Store

Feed Store is a Go library designed to efficiently store and manage feed data (like RSS or Atom) using SQL database backends. It provides a simple interface for adding, retrieving, and querying feed items, supporting SQLite, PostgreSQL, and MySQL.

License

This project is dual-licensed under the following terms:

  • For non-commercial use, you may choose either the GNU Affero General Public License v3.0 (AGPLv3) or a separate commercial license (see below). You can find a copy of the AGPLv3 at: https://www.gnu.org/licenses/agpl-3.0.txt

  • For commercial use, a separate commercial license is required. Commercial licenses are available for various use cases. Please contact me via my contact page to obtain a commercial license.

Description

Feed Store provides a persistent storage solution for feed items parsed from sources like RSS or Atom feeds. It abstracts the underlying database interactions, allowing you to work with feed data through a consistent Go API.

Key Features:

  • SQL Backends: Supports SQLite, PostgreSQL, and MySQL databases.
  • Simple API: Offers straightforward methods for adding, retrieving, and querying feed items.
  • Persistence: Stores feed data durably in your chosen SQL database.

This library focuses solely on the storage aspect. Fetching and parsing feeds should be handled by other libraries (e.g., gofeed).

Installation

go get github.com/dracory/feedstore

Examples

1. Store Initialization:

    // --- Initialize Feed Store ---
    // Provide table names and enable automigration for this example
    store, err := feedstore.NewStore(feedstore.NewStoreOptions{
        DB:                 db,
        FeedTableName:      "feeds", // Choose your feed table name
        LinkTableName:      "links", // Choose your link table name
        AutomigrateEnabled: true,    // Automatically create/update tables
        // DebugEnabled:    true,    // Optional: Enable SQL logging
    })
    if err != nil {
        log.Fatalf("❌ Failed to initialize feed store: %v", err)
    }
    fmt.Println("✅ Feed store initialized (tables migrated if needed).")

2. Feed Operations:

    // --- Create a Feed ---
    feed1 := feedstore.NewFeed().
        SetName("Example Blog Feed").
        SetURL("https://example.com/blog/rss").
        SetStatus(feedstore.FEED_STATUS_ACTIVE).
        SetFetchInterval("3600") // e.g., 1 hour

    err := store.FeedCreate(feed1)
    if err != nil {
        log.Printf("⚠️ Failed to create feed: %v", err)
        return
    }
    fmt.Printf("✅ Feed created successfully: ID=%s, Name=%s\n", feed1.GetID(), feed1.GetName())

    // --- Find Feed by ID ---
    foundFeed, err := store.FeedFindByID(feed1.GetID())
    if err != nil {
        log.Printf("⚠️ Error finding feed %s: %v", feed1.GetID(), err)
    } else if foundFeed == nil {
        fmt.Printf("ℹ️ Feed %s not found.\n", feed1.GetID())
    } else {
        fmt.Printf("✅ Found feed by ID: %s (Name: %s)\n", foundFeed.GetID(), foundFeed.GetName())
    }

    // --- List Active Feeds ---
    activeFeeds, err := store.FeedList(feedstore.FeedQuery().
        SetStatus(feedstore.FEED_STATUS_ACTIVE).
        SetLimit(10)) // Limit results
    if err != nil {
        log.Printf("⚠️ Error listing active feeds: %v", err)
    } else {
        fmt.Printf("✅ Found %d active feed(s):\n", len(activeFeeds))
        for _, f := range activeFeeds {
            fmt.Printf("   - ID: %s, Name: %s, Status: %s\n", f.GetID(), f.GetName(), f.GetStatus())
        }
    }

    // --- Update a Feed ---
    foundFeed.SetMemo("This feed was updated.")
    err = store.FeedUpdate(foundFeed)
    if err != nil {
        log.Printf("⚠️ Error updating feed %s: %v", foundFeed.GetID(), err)
    } else {
        fmt.Printf("✅ Feed %s updated successfully.\n", foundFeed.GetID())
        // Verify update
        updatedFeed, _ := store.FeedFindByID(foundFeed.GetID())
        if updatedFeed != nil {
            fmt.Printf("   Updated Memo: %s\n", updatedFeed.GetMemo())
        }
    }

    // --- Soft Delete a Feed ---
    // Create another feed to delete
    feedToDelete := feedstore.NewFeed().SetName("Temporary Feed").SetURL("http://temp.com/rss")
    _ = store.FeedCreate(feedToDelete)
    fmt.Printf("   Created temporary feed: %s\n", feedToDelete.GetID())

    err = store.FeedSoftDeleteByID(feedToDelete.GetID())
    if err != nil {
        log.Printf("⚠️ Error soft deleting feed %s: %v", feedToDelete.GetID(), err)
    } else {
        fmt.Printf("✅ Feed %s soft deleted.\n", feedToDelete.GetID())
    }

3. Link Operations:


// --- Create Links ---
link1 := feedstore.NewLink().
    SetFeedID(feedID).
    SetTitle("First Blog Post").
    SetURL("https://example.com/blog/post1").
    SetStatus(feedstore.LINK_STATUS_ACTIVE)


err = store.LinkCreate(link1)
if err != nil {
    log.Printf("⚠️ Failed to create link1: %v", err)
} else {
    fmt.Printf("✅ Link created successfully: ID=%s, Title=%s\n", link1.GetID(), link1.GetTitle())
}

// --- Find Link by ID ---
foundLink, err := store.LinkFindByID(link1.GetID())
if err != nil {
    log.Printf("⚠️ Error finding link %s: %v", link1.GetID(), err)
} else if foundLink == nil {
    fmt.Printf("ℹ️ Link %s not found.\n", link1.GetID())
} else {
    fmt.Printf("✅ Found link by ID: %s (Title: %s)\n", foundLink.GetID(), foundLink.GetTitle())
}

// --- List Links for a Specific Feed ---
feedLinks, err := store.LinkList(feedstore.LinkQuery().
    SetFeedID(feedID). // Filter by the feed's ID
    SetLimit(10))
if err != nil {
    log.Printf("⚠️ Error listing links for feed %s: %v", feedID, err)
} else {
    fmt.Printf("✅ Found %d link(s) for feed %s:\n", len(feedLinks), feedID)
    for _, lnk := range feedLinks {
        fmt.Printf("   - ID: %s, Title: %s, URL: %s\n", lnk.GetID(), lnk.GetTitle(), lnk.GetURL())
    }
}

// --- Update a Link ---
foundLink.SetDescription("Added a description.")
err = store.LinkUpdate(foundLink)
if err != nil {
    log.Printf("⚠️ Error updating link %s: %v", foundLink.GetID(), err)
} else {
    fmt.Printf("✅ Link %s updated successfully.\n", foundLink.GetID())
    // Verify update
    updatedLink, _ := store.LinkFindByID(foundLink.GetID())
    if updatedLink != nil {
        fmt.Printf("   Updated Description: %s\n", updatedLink.GetDescription())
    }
}

// --- Soft Delete a Link ---
err = store.LinkSoftDeleteByID(link2.GetID())
if err != nil {
    log.Printf("⚠️ Error soft deleting link %s: %v", link2.GetID(), err)
} else {
    fmt.Printf("✅ Link %s soft deleted.\n", link2.GetID())
}

Documentation

Index

Constants

View Source
const COLUMN_AUTHOR = "author"
View Source
const COLUMN_CHECKED_AT = "checked_at"
View Source
const COLUMN_CONTENT = "content"
View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_DEDUP_HASH = "dedup_hash"
View Source
const COLUMN_DESCRIPTION = "description"
View Source
const COLUMN_FEED_ID = "feed_id"
View Source
const COLUMN_FETCH_INTERVAL = "fetch_interval"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_LANGUAGE = "language"
View Source
const COLUMN_LAST_FETCHED_AT = "last_fetched_at"
View Source
const COLUMN_MEMO = "memo"
View Source
const COLUMN_METAS = "metas"
View Source
const COLUMN_NAME = "name"
View Source
const COLUMN_PRIORITY = "priority"
View Source
const COLUMN_PUBLISHED_AT = "published_at"
View Source
const COLUMN_REPORT = "report"
View Source
const COLUMN_REPORTED_AT = "reported_at"
View Source
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_TITLE = "title"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const COLUMN_URL = "url"
View Source
const COLUMN_VIEWS = "views"
View Source
const COLUMN_VOTES_DOWN = "votes_down"
View Source
const COLUMN_VOTES_UP = "votes_up"
View Source
const FEED_STATUS_ACTIVE = "active"
View Source
const FEED_STATUS_INACTIVE = "inactive"
View Source
const LINK_STATUS_ACTIVE = "active"
View Source
const LINK_STATUS_INACTIVE = "inactive"

Variables

This section is empty.

Functions

func NewFeed

func NewFeed() *feedImplementation

func NewFeedFromExistingData

func NewFeedFromExistingData(data map[string]string) *feedImplementation
func NewLink() *linkImplementation

func NewLinkFromExistingData

func NewLinkFromExistingData(data map[string]string) *linkImplementation

Types

type FeedInterface

type FeedInterface interface {
	Data() map[string]string
	MarkAsNotDirty(...string)

	// GetCreatedAt returns the created at timestamp as a string
	GetCreatedAt() string

	// GetCreatedAtCarbon returns the created at timestamp as a carbon instance
	GetCreatedAtCarbon() *carbon.Carbon

	// SetCreatedAt sets the created at timestamp
	SetCreatedAt(createdAt string) FeedInterface

	// GetDescription returns the description
	GetDescription() string

	// SetDescription sets the description
	SetDescription(description string) FeedInterface

	// GetFetchInterval returns the fetch interval
	GetFetchInterval() string

	// SetFetchInterval sets the fetch interval
	SetFetchInterval(fetchInterval string) FeedInterface

	// GetID returns the ID
	GetID() string

	// SetID sets the ID
	SetID(id string) FeedInterface

	// GetLanguage returns the language
	GetLanguage() string

	// SetLanguage sets the language
	SetLanguage(language string) FeedInterface

	// GetLastFetchedAt returns the last fetched at timestamp as a string
	GetLastFetchedAt() string

	// GetLastFetchedAtCarbon returns the last fetched at timestamp as a carbon instance
	GetLastFetchedAtCarbon() *carbon.Carbon

	// SetLastFetchedAt sets the last fetched at timestamp
	SetLastFetchedAt(lastFetchedAt time.Time) FeedInterface

	// SetLastFetchedAtString sets the last fetched at timestamp from a string
	SetLastFetchedAtString(lastFetchedAt string) FeedInterface

	// GetMemo returns the memo
	GetMemo() string

	// SetMemo sets the memo
	SetMemo(memo string) FeedInterface

	// GetMeta returns a specific meta value by key
	GetMeta(key string) (string, error)

	// SetMeta sets a specific meta value by key
	SetMeta(key string, value string) error

	// DeleteMeta removes a specific meta value by key
	DeleteMeta(key string) error

	// GetMetas returns all meta values as a map
	GetMetas() (map[string]string, error)

	// SetMetas sets all meta values from a map
	SetMetas(metas map[string]string) error

	// GetName returns the name
	GetName() string

	// SetName sets the name
	SetName(name string) FeedInterface

	// GetSoftDeletedAt returns the soft deleted at timestamp as a string
	GetSoftDeletedAt() string

	// GetSoftDeletedAtCarbon returns the soft deleted at timestamp as a carbon instance
	GetSoftDeletedAtCarbon() *carbon.Carbon

	// SetSoftDeletedAt sets the soft deleted at timestamp
	SetSoftDeletedAt(softDeletedAt string) FeedInterface

	// GetStatus returns the status
	GetStatus() string

	// SetStatus sets the status
	SetStatus(status string) FeedInterface

	// GetUpdatedAt returns the updated at timestamp as a string
	GetUpdatedAt() string

	// GetUpdatedAtCarbon returns the updated at timestamp as a carbon instance
	GetUpdatedAtCarbon() *carbon.Carbon

	// SetUpdatedAt sets the updated at timestamp
	SetUpdatedAt(updatedAt string) FeedInterface

	// GetURL returns the URL
	GetURL() string

	// SetURL sets the URL
	SetURL(url string) FeedInterface
}

type FeedQueryInterface

type FeedQueryInterface interface {
	// Validation method
	Validate() error

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) FeedQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) FeedQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) FeedQueryInterface

	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) FeedQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) FeedQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) FeedQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) FeedQueryInterface

	IsLanguageSet() bool
	GetLanguage() string
	SetLanguage(language string) FeedQueryInterface

	IsLastFetchedAtLteSet() bool
	GetLastFetchedAtLte() string
	SetLastFetchedAtLte(lastFetchedAtLte string) FeedQueryInterface

	IsLastFetchedAtGteSet() bool
	GetLastFetchedAtGte() string
	SetLastFetchedAtGte(lastFetchedAtGte string) FeedQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) FeedQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) FeedQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) FeedQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) FeedQueryInterface

	IsStatusSet() bool
	GetStatus() string
	SetStatus(status string) FeedQueryInterface

	IsStatusInSet() bool
	GetStatusIn() []string
	SetStatusIn(statuses []string) FeedQueryInterface

	IsUpdatedAtGteSet() bool
	GetUpdatedAtGte() string
	SetUpdatedAtGte(updatedAt string) FeedQueryInterface

	IsUpdatedAtLteSet() bool
	GetUpdatedAtLte() string
	SetUpdatedAtLte(updatedAt string) FeedQueryInterface

	// Owner ID (legacy, kept for compatibility)
	IsOwnerIDSet() bool
	GetOwnerID() string
	SetOwnerID(ownerID string) FeedQueryInterface
}

FeedQueryInterface defines the interface for querying feeds

func FeedQuery

func FeedQuery() FeedQueryInterface

FeedQuery creates a new feed query

type LinkInterface

type LinkInterface interface {
	Data() map[string]string
	MarkAsNotDirty(...string)

	// Creation and update timestamps
	GetCreatedAt() string
	GetCreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) LinkInterface
	GetDescription() string
	SetDescription(description string) LinkInterface
	GetContent() string
	SetContent(content string) LinkInterface
	GetAuthor() string
	SetAuthor(author string) LinkInterface
	GetPriority() bool
	SetPriority(priority bool) LinkInterface
	GetFeedID() string
	SetFeedID(feedID string) LinkInterface
	GetID() string
	SetID(id string) LinkInterface
	GetLanguage() string
	SetLanguage(language string) LinkInterface
	GetMeta(key string) (string, error)
	SetMeta(key string, value string) error
	DeleteMeta(key string) error
	GetMetas() (map[string]string, error)
	SetMetas(metas map[string]string) error
	GetStatus() string
	SetStatus(status string) LinkInterface
	GetTitle() string
	SetTitle(title string) LinkInterface
	GetPublishedAt() string
	GetPublishedAtCarbon() *carbon.Carbon
	SetPublishedAt(publishedAt time.Time) LinkInterface
	SetPublishedAtString(publishedAt string) LinkInterface
	GetDedupHash() string
	SetDedupHash(dedupHash string) LinkInterface
	GetSoftDeletedAt() string
	GetSoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) LinkInterface
	GetUpdatedAt() string
	GetUpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) LinkInterface
	GetURL() string
	SetURL(url string) LinkInterface
	GetViews() string
	SetViews(views string) LinkInterface
	GetVotesUp() string
	SetVotesUp(votesUp string) LinkInterface
	GetVotesDown() string
	SetVotesDown(votesDown string) LinkInterface
	GetReport() string
	SetReport(report string) LinkInterface
	GetReportedAt() string
	GetReportedAtCarbon() *carbon.Carbon
	SetReportedAt(reportedAt time.Time) LinkInterface
	SetReportedAtString(reportedAt string) LinkInterface
	GetCheckedAt() string
	GetCheckedAtCarbon() *carbon.Carbon
	SetCheckedAt(timeChecked time.Time) LinkInterface
	SetCheckedAtString(timeChecked string) LinkInterface
}

type LinkQueryInterface

type LinkQueryInterface interface {
	// Validation method
	Validate() error

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) LinkQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) LinkQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) LinkQueryInterface

	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) LinkQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) LinkQueryInterface

	IsFeedIDSet() bool
	GetFeedID() string
	SetFeedID(feedID string) LinkQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) LinkQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) LinkQueryInterface

	IsLanguageSet() bool
	GetLanguage() string
	SetLanguage(language string) LinkQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) LinkQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) LinkQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) LinkQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) LinkQueryInterface

	IsStatusSet() bool
	GetStatus() string
	SetStatus(status string) LinkQueryInterface

	IsStatusInSet() bool
	GetStatusIn() []string
	SetStatusIn(statuses []string) LinkQueryInterface

	IsURLSet() bool
	GetURL() string
	SetURL(url string) LinkQueryInterface

	IsUpdatedAtGteSet() bool
	GetUpdatedAtGte() string
	SetUpdatedAtGte(updatedAt string) LinkQueryInterface

	IsUpdatedAtLteSet() bool
	GetUpdatedAtLte() string
	SetUpdatedAtLte(updatedAt string) LinkQueryInterface

	// PublishedAt (publication datetime) filters
	IsPublishedAtGteSet() bool
	GetPublishedAtGte() string
	SetPublishedAtGte(publishedAt string) LinkQueryInterface

	IsPublishedAtLteSet() bool
	GetPublishedAtLte() string
	SetPublishedAtLte(publishedAt string) LinkQueryInterface

	// Dedup hash filter
	IsDedupHashSet() bool
	GetDedupHash() string
	SetDedupHash(dedupHash string) LinkQueryInterface

	// Priority filter
	IsPrioritySet() bool
	GetPriority() string
	SetPriority(priority string) LinkQueryInterface

	// Owner ID (legacy, kept for compatibility)
	IsOwnerIDSet() bool
	GetOwnerID() string
	SetOwnerID(ownerID string) LinkQueryInterface
}

LinkQueryInterface defines the interface for querying links

func LinkQuery

func LinkQuery() LinkQueryInterface

LinkQuery creates a new link query

type NewStoreOptions

type NewStoreOptions struct {
	FeedTableName      string
	LinkTableName      string
	DB                 *sql.DB
	AutomigrateEnabled bool
	DebugEnabled       bool
}

NewStoreOptions define the options for creating a new feed store

type StoreInterface

type StoreInterface interface {
	// MigrateDown drops the feed and link tables
	MigrateDown(ctx context.Context, tx ...*sql.Tx) error

	// MigrateUp creates the feed and link tables
	MigrateUp(ctx context.Context, tx ...*sql.Tx) error
	EnableDebug(debug bool)

	GetDB() *sql.DB
	GetFeedTableName() string
	GetLinkTableName() string

	FeedCount(ctx context.Context, query FeedQueryInterface) (int64, error)
	FeedCreate(ctx context.Context, feed FeedInterface) error
	FeedDelete(ctx context.Context, feed FeedInterface) error
	FeedDeleteByID(ctx context.Context, id string) error
	FeedFindByID(ctx context.Context, id string) (FeedInterface, error)
	FeedList(ctx context.Context, query FeedQueryInterface) ([]FeedInterface, error)
	FeedSoftDelete(ctx context.Context, feed FeedInterface) error
	FeedSoftDeleteByID(ctx context.Context, id string) error
	FeedUpdate(ctx context.Context, feed FeedInterface) error

	LinkCount(ctx context.Context, query LinkQueryInterface) (int64, error)
	LinkCreate(ctx context.Context, link LinkInterface) error
	LinkDelete(ctx context.Context, link LinkInterface) error
	LinkDeleteByID(ctx context.Context, id string) error
	LinkFindByID(ctx context.Context, id string) (LinkInterface, error)
	LinkList(ctx context.Context, query LinkQueryInterface) ([]LinkInterface, error)
	LinkSoftDelete(ctx context.Context, link LinkInterface) error
	LinkSoftDeleteByID(ctx context.Context, id string) error
	LinkUpdate(ctx context.Context, link LinkInterface) error
}

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new feed store

Jump to

Keyboard shortcuts

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