Documentation ¶
Index ¶
- type Database
- type MockDatabase
- func (db *MockDatabase) Close()
- func (db *MockDatabase) DeleteBook(id int) error
- func (db *MockDatabase) InsertBook(book *models.Book) (int, error)
- func (db *MockDatabase) InsertUser(user *models.User) (int, error)
- func (db *MockDatabase) SelectAllBooks() ([]*models.Book, error)
- func (db *MockDatabase) SelectBookByID(id int) (*models.Book, error)
- func (db *MockDatabase) SelectUserByEmail(email string) (*models.User, error)
- func (db *MockDatabase) SelectUserByID(id int) (*models.User, error)
- func (db *MockDatabase) UpdateBook(id int, book *models.Book) error
- type PostgresqlDatabase
- func (db *PostgresqlDatabase) Close()
- func (db *PostgresqlDatabase) DeleteBook(id int) error
- func (db *PostgresqlDatabase) InsertBook(book *models.Book) (int, error)
- func (db *PostgresqlDatabase) InsertUser(user *models.User) (int, error)
- func (db *PostgresqlDatabase) SelectAllBooks() ([]*models.Book, error)
- func (db *PostgresqlDatabase) SelectBookByID(id int) (*models.Book, error)
- func (db *PostgresqlDatabase) SelectUserByEmail(email string) (*models.User, error)
- func (db *PostgresqlDatabase) SelectUserByID(id int) (*models.User, error)
- func (db *PostgresqlDatabase) UpdateBook(id int, book *models.Book) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface { InsertUser(*models.User) (int, error) SelectUserByID(int) (*models.User, error) SelectUserByEmail(string) (*models.User, error) InsertBook(*models.Book) (int, error) SelectBookByID(int) (*models.Book, error) SelectAllBooks() ([]*models.Book, error) DeleteBook(int) error UpdateBook(int, *models.Book) error Close() }
Database is an interface for database operations.
func NewPostgresqlDatabase ¶
NewPostgresqlDatabase creates a new PostgresqlDatabase.
type MockDatabase ¶
type MockDatabase struct {
// contains filtered or unexported fields
}
MockDatabase is a mock implementation of Database interface.
func (*MockDatabase) DeleteBook ¶
func (db *MockDatabase) DeleteBook(id int) error
DeleteBook deletes a book with given ID from the database.
func (*MockDatabase) InsertBook ¶
func (db *MockDatabase) InsertBook(book *models.Book) (int, error)
InsertBook inserts a new book into the database.
func (*MockDatabase) InsertUser ¶
func (db *MockDatabase) InsertUser(user *models.User) (int, error)
InsertUser inserts a new user into the database.
func (*MockDatabase) SelectAllBooks ¶
func (db *MockDatabase) SelectAllBooks() ([]*models.Book, error)
SelectAllBooks selects all books from the database.
func (*MockDatabase) SelectBookByID ¶
func (db *MockDatabase) SelectBookByID(id int) (*models.Book, error)
SelectBookByID selects a book with given ID from the database.
func (*MockDatabase) SelectUserByEmail ¶
func (db *MockDatabase) SelectUserByEmail(email string) (*models.User, error)
SelectUserByEmail selects a user with given email from the database.
func (*MockDatabase) SelectUserByID ¶
func (db *MockDatabase) SelectUserByID(id int) (*models.User, error)
SelectUserByID selects a user with given ID from the database.
func (*MockDatabase) UpdateBook ¶
func (db *MockDatabase) UpdateBook(id int, book *models.Book) error
UpdateBook updates a book with given ID in the database.
type PostgresqlDatabase ¶
type PostgresqlDatabase struct {
// contains filtered or unexported fields
}
PostgresqlDatabase is a Postgresql implementation of Database interface. It uses pgx as a Postgresql driver.
func (*PostgresqlDatabase) Close ¶
func (db *PostgresqlDatabase) Close()
Close closes the database connection.
func (*PostgresqlDatabase) DeleteBook ¶
func (db *PostgresqlDatabase) DeleteBook(id int) error
DeleteBook deletes a book with given ID from the database.
func (*PostgresqlDatabase) InsertBook ¶
func (db *PostgresqlDatabase) InsertBook(book *models.Book) (int, error)
InsertBook inserts a new book into the database.
func (*PostgresqlDatabase) InsertUser ¶
func (db *PostgresqlDatabase) InsertUser(user *models.User) (int, error)
InsertUser inserts a new user into the database.
func (*PostgresqlDatabase) SelectAllBooks ¶
func (db *PostgresqlDatabase) SelectAllBooks() ([]*models.Book, error)
SelectAllBooks selects all books from the database.
func (*PostgresqlDatabase) SelectBookByID ¶
func (db *PostgresqlDatabase) SelectBookByID(id int) (*models.Book, error)
SelectBookByID selects a book with given ID from the database.
func (*PostgresqlDatabase) SelectUserByEmail ¶
func (db *PostgresqlDatabase) SelectUserByEmail(email string) (*models.User, error)
SelectUserByEmail selects a user with given email
func (*PostgresqlDatabase) SelectUserByID ¶
func (db *PostgresqlDatabase) SelectUserByID(id int) (*models.User, error)
SelectUserByID selects a user with given ID from the database.
func (*PostgresqlDatabase) UpdateBook ¶
func (db *PostgresqlDatabase) UpdateBook(id int, book *models.Book) error
UpdateBook updates a book with given ID in the database.