db

package
v0.0.0-...-60af178 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnnectionString

func ConnnectionString(host, user, password, dbname string, port int64) string

ConnnectionString returns a DSN.

Types

type BrandedFood

type BrandedFood struct {
	BrandOwner          *string `db:"brand_owner"`
	Ingredients         *string `db:"ingredients"`
	ServingSize         float64 `db:"serving_size"`
	ServingSizeUnit     string  `db:"serving_size_unit"`
	HouseholdServing    *string `db:"household_serving_fulltext"`
	BrandedFoodCategory *string `db:"branded_food_category"`
}

type Client

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

Client is a database client

func New

func New(dbConn *sql.DB) (*Client, error)

New creates a new Client.

func (*Client) AddIngredientUnit

func (c *Client) AddIngredientUnit(ctx context.Context, m IngredientUnitMapping) error

func (*Client) AddRecipeToMeal

func (c *Client) AddRecipeToMeal(ctx context.Context, mealId, recipeId string, multiplier float64) error

func (*Client) AssignIds

func (c *Client) AssignIds(ctx context.Context, r *RecipeDetail) error

AssignIds adds ids where missing.

func (*Client) AssociateFoodWithIngredient

func (c *Client) AssociateFoodWithIngredient(ctx context.Context, ingredient string, fdcId int) error

func (*Client) FillFdcIdFromParentIfNcessary

func (c *Client) FillFdcIdFromParentIfNcessary(ctx context.Context, i *Ingredient) error

func (*Client) FoodsByIds

func (c *Client) FoodsByIds(ctx context.Context, ids []int) ([]Food, uint64, error)

func (*Client) GetAlbums

func (c *Client) GetAlbums(ctx context.Context) ([]GAlbum, error)

func (*Client) GetAllMeals

func (c *Client) GetAllMeals(ctx context.Context) (Meals, error)

func (*Client) GetAllPhotos

func (c *Client) GetAllPhotos(ctx context.Context) (map[string]Photo, error)

func (*Client) GetBrandInfo

func (c *Client) GetBrandInfo(ctx context.Context, fdcID int) (*BrandedFood, error)

func (*Client) GetCategory

func (c *Client) GetCategory(ctx context.Context, categoryID int64) (*FoodCategory, error)

func (*Client) GetFood

func (c *Client) GetFood(ctx context.Context, fdcID int) (*Food, error)

func (*Client) GetFoodNutrients

func (c *Client) GetFoodNutrients(ctx context.Context, fdcID ...int) (FoodNutrients, error)

func (*Client) GetFoodPortions

func (c *Client) GetFoodPortions(ctx context.Context, fdcId ...int) (FoodPortions, error)

func (*Client) GetIngredientById

func (c *Client) GetIngredientById(ctx context.Context, id string) (*Ingredient, error)

GetIngredientById finds an ingredient.

func (*Client) GetIngredientUnits

func (c *Client) GetIngredientUnits(ctx context.Context, ingredient []string) (map[string][]IngredientUnitMapping, error)

func (*Client) GetIngredients

func (c *Client) GetIngredients(ctx context.Context, name string, ids []string, opts ...SearchOption) ([]Ingredient, uint64, error)

GetIngredients returns all ingredients.

func (*Client) GetIngrientsSameAs

func (c *Client) GetIngrientsSameAs(ctx context.Context, parent ...string) (Ingredients, uint64, error)

func (*Client) GetKV

func (c *Client) GetKV(ctx context.Context, key string) (string, error)

func (*Client) GetMealById

func (c *Client) GetMealById(ctx context.Context, id string) (*Meal, error)

func (*Client) GetMealRecipes

func (c *Client) GetMealRecipes(ctx context.Context, mealID ...string) (MealRecipes, error)

func (*Client) GetNutrients

func (c *Client) GetNutrients(ctx context.Context, nutrientID ...int) (Nutrients, error)

func (*Client) GetPhotos

func (c *Client) GetPhotos(ctx context.Context) ([]Photo, error)

func (*Client) GetPhotosForMeal

func (c *Client) GetPhotosForMeal(ctx context.Context, meal string) ([]Photo, error)

func (*Client) GetRecipeDetailByIdFull

func (c *Client) GetRecipeDetailByIdFull(ctx context.Context, detailId string) (*RecipeDetail, error)

GetRecipeDetailByIdFull gets a recipe by Id, with all dependencies.

func (*Client) GetRecipeDetailSections

func (c *Client) GetRecipeDetailSections(ctx context.Context, detailID string) ([]Section, error)

GetRecipeDetailSections finds the sections.

func (*Client) GetRecipeDetailWhere

func (c *Client) GetRecipeDetailWhere(ctx context.Context, eq sq.Sqlizer) (RecipeDetails, error)

GetRecipeById gets a recipe by name, shallowly.

func (*Client) GetRecipeDetailsWithIngredient

func (c *Client) GetRecipeDetailsWithIngredient(ctx context.Context, ingredient ...string) (RecipeDetails, error)

GetRecipeDetailsWithIngredient gets all recipes with an ingredeitn todo: consolidate into getrecipes

func (*Client) GetRecipes

func (c *Client) GetRecipes(ctx context.Context, searchQuery string, opts ...SearchOption) ([]Recipe, uint64, error)

func (*Client) GetRecipesDetails

func (c *Client) GetRecipesDetails(ctx context.Context, searchQuery string, opts ...SearchOption) ([]RecipeDetail, uint64, error)

GetRecipes returns all recipes, shallowly.

func (*Client) GetSectionIngredients

func (c *Client) GetSectionIngredients(ctx context.Context, sectionId []string) (map[string][]SectionIngredient, error)

GetSectionIngredients finds the ingredients for a section.

func (*Client) GetSectionInstructions

func (c *Client) GetSectionInstructions(ctx context.Context, sectionId []string) (map[string][]SectionInstruction, error)

GetSectionInstructions finds the instructions for a section.

func (*Client) IngredientByName

func (c *Client) IngredientByName(ctx context.Context, name string) (*Ingredient, error)

IngredientByName retrieves an ingredient by name, creating it if it does not exist.

func (*Client) IngredientToRecipe

func (c *Client) IngredientToRecipe(ctx context.Context, ingredientID string) (*RecipeDetail, error)

func (*Client) InsertRecipe

func (c *Client) InsertRecipe(ctx context.Context, r *RecipeDetail) (*RecipeDetail, error)

InsertRecipe inserts a recipe.

func (*Client) MergeIngredients

func (c *Client) MergeIngredients(ctx context.Context, ingredientID string, ids []string) error

MergeIngredients sets the provided ingredients `same_as` to the first one. TODO: prevent cyclic loop?

func (*Client) RecipeIngredientDependencies

func (c *Client) RecipeIngredientDependencies(ctx context.Context) ([]RecipeIngredientDependency, error)

func (*Client) SearchFoods

func (c *Client) SearchFoods(ctx context.Context, searchQuery string, dataType []string, foodCategoryID *int, opts ...SearchOption) ([]Food, uint64, error)

func (*Client) SetKV

func (c *Client) SetKV(ctx context.Context, key string, json string) error

func (*Client) SyncMealsFromPhotos

func (c *Client) SyncMealsFromPhotos(ctx context.Context) error

func (*Client) UpsertPhotos

func (c *Client) UpsertPhotos(ctx context.Context, photos []Photo) error

type Food

type Food struct {
	Description string   `db:"description"`
	DataType    string   `db:"data_type"`
	FdcID       int      `db:"fdc_id"`
	CategoryID  zero.Int `db:"food_category_id"`
}

type FoodCategory

type FoodCategory struct {
	Code        string `json:"code"`
	Description string `json:"description"`
}

type FoodNutrient

type FoodNutrient struct {
	FdcID      int      `db:"fdc_id"`
	NutrientID int      `json:"nutrient" db:"nutrient_id"`
	Amount     float64  `json:"amount" db:"amount"`
	DataPoints zero.Int `json:"data_points" db:"data_points"`
}

type FoodNutrients

type FoodNutrients []FoodNutrient

type FoodPortion

type FoodPortion struct {
	Id                 int         `db:"id"`
	FdcID              int         `db:"fdc_id"`
	Amount             zero.Float  `db:"amount"`
	GramWeight         float64     `db:"gram_weight"`
	Modifier           zero.String `db:"modifier"`
	PortionDescription zero.String `db:"portion_description"`
}

type FoodPortions

type FoodPortions []FoodPortion

func (FoodPortions) ByFdcId

func (r FoodPortions) ByFdcId() map[int][]FoodPortion

type Foods

type Foods []Food

type GAlbum

type GAlbum struct {
	ID      string `db:"id"`
	Usecase string `db:"usecase"`
}

type Ingredient

type Ingredient struct {
	Id     string      `json:"id"`
	Name   string      `json:"name"`
	FdcID  zero.Int    `db:"fdc_id"`
	SameAs zero.String `db:"same_as"`
}

Ingredient is a globally-scoped ingredient

type IngredientUnitMapping

type IngredientUnitMapping struct {
	Id           int64   `db:"id"`
	IngredientId string  `db:"ingredient"`
	UnitA        string  `db:"unit_a"`
	AmountA      float64 `db:"amount_a"`
	UnitB        string  `db:"unit_b"`
	AmountB      float64 `db:"amount_b"`
	Source       string  `db:"source"`
}

type Ingredients

type Ingredients []Ingredient

func (Ingredients) BySameAs

func (r Ingredients) BySameAs() map[string][]Ingredient

func (Ingredients) IdsBySameAs

func (r Ingredients) IdsBySameAs(id string) []string

type Meal

type Meal struct {
	ID    string    `db:"id"`
	Name  string    `db:"name"`
	AteAt time.Time `db:"ate_at"`
}

type MealRecipe

type MealRecipe struct {
	MealID     string  `db:"meal_id"`
	RecipeID   string  `db:"recipe_id"`
	Multiplier float64 `db:"multiplier"`
}

type MealRecipes

type MealRecipes []MealRecipe

func (MealRecipes) ByMealID

func (r MealRecipes) ByMealID() map[string][]MealRecipe

func (MealRecipes) RecipeIDs

func (r MealRecipes) RecipeIDs() []string

type Meals

type Meals []Meal

func (Meals) MealIDs

func (r Meals) MealIDs() []string

type Nutrient

type Nutrient struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	UnitName string `json:"unitName"`
}

type Nutrients

type Nutrients []Nutrient

func (Nutrients) ById

func (r Nutrients) ById() map[int]Nutrient

type Photo

type Photo struct {
	AlbumID  string      `db:"album_id"`
	PhotoID  string      `db:"id"`
	Created  time.Time   `db:"creation_time"`
	Seen     time.Time   `db:"last_seen"`
	BlurHash zero.String `db:"blur_hash"`
}

type Recipe

type Recipe struct {
	Id     string `db:"id"`
	Detail RecipeDetail
}

RecipeDetail represents a recipe

type RecipeDetail

type RecipeDetail struct {
	Id            string      `db:"id"`
	RecipeId      string      `db:"recipe"`
	Name          string      `db:"name"`
	Equipment     zero.String `db:"equipment"`
	Source        zero.String `db:"source"`
	Servings      zero.Int    `db:"servings"`
	Quantity      zero.Int    `db:"quantity"`
	Unit          zero.String `db:"unit"`
	Version       int64       `db:"version"`
	LatestVersion bool        `db:"is_latest_version"`
	Sections      []Section
	Ingredient    zero.String `db:"ingredient"` // sometimes, from FK
}

RecipeDetail represents a recipe

type RecipeDetails

type RecipeDetails []RecipeDetail

func (RecipeDetails) ByDetailId

func (r RecipeDetails) ByDetailId() map[string]RecipeDetail

func (RecipeDetails) ByIngredientId

func (r RecipeDetails) ByIngredientId() map[string][]RecipeDetail

func (RecipeDetails) ByRecipeId

func (r RecipeDetails) ByRecipeId() map[string][]RecipeDetail

func (RecipeDetails) First

func (r RecipeDetails) First() *RecipeDetail

type RecipeIngredientDependency

type RecipeIngredientDependency struct {
	RecipeName     string `db:"recipe_name"`
	RecipeId       string `db:"recipe_id"`
	IngredientName string `db:"ingredient_name"`
	IngredientId   string `db:"ingredient_id"`
	IngredientKind string `db:"ingredient_kind"`
}

type SearchOption

type SearchOption func(*SearchQuery)

func WithLimit

func WithLimit(limit uint64) SearchOption

func WithOffset

func WithOffset(offset uint64) SearchOption

type SearchQuery

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

type Section

type Section struct {
	Id             string   `db:"id"`
	RecipeDetailId string   `db:"recipe_detail"`
	TimeRange      string   `db:"duration_timerange"`
	Sort           zero.Int `db:"sort"`
	Ingredients    []SectionIngredient
	Instructions   []SectionInstruction
}

Section represents a Section

type SectionIngredient

type SectionIngredient struct {
	Id        string      `db:"id"`
	SectionId string      `db:"section"`
	Sort      zero.Int    `db:"sort"`
	Grams     zero.Float  `db:"grams"`
	Amount    zero.Float  `db:"amount"`
	Unit      zero.String `db:"unit"`
	Adjective zero.String `db:"adjective"`
	Optional  zero.Bool   `db:"optional"`
	Original  zero.String `db:"original"`
	SubsFor   zero.String `db:"substitutes_for"`

	// one of the following is required for get and update:
	RecipeId     zero.String `db:"recipe"`
	IngredientId zero.String `db:"ingredient"`

	// one of these is populated via gets
	RawRecipe     *RecipeDetail
	RawIngredient *Ingredient
}

SectionIngredient is a foo

type SectionInstruction

type SectionInstruction struct {
	Id          string   `db:"id"`
	Sort        zero.Int `db:"sort"`
	Instruction string   `db:"instruction"`
	SectionId   string   `db:"section"`
}

SectionInstruction represents a SectionInstruction

Jump to

Keyboard shortcuts

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