db

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: AGPL-3.0 Imports: 5 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 AddPost

func AddPost(post types.Post) int64

AddPost adds a new 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 AuthorizedPosts

func AuthorizedPosts(authorized bool) (posts []types.Post)

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

func AuthorizedPostsForCategory

func AuthorizedPostsForCategory(authorized bool, catName string) (posts []types.Post)

func Categories

func Categories(authorized bool) (cats []types.Category)

Categories returns all categories found on posts one has access to. They all have PostCount set to a non-zero value.

func CategoriesForPost

func CategoriesForPost(id int) (cats []types.Category)

func DeletePost

func DeletePost(id int)

func DescriptionForCategory added in v0.7.0

func DescriptionForCategory(catName string) (myco string)

func EditCategory added in v0.7.0

func EditCategory(category types.Category, newName, newDescription string)

func EditPost

func EditPost(post types.Post)

func Finalize

func Finalize()

Finalize closes the connection with the database.

func HasCategory added in v0.7.0

func HasCategory(category types.Category) (has bool)

func HasPost

func HasPost(id int) (has bool)

func HasSession

func HasSession(token string) (has bool)

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 LinkCount

func LinkCount(authorized bool) int

func MetaEntry

func MetaEntry[T any](key BetulaMetaKey) T

func NewestTime

func NewestTime(authorized bool) *time.Time

func OldestTime

func OldestTime(authorized bool) *time.Time

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 PostLast added in v0.7.0

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

func SetCategoriesFor

func SetCategoriesFor(postID int, categories []types.Category)

func SetCredentials

func SetCredentials(name, hash string)

func SetMetaEntry added in v0.7.0

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

func StopSession

func StopSession(token string)

Types

type BetulaMetaKey added in v0.7.0

type BetulaMetaKey string
const (
	BetulaMetaAdminUsername     BetulaMetaKey = "Admin username"
	BetulaMetaAdminPasswordHash BetulaMetaKey = "Admin password hash"
	BetulaMetaNetworkPort       BetulaMetaKey = "Network port"
	BetulaMetaSiteTitle         BetulaMetaKey = "Site title HTML"
	BetulaMetaSiteName          BetulaMetaKey = "Site name plaintext"
	BetulaMetaSiteDescription   BetulaMetaKey = "Site description Mycomarkup"
)

Jump to

Keyboard shortcuts

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