database

package
v0.0.0-...-abdde1b Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateEntry = errors.New("already exists")
View Source
var ErrNoRows = sql.ErrNoRows

Functions

This section is empty.

Types

type Database

type Database struct {
	Handle     *sql.DB
	Recipe     *RecipeTable
	Ingredient *IngredientTable
	User       *UserTable
}

func New

func New(c config.Database) (*Database, error)

type Ingredient

type Ingredient struct {
	ID        int64
	RecipeID  int64
	Name      string
	CreatedAt string
	UpdatedAt string
}

Ingredient entity

type IngredientTable

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

RecipeTable object

func NewIngredientTable

func NewIngredientTable(db *sql.DB) *IngredientTable

NewIngredientTable create a IngredientTable object

func (*IngredientTable) Get

func (it *IngredientTable) Get(id uint64) (*Ingredient, error)

Get a recipe by id

type Ingredients

type Ingredients []Ingredient

Ingredients slice or recipe ingredient entities

type Recipe

type Recipe struct {
	ID          int64
	Title       string
	URL         string
	Thumbnail   string
	Ingredients Ingredients
	CreatedAt   string
	UpdatedAt   string
}

Recipe entity

type RecipeFilters

type RecipeFilters struct {
	Term        string
	Ingredients []string
}

RecipeFilters object

type RecipeTable

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

RecipeTable object

func NewRecipeTable

func NewRecipeTable(db *sql.DB) *RecipeTable

NewRecipeTable object

func (*RecipeTable) Get

func (rt *RecipeTable) Get(id uint64) (*Recipe, error)

Get a recipe by id

func (*RecipeTable) Insert

func (rt *RecipeTable) Insert(recipe Recipe) (int64, error)

Insert a new recipe, returns inserted recipe id

func (*RecipeTable) Paginate

func (rt *RecipeTable) Paginate(page uint64, filters *RecipeFilters) (Recipes, int64, error)

Paginate get paginated recipes

type Recipes

type Recipes []Recipe

Recipes slice or recipe entities

type User

type User struct {
	ID        int64
	Username  string
	Password  string `json:"-"`
	FullName  string
	Email     string
	Active    bool
	CreatedAt string
	UpdatedAt string
}

User entity

type UserTable

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

UserTable object

func NewUserTable

func NewUserTable(db *sql.DB) *UserTable

NewUserTable object

func (*UserTable) Get

func (ut *UserTable) Get(id uint64) (*User, error)

Get user by id

func (*UserTable) GetByUsername

func (ut *UserTable) GetByUsername(uName string) (*User, error)

Get user by id

func (*UserTable) Insert

func (ut *UserTable) Insert(u User) (int64, error)

Insert a new user and return a unique identifier

type Users

type Users []User

Users slice or user entities

Jump to

Keyboard shortcuts

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