database

package
v0.0.0-...-e4064bc Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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 NewMockDatabase

func NewMockDatabase() Database

NewMockDatabase creates a new MockDatabase.

func NewPostgresqlDatabase

func NewPostgresqlDatabase(connectionString string) (Database, error)

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) Close

func (db *MockDatabase) Close()

Close closes the database connection.

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.

Jump to

Keyboard shortcuts

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