statements

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package statements provides SQLite statements for the service.

Index

Constants

View Source
const DeleteAuthToken = `
	DELETE
	FROM auth_tokens
	WHERE user_id = ?`

DeleteAuthToken removes the authentication token associated with the user id from the database.

View Source
const DeleteCookbook = `
	DELETE
	FROM cookbooks
	WHERE id = ?
		AND user_id = ?`

DeleteCookbook deletes a user's cookbook.

View Source
const DeleteCookbookRecipe = `` /* 128-byte string literal not displayed */

DeleteCookbookRecipe deletes a recipe from a user's cookbook.

View Source
const DeleteCookbooks = `
	DELETE
	FROM cookbooks
	WHERE user_id = ?`

DeleteCookbooks deletes all the user's cookbooks.

View Source
const DeleteRecipe = `` /* 133-byte string literal not displayed */

DeleteRecipe deletes a user's recipe and the recipe itself.

View Source
const DeleteRecipeIngredients = `
	DELETE
	FROM ingredient_recipe
	WHERE recipe_id = ?`

DeleteRecipeIngredients deletes all ingredients from a recipe.

View Source
const DeleteRecipeInstructions = `
	DELETE
	FROM instruction_recipe
	WHERE recipe_id = ?`

DeleteRecipeInstructions deletes all instructions from a recipe.

View Source
const DeleteRecipesUser = `
	DELETE
	FROM recipes
	WHERE id IN (SELECT recipe_id
				 FROM user_recipe
				 WHERE user_id = ?)`

DeleteRecipesUser deletes the user's recipes.

View Source
const DeleteUser = `
	DELETE
	FROM users
	WHERE id = ?`

DeleteUser deletes a user from the users table.

View Source
const InsertAuthToken = `
	INSERT INTO auth_tokens (selector, hash_validator, user_id)
	VALUES (?, ?, ?)`

InsertAuthToken is the query to add an authentication token to the database.

View Source
const InsertCategory = `
	INSERT INTO categories (name)
	VALUES (?)
	ON CONFLICT DO UPDATE SET name = EXCLUDED.name
	RETURNING id`

InsertCategory is the query to add a category to the database.

View Source
const InsertCookbook = `
	INSERT INTO cookbooks (title, image, user_id) 
	VALUES (?, ?, ?)
	RETURNING id`

InsertCookbook is the query to add a cookbook to the database.

View Source
const InsertCookbookRecipe = `` /* 241-byte string literal not displayed */

InsertCookbookRecipe is the query to add a recipe to a cookbook.

View Source
const InsertCuisine = `
	INSERT OR IGNORE INTO cuisines (name)
	VALUES (?)`

InsertCuisine is the query to add a cuisine to the database

View Source
const InsertIngredient = `
	INSERT INTO ingredients (name)
	VALUES (?)
	ON CONFLICT (name) DO UPDATE SET name = EXCLUDED.name
	RETURNING id`

InsertIngredient is the query to add an ingredient.

View Source
const InsertInstruction = `
	INSERT INTO instructions (name)
	VALUES (?)
	ON CONFLICT (name)
		DO UPDATE SET name = EXCLUDED.name
	RETURNING id`

InsertInstruction is the query to add an instruction.

View Source
const InsertKeyword = `
	INSERT INTO keywords (name)
	VALUES (?)
	ON CONFLICT (name)
		DO UPDATE SET name = EXCLUDED.name
	RETURNING id`

InsertKeyword is the query to add a keyword.

View Source
const InsertNutrition = `` /* 215-byte string literal not displayed */

InsertNutrition is the query to add a nutrition facts.

View Source
const InsertRecipe = `
	INSERT INTO recipes (name, description, image, yield, url)
	VALUES (?, ?, ?, ?, ?)
	RETURNING id`

InsertRecipe is the query to add a recipe to the database.

View Source
const InsertRecipeCategory = `
	INSERT INTO category_recipe (category_id, recipe_id)
	VALUES (?, ?)`

InsertRecipeCategory associates a recipe with a category.

View Source
const InsertRecipeCuisine = `
	INSERT INTO cuisine_recipe (cuisine_id, recipe_id)
	VALUES (?, ?)`

InsertRecipeCuisine associates a recipe with a category.

View Source
const InsertRecipeIngredient = `
	INSERT INTO ingredient_recipe (ingredient_id, recipe_id, ingredient_order)
	VALUES (?, ?, ?)`

InsertRecipeIngredient is the query to associate a recipe with an ingredient.

View Source
const InsertRecipeInstruction = `
	INSERT INTO instruction_recipe (instruction_id, recipe_id, instruction_order)
	VALUES (?, ?, ?)`

InsertRecipeInstruction is the query to associate a recipe with an instruction.

View Source
const InsertRecipeKeyword = `
	INSERT INTO keyword_recipe (keyword_id, recipe_id)
	VALUES (?, ?)`

InsertRecipeKeyword is the query to associate a recipe with a keyword.

View Source
const InsertRecipeShadow = `
	INSERT OR REPLACE INTO shadow_last_inserted_recipe (row, id, name, description, source)
	VALUES (1, ?, ?, ?, ?)`

InsertRecipeShadow is the query to insert a recipe into the shadow table.

View Source
const InsertRecipeTime = `
	INSERT INTO time_recipe (time_id, recipe_id)
	VALUES (?, ?)`

InsertRecipeTime is the query to associate a recipe with a time.

View Source
const InsertRecipeTool = `
	INSERT INTO tool_recipe (tool_id, recipe_id)
	VALUES (?, ?)`

InsertRecipeTool is the query to associate a recipe with a tool.

View Source
const InsertReport = `
	INSERT INTO reports (report_type, created_at, exec_time_ns, user_id) 
	VALUES (?, ?, ?, ?)
	RETURNING id`

InsertReport is the query to add a report without logs into the database

View Source
const InsertReportLog = `
	INSERT INTO report_logs (report_id, title, success, error_reason) 
	VALUES (?, ?, ?, ?)`

InsertReportLog is the query to add a log to a report.

View Source
const InsertShareLink = `
	INSERT INTO share_recipes (link, recipe_id, user_id)
	VALUES (?, ?, ?)
	ON CONFLICT (link, recipe_id) DO NOTHING`

InsertShareLink is the query to add a recipe share link to the database.

View Source
const InsertShareLinkCookbook = `
	INSERT INTO share_cookbooks (link, cookbook_id, user_id)
	VALUES (?, ?, ?)
	ON CONFLICT (link, cookbook_id) DO NOTHING`

InsertShareLinkCookbook is the query to add a cookbook share link to the database.

View Source
const InsertTimes = `` /* 223-byte string literal not displayed */

InsertTimes is the query to add kitchen times.

View Source
const InsertTool = `
	INSERT INTO tools (name)
	VALUES (?)
	ON CONFLICT (name)
		DO UPDATE SET name = EXCLUDED.name
	RETURNING id`

InsertTool is the query to add a tool.

View Source
const InsertUser = `
	INSERT INTO users (email, hashed_password)
	VALUES (?, ?)
	RETURNING id`

InsertUser is the query to add a user to the database.

View Source
const InsertUserCategory = `
	INSERT OR IGNORE INTO user_category (user_id, category_id)
	VALUES (?, ?)`

InsertUserCategory is the query to associate a category with a user.

View Source
const InsertUserRecipe = `
	INSERT INTO user_recipe (user_id, recipe_id)
	VALUES (?, ?)`

InsertUserRecipe is the query to associate a recipe with a user.

View Source
const IsRecipeForUserExist = `` /* 251-byte string literal not displayed */

IsRecipeForUserExist checks whether the recipe belongs to the given user.

View Source
const SelectAppInfo = `
	SELECT is_update_available, updated_at, update_last_checked_at
	FROM app
	WHERE id = 1`

SelectAppInfo fetches general information on the application.

View Source
const SelectAuthToken = `
	SELECT id, hash_validator, expires, user_id
	FROM auth_tokens
	WHERE selector = ?
	AND expires > unixepoch('now')`

SelectAuthToken fetches a non-expired auth token by the selector.

View Source
const SelectCategories = `
	SELECT c.name
	FROM user_category AS uc
	JOIN categories c ON c.id = uc.category_id
	WHERE uc.user_id = ?
	ORDER BY name`

SelectCategories fetches a user's recipe categories.

View Source
const SelectCookbook = `
	SELECT c.id, c.title, c.image, c.count
	FROM cookbooks AS c
	WHERE id = ?
		AND user_id = ?`

SelectCookbook gets a user's cookbook by cookbook ID.

View Source
const SelectCookbookExists = `
	SELECT EXISTS (SELECT c.id
				   FROM cookbooks AS c
				   WHERE id = ?
					 AND user_id = ?)`

SelectCookbookExists verifies whether the cookbook belongs to the user.

View Source
const SelectCookbookRecipe = baseSelectRecipe + `
	JOIN cookbook_recipes AS cr ON recipes.id = cr.recipe_id
	WHERE cr.cookbook_id = ?
		AND cr.recipe_id = ?
	GROUP BY recipes.id`

SelectCookbookRecipe fetches a recipe from a cookbook.

View Source
const SelectCookbookRecipeExists = `` /* 186-byte string literal not displayed */

SelectCookbookRecipeExists verifies whether the recipe and the cookbook belongs to a user.

View Source
const SelectCookbookRecipes = baseSelectRecipe + `
	JOIN cookbook_recipes AS cr ON recipes.id = cr.recipe_id
	WHERE cr.cookbook_id = ?
	GROUP BY recipes.id
	ORDER BY cr.order_index`

SelectCookbookRecipes fetches the recipes in a cookbook.

View Source
const SelectCookbookShared = `
	SELECT cookbook_id, user_id
	FROM share_cookbooks
	WHERE link = ?`

SelectCookbookShared gets a shared cookbook link.

View Source
const SelectCookbookSharedLink = `
	SELECT link 
	FROM share_cookbooks
	WHERE cookbook_id = ?
		AND user_id = ?`

SelectCookbookSharedLink gets the link of a shared cookbook.

View Source
const SelectCookbookUser = `
	SELECT user_id
	FROM cookbooks
	WHERE id = ?`

SelectCookbookUser gets the ID of the user who has the cookbook ID.

View Source
const SelectCookbooksShared = `
	SELECT link, cookbook_id
	FROM share_cookbooks
	WHERE user_id = ?`

SelectCookbooksShared gets the user's shared cookbooks.

View Source
const SelectCookbooksUser = `
	SELECT id, title, image, count
	FROM cookbooks
	WHERE user_id = 2`

SelectCookbooksUser gets all cookbooks belonging to the user.

View Source
const SelectCountWebsites = `
	SELECT COUNT(id)
	FROM websites`

SelectCountWebsites fetches the number of supported websites.

View Source
const SelectCounts = `
	SELECT cookbooks, recipes
	FROM counts 
	WHERE user_id = ?`

SelectCounts gets the number of recipes and cookbooks belonging to the user.

View Source
const SelectCuisineID = `
	SELECT id 
	FROM cuisines 
	WHERE name = ?`

SelectCuisineID gets the ID of the specified cuisine.

View Source
const SelectDistinctImages = `
	SELECT DISTINCT image
	FROM recipes
	UNION
	SELECT DISTINCT image
	FROM cookbooks`

SelectDistinctImages gets all distinct image UUIDs from the recipes table.

View Source
const SelectMeasurementSystems = `` /* 279-byte string literal not displayed */

SelectMeasurementSystems fetches the units systems along with the user's selected system and settings.

View Source
const SelectRecipe = baseSelectRecipe + `
	INNER JOIN user_recipe AS ur ON ur.recipe_id = recipes.id
	WHERE recipes.id = ?
		AND ur.user_id = ?
	LIMIT 1`

SelectRecipe fetches a user's recipe.

View Source
const SelectRecipeShared = `
	SELECT recipe_id, user_id
	FROM share_recipes
	WHERE link = ?`

SelectRecipeShared checks whether the recipe is shared.

View Source
const SelectRecipeUser = `
	SELECT user_id
	FROM user_recipe
	WHERE recipe_id = ?`

SelectRecipeUser fetches the user whose recipe belongs to.

View Source
const SelectRecipes = `
	WITh results AS (
		SELECT recipe_id, name, description,image,created_at,category,row_num FROM (
			` + baseSelectSearchRecipe + `
			WHERE user_recipe.user_id = ?
			GROUP BY recipes.id
		)
	) SELECT * FROM results WHERE row_num BETWEEN (?-1)*` + templates.ResultsPerPageStr + `+1 AND (?-1)*` + templates.ResultsPerPageStr + `+` + templates.ResultsPerPageStr

SelectRecipes fetches a chunk of the user's recipes.

View Source
const SelectRecipesAll = baseSelectRecipe + `
	WHERE recipes.id IN (SELECT recipe_id FROM user_recipe WHERE user_id = ?)
	GROUP BY recipes.id`

SelectRecipesAll fetches all the user's recipes.

View Source
const SelectRecipesShared = `
	SELECT link, recipe_id
	FROM share_recipes
	WHERE user_id = ?`

SelectRecipesShared gets the recipes the user shared.

View Source
const SelectReport = `` /* 132-byte string literal not displayed */

SelectReport fetches the report of the given ID belonging to the user.

View Source
const SelectReports = `` /* 231-byte string literal not displayed */

SelectReports fetches the import reports for the user.

View Source
const SelectUserEmail = `
	SELECT email
	FROM users
	WHERE id = ?`

SelectUserEmail fetches the user's email from their id.

View Source
const SelectUserExist = `
	SELECT EXISTS(
		SELECT 1
		FROM users
		WHERE email = ?
	)`

SelectUserExist checks whether the user is present.

View Source
const SelectUserID = `
	SELECT id
	FROM users
	WHERE email = ?`

SelectUserID fetches the user's id from their email.

View Source
const SelectUserOne = `
	SELECT id
	FROM users
	WHERE id = 1`

SelectUserOne fetches the first user.

View Source
const SelectUserPassword = `
	SELECT id, hashed_password
	FROM users
	WHERE email = ?`

SelectUserPassword fetches the user's password for verification purposes.

View Source
const SelectUserPasswordByID = `
	SELECT hashed_password
	FROM users
	WHERE id = ?`

SelectUserPasswordByID fetches the user's hashed password by their id.

View Source
const SelectUserSettings = `` /* 177-byte string literal not displayed */

SelectUserSettings fetchs a user's settings.

View Source
const SelectUsers = `
	SELECT id, email 
	FROM users
	ORDER BY id`

SelectUsers fetches all users from the database.

View Source
const SelectWebsites = `
	SELECT id, host, url
	FROM websites`

SelectWebsites fetches all websites from the database.

View Source
const UpdateCalculateNutrition = `
	UPDATE user_settings
	SET calculate_nutrition = ?
	WHERE user_id = ?`

UpdateCalculateNutrition is the query to update the user's calculate nutrition setting.

View Source
const UpdateConvertAutomatically = `
	UPDATE user_settings
	SET convert_automatically = ?
	WHERE user_id = ?`

UpdateConvertAutomatically is the query to update the user's convert automatically setting.

View Source
const UpdateCookbookImage = `
UPDATE cookbooks
	SET image = ?
	WHERE user_id = ?
	 AND id = ?`

UpdateCookbookImage is the query to update the image of a user's cookbook.

View Source
const UpdateCookbookRecipesReorder = `
	UPDATE cookbook_recipes
	SET order_index = ?
	WHERE cookbook_id = ?
		AND recipe_id = ?`

UpdateCookbookRecipesReorder is the query to reorder recipes in a cookbook.

View Source
const UpdateIsConfirmed = `
	UPDATE users
	SET is_confirmed = 1
	WHERE id = ?`

UpdateIsConfirmed sets the user's account confirmed to true.

View Source
const UpdateIsUpdateAvailable = `
	UPDATE app
	SET is_update_available = ?
	WHERE id = 1
	RETURNING updated_at, update_last_checked_at`

UpdateIsUpdateAvailable is the query to flag whether a release update is available.

View Source
const UpdateMeasurementSystem = `
	UPDATE user_settings
	SET measurement_system_id = (SELECT id FROM measurement_systems WHERE name = ?)
	WHERE user_id = ?`

UpdateMeasurementSystem is the query to update the user's preferred measurement system.

View Source
const UpdateNutrition = `` /* 280-byte string literal not displayed */

UpdateNutrition updates the recipe's nutrition.

View Source
const UpdatePassword = `
	UPDATE users
	SET hashed_password = ?, updated_at = CURRENT_TIMESTAMP 
	WHERE id = ?`

UpdatePassword sets the user's new password.

View Source
const UpdateRecipeCategory = `
	UPDATE category_recipe
	SET category_id = ?
	WHERE id = ?`

UpdateRecipeCategory is the query to update a recipe's category.

View Source
const UpdateRecipeDescription = `
	UPDATE recipes
	SET description = ?
	WHERE id = ?`

UpdateRecipeDescription is the query to update a recipe's description.

View Source
const UpdateRecipeIngredient = `` /* 137-byte string literal not displayed */

UpdateRecipeIngredient is the query to update a recipe's ingredient.

View Source
const UpdateRecipeInstruction = `` /* 141-byte string literal not displayed */

UpdateRecipeInstruction is the query to update a recipe's instruction.

View Source
const UpdateRecipeTimes = `
	UPDATE time_recipe
	SET time_id = ?
	WHERE recipe_id = ?`

UpdateRecipeTimes is the query to update a recipe's times.

View Source
const UpdateUserSettingsCookbooksViewMode = `
	UPDATE user_settings
	SET cookbooks_view = ?
	WHERE user_id = ?`

UpdateUserSettingsCookbooksViewMode is the query to update the cookbooks_view column of a user's settings.

Variables

View Source
var RecipesFTSFields = []string{"name", "description", "category", "ingredients", "instructions", "keywords", "source"}

RecipesFTSFields lists all columns in the recipes_fts table.

View Source
var SelectCookbooks = `
	SELECT id, image, title, count
	FROM cookbooks
	WHERE id >= (SELECT id
				 FROM (SELECT id, ROW_NUMBER() OVER (ORDER BY id) AS row_num
					   FROM cookbooks
					   WHERE user_id = ?)
				 WHERE row_num > (? - 1) *` + templates.ResultsPerPageStr + " + " + templates.ResultsPerPageStr + `)
		AND user_id = ?
	LIMIT ` + templates.ResultsPerPageStr

SelectCookbooks gets a limited number of cookbooks belonging to the user.

Functions

func BuildBaseSelectRecipe added in v1.1.0

func BuildBaseSelectRecipe(sorts models.Sort) string

BuildBaseSelectRecipe builds from the options.

func BuildSelectNutrientFDC

func BuildSelectNutrientFDC(ingredients []string) string

BuildSelectNutrientFDC builds the query to fetch a nutrient from the FDC database.

func BuildSelectPaginatedResults added in v1.1.0

func BuildSelectPaginatedResults(queries []string, page uint64, options models.SearchOptionsRecipes) string

BuildSelectPaginatedResults builds a SQL query for paginated search results.

func BuildSelectSearchResultsCount added in v1.1.0

func BuildSelectSearchResultsCount(queries []string, options models.SearchOptionsRecipes) string

BuildSelectSearchResultsCount builds a SQL query for fetching the number of paginated results.

Types

This section is empty.

Jump to

Keyboard shortcuts

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