Documentation
¶
Overview ¶
Package db provides a database interface and implementations.
Index ¶
- type Database
- type Memory
- func (m Memory) Close() error
- func (m Memory) Connect() error
- func (m Memory) Create(i *models.IPSW) error
- func (m Memory) Delete(id uint) error
- func (m Memory) Get(id uint) (*models.IPSW, error)
- func (m Memory) List(version string) ([]*models.IPSW, error)
- func (m Memory) Set(key uint, value *models.IPSW) error
- type Postgres
- type Sqlite
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 ¶
NewInMemory creates a new in-memory database.
func NewPostgres ¶
NewPostgres creates a new Postgres database.
type Memory ¶
Memory is a database that stores data in memory.
func (Memory) Close ¶
Close closes the database. It returns ErrClosed if the database is already closed.
func (Memory) Create ¶
Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.
func (Memory) Delete ¶
Delete removes the given key. It returns ErrNotFound if the key does not exist.
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 ¶
Close closes the database. It returns ErrClosed if the database is already closed.
func (Postgres) Create ¶
Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.
func (Postgres) Delete ¶
Delete removes the given key. It returns ErrNotFound if the key does not exist.
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 ¶
Close closes the database. It returns ErrClosed if the database is already closed.
func (*Sqlite) Create ¶
Create creates a new entry in the database. It returns ErrAlreadyExists if the key already exists.
func (*Sqlite) Delete ¶
Delete removes the given key. It returns ErrNotFound if the key does not exist.