Documentation
¶
Overview ¶
Package database is used to handle the database connection and queries.
Index ¶
- func CreateLink(database *sql.DB, identifier uuid.UUID, createdAt time.Time, ...) error
- func CreateLinksTable(database *sql.DB, dbType string, maxShort int) error
- func DBConnect(dbType, dbURL, dbUser, dbPass, dbHost, dbPort, dbName string) (*sql.DB, error)
- func GetHashByShort(db *sql.DB, short string) (string, error)
- func GetURLByShort(db *sql.DB, short string) (string, error)
- func RemoveExpiredLinks(db *sql.DB) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateLink ¶
func CreateLink( database *sql.DB, identifier uuid.UUID, createdAt time.Time, expireAt time.Time, url, short, password string, ) error
CreateLink inserts a link entry in the links table.
An SQL statement is prepared, it will insert a record into the links table giving a uuid, a creation time, an expiration time, a url, a short and a password.
func CreateLinksTable ¶
CreateLinksTable creates the links table in the database.
An SQL statement is prepared using the max short length as the max for the short column, the statement is then executed which should create the links table if it doesn't exist.
func DBConnect ¶
DBConnect returns a pointer to a database connection.
It connects to the database using sql.Open with the database type and the connection string, it then tests the connection before returning it.
func GetHashByShort ¶
GetHashByShort gets a hash from a link entry by its value of the short column.
func GetURLByShort ¶
GetURLByShort gets a link entry from the links table by its value of the short column.
func RemoveExpiredLinks ¶
RemoveExpiredLinks removes an expired link entry from the links table.
Types ¶
This section is empty.