db

package
v0.0.0-...-a602de9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate(_ context.Context, dbConn *sql.DB, up bool) error

func ConnnectionString

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

ConnnectionString returns a DSN.

Types

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 models.IngredientUnit) (int64, error)

func (*Client) AddRecipeToMeal

func (c *Client) AddRecipeToMeal(ctx context.Context, mealId, recipeId string, m *float64, tx *sql.Tx) error

func (*Client) AssociateFoodWithIngredient

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

func (*Client) DB

func (c *Client) DB() *sqlx.DB

func (*Client) DoesNotionImageExist

func (c *Client) DoesNotionImageExist(ctx context.Context, blockID string) (exists bool, err error)

func (*Client) GetAlbums

func (c *Client) GetAlbums(ctx context.Context) (models.GphotosAlbumSlice, error)

func (*Client) GetAllMeals

func (c *Client) GetAllMeals(ctx context.Context) (Meals, 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) GetMealsWithRecipe

func (c *Client) GetMealsWithRecipe(ctx context.Context, recipeID string) (Meals, error)

func (*Client) GetNotionPhotosForMeal

func (c *Client) GetNotionPhotosForMeal(ctx context.Context, meal string) (models.NotionImageSlice, error)

func (*Client) GetPhotos

func (c *Client) GetPhotos(ctx context.Context) (models.GphotosPhotoSlice, error)

func (*Client) GetPhotosForMeal

func (c *Client) GetPhotosForMeal(ctx context.Context, meal string) (models.GphotosPhotoSlice, error)

func (*Client) MealIDInRange

func (c *Client) MealIDInRange(ctx context.Context, t time.Time, name string, tx *sql.Tx) (mealID string, err error)

func (*Client) MergeIngredients

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

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

func (*Client) RecipeIngredientDependencies

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

func (*Client) SaveImage

func (c *Client) SaveImage(ctx context.Context, tx *sql.Tx, items ...*models.Image) error

func (*Client) SetKV

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

func (*Client) SyncMealsFromGPhotos

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

func (*Client) SyncNotionMealFromNotionRecipe

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

func (*Client) UpsertNotionImages

func (c *Client) UpsertNotionImages(ctx context.Context, tx *sql.Tx, photos models.NotionImageSlice) error

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 NotionRecipeMeta

type NotionRecipeMeta struct {
	Tags []string `json:"tags"`
}

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"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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