database

package
v0.0.0-...-4367a76 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

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.

func CreateLinksTable

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

CreateLinksTable creates the links table in the database.

func DBConnect

func DBConnect(dbType, dbURL string) (*sql.DB, error)

DBConnect tries to connect to database using given driver and db url, error if it can't.

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 RemoveLink(db *sql.DB, short string) error

RemoveLink removes a link entry from the links table by its value of the short column.

Types

type Link struct {
	ExpireAt time.Time `json:"expireAt"`
	URL      string    `json:"url"`
	Short    string    `json:"short"`
}

Link defines the structure of a link entry that will be served to the client in json.

func GetLinks(db *sql.DB) ([]Link, error)

GetLinks gets all the links entries from the database.

Jump to

Keyboard shortcuts

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