db

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package db encapsulates all used queries to the database.

Do not forget to Initialize and Finalize.

All functions in this package might crash vividly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActorByAcct added in v1.2.0

func ActorByAcct(user, host string) (a *types.Actor, found bool)

func ActorByID added in v1.2.0

func ActorByID(actorID string) (a *types.Actor, found bool)

func AddFollower added in v1.2.0

func AddFollower(id string)

func AddPendingFollowing added in v1.2.0

func AddPendingFollowing(id string)

func AddSession

func AddSession(token, userAgent string)

func BookmarkCount added in v1.3.0

func BookmarkCount(authorized bool) uint

func Bookmarks added in v1.3.0

func Bookmarks(authorized bool, page uint) (bookmarks []types.Bookmark, total uint)

Bookmarks returns all bookmarks stored in the database on the given page, along with their tags, but only if the viewer is authorized! Otherwise, only public bookmarks will be given.

func BookmarksForDay added in v1.3.0

func BookmarksForDay(authorized bool, dayStamp string) (bookmarks []types.Bookmark)

BookmarksForDay returns bookmarks for the given dayStamp, which looks like this: 2023-03-14. The result might as well be nil, that means there are no bookmarks for the day.

func BookmarksWithTag added in v1.3.0

func BookmarksWithTag(authorized bool, tagName string, page uint) (bookmarks []types.Bookmark, total uint)

func CountFollowers added in v1.2.0

func CountFollowers() uint

func CountFollowing added in v1.2.0

func CountFollowing() uint

func CountRepostsOf added in v1.1.0

func CountRepostsOf(id int) int

func DeleteBookmark added in v1.3.0

func DeleteBookmark(id int)

func DeleteRemoteBookmark added in v1.3.0

func DeleteRemoteBookmark(bid string)

func DeleteRepost added in v1.1.0

func DeleteRepost(bookmarkID int, repostURL string)

func DeleteTag added in v0.8.0

func DeleteTag(tagName string)

func DescriptionForTag added in v0.8.0

func DescriptionForTag(tagName string) (myco string)

func DropJob added in v1.1.0

func DropJob(id int64)

DropJob removes the job specified by id from the database. Call after the job is done.

func EditBookmark added in v1.3.0

func EditBookmark(bookmark types.Bookmark)

func Finalize

func Finalize()

Finalize closes the connection with the database.

func GetBookmarkByID added in v1.3.0

func GetBookmarkByID(id int) (b types.Bookmark, found bool)

GetBookmarkByID returns the bookmark corresponding to the given id, if there is any.

func GetFollowers added in v1.2.0

func GetFollowers() (actors []types.Actor)

func GetFollowing added in v1.2.0

func GetFollowing() (actors []types.Actor)

func GetRemoteBookmarks added in v1.3.0

func GetRemoteBookmarks(page uint) (bookmarks []types.RemoteBookmark, total uint)

func GetRemoteBookmarksBy added in v1.3.0

func GetRemoteBookmarksBy(authorID string, page uint) (bookmarks []types.RemoteBookmark, total uint)

func InitInMemoryDB added in v0.8.0

func InitInMemoryDB()

InitInMemoryDB initializes a database in :memory:. Use it instead of a real db in a file for tests.

func Initialize

func Initialize(filename string)

Initialize opens a SQLite3 database with the given filename. The connection is encapsulated, you cannot access the database directly, you are to use the functions provided by the package.

func InsertBookmark added in v1.3.0

func InsertBookmark(bookmark types.Bookmark) int64

InsertBookmark adds a new local bookmark to the database. Creation time is set by this function, ID is set by the database. The ID is returned.

func InsertRemoteBookmark added in v1.3.0

func InsertRemoteBookmark(b types.RemoteBookmark)

func KeyPemByID added in v1.2.0

func KeyPemByID(keyID string) string

func LoadAllJobs added in v1.1.0

func LoadAllJobs() (jobs []jobtype.Job)

LoadAllJobs reads all jobs in the database. Call on startup once.

func MarkAsSurelyFollowing added in v1.2.0

func MarkAsSurelyFollowing(id string)

func MetaEntry

func MetaEntry[T any](key BetulaMetaKey) T

func MoreTestingBookmarks added in v1.3.0

func MoreTestingBookmarks()

func NewestTime

func NewestTime(authorized bool) *time.Time

func OldestTime

func OldestTime(authorized bool) *time.Time

func PlanJob added in v1.1.0

func PlanJob(job jobtype.Job) int64

PlanJob puts a new job into the Jobs table and returns the id of the new job.

func RandomBookmarks added in v1.3.0

func RandomBookmarks(authorized bool, n uint) (bookmarks []types.Bookmark, total uint)

func RemoteBookmarkIsStored added in v1.3.0

func RemoteBookmarkIsStored(bid string) (isStored bool)

func RemoveFollower added in v1.2.0

func RemoveFollower(id string)

func RenameTag added in v0.8.0

func RenameTag(oldTagName, newTagName string)

func RepostsOf added in v1.1.0

func RepostsOf(id int) (reposts []types.RepostInfo, err error)

RepostsOf returns all reposts known about the specified bookmark.

func SaveRepost added in v1.1.0

func SaveRepost(bookmarkID int, repost types.RepostInfo)
func Search(text string, includedTags []string, excludedTags []string, repostsOnly, authorized bool, page uint) (results []types.Bookmark, totalResults uint)

func SessionExists added in v0.8.0

func SessionExists(token string) (has bool)

func Sessions added in v1.3.0

func Sessions() (sessions []types.Session)

func SetCredentials

func SetCredentials(name, hash string)

func SetMetaEntry added in v0.7.0

func SetMetaEntry[T any](key BetulaMetaKey, val T)

func SetTagDescription added in v0.8.0

func SetTagDescription(tagName string, description string)

func SetTagsFor added in v0.8.0

func SetTagsFor(bookmarkID int, tags []types.Tag)

func StopAllSessions added in v1.3.0

func StopAllSessions(excludeToken string)

func StopFollowing added in v1.2.0

func StopFollowing(id string)

func StopSession

func StopSession(token string)

func StoreValidActor added in v1.2.0

func StoreValidActor(a types.Actor)

func SubscriptionStatus added in v1.2.0

func SubscriptionStatus(id string) types.SubscriptionRelation

func TagCount added in v0.8.0

func TagCount(authorized bool) (count uint)

TagCount counts how many tags there are available to the user.

func TagExists added in v0.8.0

func TagExists(tagName string) (has bool)

func Tags added in v0.8.0

func Tags(authorized bool) (tags []types.Tag)

Tags returns all tags found on bookmarks one has access to. They all have BookmarkCount set to a non-zero value.

func TagsForBookmarkByID added in v1.3.0

func TagsForBookmarkByID(id int) (tags []types.Tag)

func UpdateRemoteBookmark added in v1.3.0

func UpdateRemoteBookmark(b types.RemoteBookmark)

Types

type BetulaMetaKey added in v0.7.0

type BetulaMetaKey string

BetulaMetaKey is key from the BetulaMeta table.

const (
	BetulaMetaAdminUsername     BetulaMetaKey = "Admin username"
	BetulaMetaAdminPasswordHash BetulaMetaKey = "Admin password hash"
	BetulaMetaNetworkHost       BetulaMetaKey = "Network hostname"
	BetulaMetaNetworkPort       BetulaMetaKey = "Network port"
	BetulaMetaSiteTitle         BetulaMetaKey = "Site title HTML"
	BetulaMetaSiteName          BetulaMetaKey = "Site name plaintext"
	BetulaMetaSiteDescription   BetulaMetaKey = "Site description Mycomarkup"
	BetulaMetaSiteURL           BetulaMetaKey = "WWW URL"
	BetulaMetaCustomCSS         BetulaMetaKey = "Custom CSS"
	BetulaMetaPrivateKey        BetulaMetaKey = "Private key PEM"
	BetulaMetaEnableFederation  BetulaMetaKey = "Federation enabled"
)

Jump to

Keyboard shortcuts

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