data

package
v0.0.0-...-f3899e4 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqliteInsertBookCommand           = "INSERT INTO Books (title, published, pages, rating) VALUES (?, ?, ?, ?) RETURNING id, created_at, version"
	SqliteInsertGenreCommand          = "INSERT INTO Genres (book_id, genre_name) VALUES (?, ?) RETURNING id"
	SqliteSelectBookQuery             = "SELECT id, created_at, title, published, pages, rating, version FROM Books WHERE id = ?"
	SqliteSelectAllBooksQuery         = "SELECT id, created_at, title, published, pages, rating, version FROM Books ORDER BY id"
	SqliteSelectGenresByBookIdCommand = "SELECT genre_name FROM Genres Where book_id = ?"
	SqliteUpdateBookCommand           = `` /* 139-byte string literal not displayed */

	SqliteDeleteBookCommand = "DELETE FROM Books WHERE id = ?"
)

Variables

View Source
var (
	NotFoundError = errors.New("error")
)

Functions

This section is empty.

Types

type Book

type Book struct {
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"-"`
	Title     string    `json:"title"`
	Published int       `json:"published,omitempty"`
	Pages     int       `json:"pages,omitempty"`
	Genres    []string  `json:"genres,omitempty"`
	Rating    float64   `json:"rating,omitempty"`
	Version   int32     `json:"-"`
}

type Repository

type Repository interface {
	Migrate() error
	Ping() error
	InsertOne(title string, published int, pages int, rating float64, genres []string) (*Book, error)
	FindById(id int64, includeGenres bool) (*Book, error)
	FindAll(includeGenres bool) ([]*Book, error)
	LoadGenres(book *Book) ([]string, error)
	Update(book *Book) error
	DeleteById(id int64) error
	Close() error
}

func NewSqliteRepository

func NewSqliteRepository(dsn string) (Repository, error)

type SqliteRepository

type SqliteRepository struct {
	// contains filtered or unexported fields
}

func (*SqliteRepository) Close

func (r *SqliteRepository) Close() error

func (*SqliteRepository) DeleteById

func (r *SqliteRepository) DeleteById(id int64) error

func (*SqliteRepository) FindAll

func (r *SqliteRepository) FindAll(includeGenres bool) ([]*Book, error)

func (*SqliteRepository) FindById

func (r *SqliteRepository) FindById(id int64, includeGenres bool) (*Book, error)

func (*SqliteRepository) InsertOne

func (r *SqliteRepository) InsertOne(title string, published int, pages int, rating float64, genres []string) (*Book, error)

func (*SqliteRepository) LoadGenres

func (r *SqliteRepository) LoadGenres(book *Book) ([]string, error)

func (*SqliteRepository) Migrate

func (r *SqliteRepository) Migrate() error

func (*SqliteRepository) Ping

func (r *SqliteRepository) Ping() error

func (*SqliteRepository) Update

func (r *SqliteRepository) Update(book *Book) error

Jump to

Keyboard shortcuts

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