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 ¶
- func AddPost(post types.Post) int64
- func AddSession(token string)
- func AuthorizedPosts(authorized bool) (posts []types.Post)
- func AuthorizedPostsForCategory(authorized bool, catName string) (posts []types.Post)
- func Categories(authorized bool) (cats []types.Category)
- func CategoriesForPost(id int) (cats []types.Category)
- func DeletePost(id int)
- func DescriptionForCategory(catName string) (myco string)
- func EditCategory(category types.Category, newName, newDescription string)
- func EditPost(post types.Post)
- func Finalize()
- func HasCategory(category types.Category) (has bool)
- func HasPost(id int) (has bool)
- func HasSession(token string) (has bool)
- func Initialize(filename string)
- func LinkCount(authorized bool) int
- func MetaEntry[T any](key BetulaMetaKey) T
- func NewestTime(authorized bool) *time.Time
- func OldestTime(authorized bool) *time.Time
- func PostForID(id int) (post types.Post, found bool)
- func PostLast(authorized bool) (post types.Post, found bool)
- func SetCategoriesFor(postID int, categories []types.Category)
- func SetCredentials(name, hash string)
- func SetMetaEntry[T any](key BetulaMetaKey, val T)
- func StopSession(token string)
- type BetulaMetaKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPost ¶
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 ¶
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 Categories ¶
Categories returns all categories found on posts one has access to. They all have PostCount set to a non-zero value.
func CategoriesForPost ¶
func DeletePost ¶
func DeletePost(id int)
func DescriptionForCategory ¶ added in v0.7.0
func EditCategory ¶ added in v0.7.0
func HasCategory ¶ added in v0.7.0
func HasSession ¶
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 MetaEntry ¶
func MetaEntry[T any](key BetulaMetaKey) T
func NewestTime ¶
func OldestTime ¶
func SetCategoriesFor ¶
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" )