datasource

package
v0.0.0-...-45a77b9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: Unlicense Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSource

type DataSource interface {
	SelectAllShortUrl() ([]ShortUrl, error)
	InsertShortUrl(ShortUrl) (sql.Result, error)
	SelectByOriginalUrl(string) (ShortUrl, error)
	SelectByShortUrlCode(string) (ShortUrl, error)
}

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

func (*Postgres) CreateShortUrlTable

func (p *Postgres) CreateShortUrlTable() (sql.Result, error)

func (*Postgres) Init

func (p *Postgres) Init(dsn string, verbose bool)

func (*Postgres) InsertShortUrl

func (p *Postgres) InsertShortUrl(u ShortUrl) (result sql.Result, err error)

InsertShortUrl inserts one record of short links in the database.

func (*Postgres) SelectAllShortUrl

func (p *Postgres) SelectAllShortUrl() (us []ShortUrl, err error)

SelectAllShortUrl reads all short links records from the database.

func (*Postgres) SelectByOriginalUrl

func (p *Postgres) SelectByOriginalUrl(oriurl string) (us ShortUrl, err error)

SelectByOriginalUrl selects the record by original URL in the database.

func (*Postgres) SelectByShortUrlCode

func (p *Postgres) SelectByShortUrlCode(code string) (us ShortUrl, err error)

SelectByShortUrlCode selects the record by short url code in the database.

type ShortUrl

type ShortUrl struct {
	ShortUrlCode string
	OriginalUrl  string
}

type Sqlite

type Sqlite struct {
	// contains filtered or unexported fields
}

func (*Sqlite) CreateShortUrlTable

func (s *Sqlite) CreateShortUrlTable() (sql.Result, error)

CreateShortUrlTable creates table in the database to store short links.

func (*Sqlite) Init

func (s *Sqlite) Init(dsn string, verbose bool) (err error)

InitSQLite initialize in-memory database to store data. The verbose flag indicates whether to print all queries to stdout.

func (*Sqlite) InsertShortUrl

func (s *Sqlite) InsertShortUrl(u ShortUrl) (result sql.Result, err error)

InsertShortUrl inserts one record of short links in the database.

func (*Sqlite) SelectAllShortUrl

func (s *Sqlite) SelectAllShortUrl() (us []ShortUrl, err error)

SelectAllShortUrl reads all short links records from the database.

func (*Sqlite) SelectByOriginalUrl

func (s *Sqlite) SelectByOriginalUrl(oriurl string) (us ShortUrl, err error)

SelectByOriginalUrl selects the record by original URL in the database.

func (*Sqlite) SelectByShortUrlCode

func (s *Sqlite) SelectByShortUrlCode(code string) (us ShortUrl, err error)

SelectByShortUrlCode selects the record by short url code in the database.

Jump to

Keyboard shortcuts

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