Annotation of gnutrition/db.h, revision 1.1

1.1     ! asm         1: // SPDX-License-Identifier: GPL-3.0-or-later
        !             2: /*
        !             3:  * $Id$
        !             4:  *
        !             5:  * db.h - Database access layer for GNUtrition
        !             6:  *
        !             7:  * Copyright (C) 2026 Free Software Foundation, Inc.
        !             8:  *
        !             9:  * Author: Jason Self <jself@gnu.org>
        !            10:  */
        !            11: 
        !            12: #ifndef DB_H
        !            13: #define DB_H
        !            14: 
        !            15: #include <sqlite3.h>
        !            16: #include <stddef.h>
        !            17: 
        !            18: /* A single food item from the FNDDS foods table.  */
        !            19: struct food_item
        !            20: {
        !            21:   int food_code;
        !            22:   char *description;
        !            23: };
        !            24: 
        !            25: /* A dynamically-sized list of food items.  */
        !            26: struct food_list
        !            27: {
        !            28:   struct food_item *items;
        !            29:   size_t count;
        !            30:   size_t capacity;
        !            31: };
        !            32: 
        !            33: /* A single nutrient value for a food.  */
        !            34: struct nutrient_info
        !            35: {
        !            36:   char *name;
        !            37:   double value;
        !            38: };
        !            39: 
        !            40: /* A dynamically-sized list of nutrient values.  */
        !            41: struct nutrient_list
        !            42: {
        !            43:   struct nutrient_info *items;
        !            44:   size_t count;
        !            45:   size_t capacity;
        !            46: };
        !            47: 
        !            48: /* FPED food pattern equivalents for a food (per 100g).  */
        !            49: struct fped_entry
        !            50: {
        !            51:   int food_code;
        !            52:   double vegetables;
        !            53:   double fruits;
        !            54:   double grains;
        !            55:   double dairy;
        !            56:   double protein;
        !            57:   double oils;
        !            58: };
        !            59: 
        !            60: /* Open the food database at PATH.  Returns NULL on failure, printing
        !            61:    an error message to stderr.  */
        !            62: sqlite3 *db_open (const char *path);
        !            63: 
        !            64: /* Close the database DB.  */
        !            65: void db_close (sqlite3 *db);
        !            66: 
        !            67: /* Search for foods matching QUERY (case-insensitive substring match).
        !            68:    Returns 0 on success, -1 on error.  The caller must free the result
        !            69:    with food_list_free.  */
        !            70: int db_search_foods (sqlite3 *db, const char *query,
        !            71:                      struct food_list *results);
        !            72: 
        !            73: /* Look up nutrient information for FOOD_CODE.  Returns 0 on success,
        !            74:    -1 on error.  The caller must free the result with
        !            75:    nutrient_list_free.  */
        !            76: int db_get_nutrients (sqlite3 *db, int food_code,
        !            77:                       struct nutrient_list *results);
        !            78: 
        !            79: /* Look up FPED food pattern equivalents for FOOD_CODE.  Returns 0 on
        !            80:    success, -1 on error, 1 if not found.  */
        !            81: int db_get_fped (sqlite3 *db, int food_code, struct fped_entry *entry);
        !            82: 
        !            83: /* Free resources held by a food_list.  */
        !            84: void food_list_free (struct food_list *list);
        !            85: 
        !            86: /* Free resources held by a nutrient_list.  */
        !            87: void nutrient_list_free (struct nutrient_list *list);
        !            88: 
        !            89: #endif /* DB_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>