database

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package database is used to handle the database connection and queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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

func CreateLinksTable(database *sql.DB, dbType string, maxShort int) error

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

func DBConnect(dbType, dbURL, dbUser, dbPass, dbHost, dbPort, dbName string) (*sql.DB, error)

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

func GetHashByShort(db *sql.DB, short string) (string, error)

GetHashByShort gets a hash from a link entry by its value of the short column.

func GetURLByShort

func GetURLByShort(db *sql.DB, short string) (string, error)

GetURLByShort gets a link entry from the links table by its value of the short column.

func RemoveExpiredLinks(db *sql.DB) error

RemoveExpiredLinks removes an expired link entry from the links table.

Types

This section is empty.

Jump to

Keyboard shortcuts

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