dblog

package module
v0.0.0-...-74b46ea Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: LGPL-3.0 Imports: 5 Imported by: 0

README

dblog aka 🐹 + 📜🪶 = 🌐✍️

Go pkg for database system for some of the sites I'm building. Originally part of angel-castaneda.com git repo.

how it works

I'm about to update a whole ton with this package to have auto post directory scanning. Will put details on how it works once it's done.

converting to a git submodule

This is a way for me to learn git submodules and put some progress here.

I followed this simple stackoverflow guide to move my git history over.

Then I went to my main repo, removed the original directory, and ran:

$ git submodule add https://git.sr.ht/~acsqdotme/dblog

That cloned in this new directory and a .gitmodules file:

[submodule "dblog"]
	path = dblog
	url = https://git.sr.ht/~acsqdotme/dblog

As always, more details can be found from git themselves.

License

This project is licensed under the LGPLv3. Check LICENSE for details.

Documentation

Overview

Package dblog for creating, reading, and writing to a sqlite database for my blog

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPost

func AddPost(post Post) (err error)

AddPost checks to see if a post is valid first will checkPost then also by ensuring every tag that is inside the post exists in the db. You don't even need to add anything more than the names of the tags in the tag slice of the post as that's how it's checked before the post is inserted into the db as well as being how the tag_id is filled into the posts_tags associative identity for linking the metadata together.

func AddTag

func AddTag(tag Tag) (err error)

AddTag is just a simpler version of AddPost. The only filtering done before is seeing if your tag struct has all the required attributes to add to the db.

func DeletePost

func DeletePost(fileName string) (err error)

DeletePost is incomplete

func DeleteTag

func DeleteTag(tagName string) (err error)

DeleteTag is incomplete

func DoesPostExist

func DoesPostExist(fileName string) bool

DoesPostExist is an evolution from my original filesystem func that I still use called doesFileExist that ensures a certain post in actually in the db.

func DoesTagExist

func DoesTagExist(tag string) bool

DoesTagExist is the exact same deal as DoesPostExist

func MakeDB

func MakeDB() (err error)

MakeDB makes the basic schema for the database if it doesn't exist. originally, it had a trigger for update_date whenever something changed, but that was too clunky to deal with for me. I might eventually add it searching for a backup .sql file in the same directory as the db in case there's backup data.

Types

type DB

type DB struct {
	PathToDB string
}

DB custom type is gonna be my attempt at making paths to the database defined in the original package. Still a todo for now.

type Img

type Img struct {
	Src   string `json:"src"`
	Alt   string `json:"alt"`
	Title string `json:"title"`
}

Img struct exists for my thumbnail image in the front of my site, but I will definitely use this package for other things that I'll need for other friend's sites I'm designing

type Post

type Post struct {
	Title       string
	FileName    string
	Content     string
	Description string
	PubDate     string
	UpdateDate  string
	Tags        []Tag
	Thumbnail   Img
}

Post type has pretty much all of the content and metadata that I'd need to manipulate for a complex blogging system that I can still manage.

func AggregatePosts

func AggregatePosts(postQty int, filterTag string) (posts []Post, err error)

AggregatePosts gets all the posts and tags metadata from the db into a slice of posts sorted in reverse chron order. if you give it a tag, it'll only return posts with that tag. giving the func a negative number returns an empty slice and giving it zero will return all the entries that match. If you give it an integer less than the total amount of posts available with the filter, it'll return that many posts back in the slice, still in reverse chron order.

func FetchPost

func FetchPost(fileName string) (post Post, err error)

FetchPost brings back the struct data of a single post including a tag slice of all matching tags to post in associative identity.

func FetchThumbnail

func FetchThumbnail() (post Post, err error)

FetchThumbnail is for a very niche thing I needed for my home page that displays my latest photos post with a valid thumbnail. Sqlite doesn't have structs, and I don't wanna bother with pgsql or mariadb for something this small, so I just marshal and unmarshal json into the db as text. This func fetches just that post and gives back not only the img struct but the rest of the post as well for easily being able to link back to the post.

type Tag

type Tag struct {
	Name        string
	Category    string
	Description string
}

Tag struct is there to aggregate together posts with common themes. I might add an html related attribute like content in post to let tag pages be more than just a paragraph.

func FetchTag

func FetchTag(tagName string) (tag Tag, err error)

FetchTag is basically identical to FetchPost but way smaller and less complicated

Jump to

Keyboard shortcuts

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