db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db provides a database interface and implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// Connect connects to the database.
	Connect() error

	// Create creates a new entry in the database.
	// It returns ErrAlreadyExists if the key already exists.
	Create(i *models.IPSW) error

	// Get returns the value for the given key.
	// It returns ErrNotFound if the key does not exist.
	Get(key uint) (*models.IPSW, error)

	// Set sets the value for the given key.
	// It overwrites any previous value for that key.
	Set(key uint, value *models.IPSW) error

	// Delete removes the given key.
	// It returns ErrNotFound if the key does not exist.
	Delete(key uint) error

	// Close closes the database.
	// It returns ErrClosed if the database is already closed.
	Close() error
}

Database is the interface that wraps the basic database operations.

func NewInMemory

func NewInMemory(path string) Database

NewInMemory creates a new in-memory database.

func NewPostgres

func NewPostgres(host, port, user, password, database string) Database

NewPostgres creates a new Postgres database.

func NewSqlite

func NewSqlite(path string) Database

NewSqlite creates a new Sqlite database.

type Memory

type Memory struct {
	IPSWs map[uint]*models.IPSW
	Path  string
}

Memory is a database that stores data in memory.

func (Memory) Close

func (m Memory) Close() error

Close closes the database. It returns ErrClosed if the database is already closed.

func (Memory) Connect

func (m Memory) Connect() error

Connect connects to the database.

func (Memory) Create

func (m Memory) Create(i *models.IPSW) error

Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.

func (Memory) Delete

func (m Memory) Delete(id uint) error

Delete removes the given key. It returns ErrNotFound if the key does not exist.

func (Memory) Get

func (m Memory) Get(id uint) (*models.IPSW, error)

Get returns the value for the given key. It returns ErrNotFound if the key does not exist.

func (Memory) List

func (m Memory) List(version string) ([]*models.IPSW, error)

func (Memory) Set

func (m Memory) Set(key uint, value *models.IPSW) error

Set sets the value for the given key. It overwrites any previous value for that key.

type Postgres

type Postgres struct {
	URL      string
	Host     string
	Port     string
	User     string
	Password string
	Database string
	// contains filtered or unexported fields
}

Postgres is a database that stores data in a Postgres database.

func (Postgres) Close

func (p Postgres) Close() error

Close closes the database. It returns ErrClosed if the database is already closed.

func (Postgres) Connect

func (p Postgres) Connect() (err error)

Connect connects to the database.

func (Postgres) Create

func (p Postgres) Create(i *models.IPSW) error

Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.

func (Postgres) Delete

func (p Postgres) Delete(key uint) error

Delete removes the given key. It returns ErrNotFound if the key does not exist.

func (Postgres) Get

func (p Postgres) Get(key uint) (*models.IPSW, error)

Get returns the value for the given key. It returns ErrNotFound if the key does not exist.

func (Postgres) Set

func (p Postgres) Set(key uint, value *models.IPSW) error

Set sets the value for the given key. It overwrites any previous value for that key.

type Sqlite

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

Sqlite is a database that stores data in a sqlite database.

func (*Sqlite) Close

func (s *Sqlite) Close() error

Close closes the database. It returns ErrClosed if the database is already closed.

func (*Sqlite) Connect

func (s *Sqlite) Connect() (err error)

Connect connects to the database.

func (*Sqlite) Create

func (s *Sqlite) Create(i *models.IPSW) error

Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.

func (*Sqlite) Delete

func (s *Sqlite) Delete(key uint) error

Delete removes the given key. It returns ErrNotFound if the key does not exist.

func (*Sqlite) Get

func (s *Sqlite) Get(key uint) (*models.IPSW, error)

Get returns the value for the given key. It returns ErrNotFound if the key does not exist.

func (*Sqlite) Set

func (s *Sqlite) Set(key uint, value *models.IPSW) error

Set sets the value for the given key. It overwrites any previous value for that key.

Jump to

Keyboard shortcuts

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