db

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 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 AddPost

func AddPost(post types.Post) int64

AddPost adds a new original post to the database. Creation time is set by this function, ID is set by the database. The ID is returned.

func AddSession

func AddSession(token string)

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 DeletePost

func DeletePost(id int)

func DeleteRepost added in v1.1.0

func DeleteRepost(postId 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 EditPost

func EditPost(post types.Post)

func Finalize

func Finalize()

Finalize closes the connection with the database.

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 HasPost

func HasPost(id int) (has bool)

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 KeyPemByID added in v1.2.0

func KeyPemByID(keyID string) string

func LastPost added in v0.8.0

func LastPost(authorized bool) (post types.Post, found bool)

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 MoreTestingPosts added in v0.8.0

func MoreTestingPosts()

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 PostCount added in v0.8.0

func PostCount(authorized bool) uint

func PostForID

func PostForID(id int) (post types.Post, found bool)

PostForID returns the post corresponding to the given id, if there is any.

func Posts added in v0.8.0

func Posts(authorized bool, page uint) (posts []types.Post, totalPosts uint)

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

func PostsForDay added in v0.8.0

func PostsForDay(authorized bool, dayStamp string) (posts []types.Post)

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

func PostsWithTag added in v0.8.0

func PostsWithTag(authorized bool, tagName string, page uint) (posts []types.Post, totalPosts uint)

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 post.

func SaveRepost added in v1.1.0

func SaveRepost(postId int, repost types.RepostInfo)
func Search(text string, includedTags []string, excludedTags []string, authorized bool, page uint) (posts []types.Post, totalPosts uint)

func SessionExists added in v0.8.0

func SessionExists(token string) (has bool)

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(postID int, tags []types.Tag)

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 posts one has access to. They all have PostCount set to a non-zero value.

func TagsForPost added in v0.8.0

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

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