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 ¶
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 ¶
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 DoesPostExist ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.