storage

package
v0.0.0-...-61649fe Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package storage describes the interface for interacting with our datastore, and provides a PostgreSQL implementation for the slice-it-api.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Db

type Db struct {
	*sql.DB
}

Db provides a set of methods for interacting with our database.

func NewDB

func NewDB() (*Db, error)

NewDB creates a connection with our postgres database and returns it, otherwise an error.

func (*Db) Create

func (db *Db) Create(url SliceItURL) error

Create handles inserting a SliceItURL into the database. With no other requirements, we don't need to return anything but an error if it happens.

func (*Db) Get

func (db *Db) Get(urlHash string) (string, error)

Get takes a URL hash and finds and returns the full length original link

func (*Db) GetViewCount

func (db *Db) GetViewCount(urlHash string) (int, error)

GetViewCount takes a short URL hash and finds and returns the view count stats from that URL

type SliceItURL

type SliceItURL struct {
	ID        int    `json:"id,omitempty"`
	Short     string `json:"short,omitempty"`
	Long      string `json:"long,omitempty"`
	ViewCount int    `json:"view_count,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
	UpdatedAt string `json:"updated_at,omitempty"`
}

SliceItURL represents a URL in in our system.

type URLRepository

type URLRepository interface {
	Create(url SliceItURL) error
	Get(urlHash string) (string, error)
	GetViewCount(urlHash string) (int, error)
}

URLRepository describes the interface for interacting with our datastore. This can viewed like a plug in adapter, making testing and/or switching datastores much more trivial.

Jump to

Keyboard shortcuts

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