database

package
v0.0.0-...-9681a29 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	GetPosts(int, int) ([]common.Post, error)
	GetPost(post_id int) (common.Post, error)
	AddPost(title string, excerpt string, content string) (int, error)
	ChangePost(id int, title string, excerpt string, content string) error
	DeletePost(id int) (int, error)
}

type SqlDatabase

type SqlDatabase struct {
	Address    string
	Port       int
	User       string
	Connection *sql.DB
}

func MakeSqlConnection

func MakeSqlConnection(user string, password string, address string, port int, database string) (SqlDatabase, error)

func (SqlDatabase) AddPost

func (db SqlDatabase) AddPost(title string, excerpt string, content string) (int, error)

/ This function adds a post to the database

func (SqlDatabase) ChangePost

func (db SqlDatabase) ChangePost(id int, title string, excerpt string, content string) error

/ This function changes a post based on the values / provided. Note that empty strings will mean that / the value will not be updated.

func (SqlDatabase) DeletePost

func (db SqlDatabase) DeletePost(id int) (int, error)

/ This function changes a post based on the values / provided. Note that empty strings will mean that / the value will not be updated.

func (SqlDatabase) GetPost

func (db SqlDatabase) GetPost(post_id int) (post common.Post, err error)

/ This function gets a post from the database / with the given ID.

func (SqlDatabase) GetPosts

func (db SqlDatabase) GetPosts(limit int, offset int) (all_posts []common.Post, err error)

/ This function gets all the posts from the current / database connection.

Jump to

Keyboard shortcuts

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