Prompt Workbench Core 1.0.0
A C library for prompt testing and evaluation with OpenAI-compatible APIs (Educational Use Only)
Loading...
Searching...
No Matches
Data Structures | Functions
db.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TestSuite
 Represents a test suite in the database. More...
 
struct  UserPrompt
 Represents a user prompt associated with a test suite. More...
 

Functions

int db_init (const char *db_path)
 Initialize the database.
 
void db_close (void)
 Close the database connection and release any resources.
 
int db_create_test_suite (const char *title, const char *description, const char *system_prompt, const char *model)
 Create a new test suite.
 
TestSuitedb_get_test_suite (int id)
 Retrieve a test suite by ID.
 
TestSuite ** db_get_all_test_suites (int *count)
 Retrieve all test suites.
 
int db_update_test_suite (int id, const char *title, const char *description, const char *system_prompt, const char *model)
 Update an existing test suite.
 
int db_delete_test_suite (int id)
 Delete a test suite (cascading deletes associated user prompts).
 
void db_free_test_suite (TestSuite *suite)
 Free a TestSuite structure.
 
void db_free_test_suites (TestSuite **suites, int count)
 Free an array of TestSuite structures.
 
int db_create_user_prompt (const char *prompt, int test_suite_id)
 Create a new user prompt associated with a test suite.
 
UserPromptdb_get_user_prompt (int id)
 Retrieve a user prompt by ID.
 
UserPrompt ** db_get_user_prompts_by_suite (int test_suite_id, int *count)
 Retrieve all user prompts for a specific test suite.
 
UserPrompt ** db_get_all_user_prompts (int *count)
 Retrieve all user prompts.
 
int db_update_user_prompt (int id, const char *prompt, int test_suite_id)
 Update an existing user prompt.
 
int db_delete_user_prompt (int id)
 Delete a user prompt.
 
void db_free_user_prompt (UserPrompt *prompt)
 Free a UserPrompt structure.
 
void db_free_user_prompts (UserPrompt **prompts, int count)
 Free an array of UserPrompt structures.
 

Function Documentation

◆ db_close()

void db_close ( void  )

Close the database connection and release any resources.

Definition at line 76 of file db.c.

References db.

◆ db_create_test_suite()

int db_create_test_suite ( const char *  title,
const char *  description,
const char *  system_prompt,
const char *  model 
)

Create a new test suite.

Parameters
titleTest suite title
descriptionTest suite description
system_promptSystem prompt for the test suite
modelModel name to use
Returns
The ID of the newly created test suite, or -1 on error

Definition at line 85 of file db.c.

References db.

◆ db_create_user_prompt()

int db_create_user_prompt ( const char *  prompt,
int  test_suite_id 
)

Create a new user prompt associated with a test suite.

Parameters
promptThe text of the user prompt
test_suite_idID of the test suite this prompt belongs to
Returns
The ID of the newly created prompt, or -1 on error

Definition at line 325 of file db.c.

References db.

◆ db_delete_test_suite()

int db_delete_test_suite ( int  id)

Delete a test suite (cascading deletes associated user prompts).

Parameters
idThe test suite ID
Returns
0 on success, -1 on error

Definition at line 277 of file db.c.

References db.

◆ db_delete_user_prompt()

int db_delete_user_prompt ( int  id)

Delete a user prompt.

Parameters
idThe user prompt ID
Returns
0 on success, -1 on error

Definition at line 553 of file db.c.

References db.

◆ db_free_test_suite()

void db_free_test_suite ( TestSuite suite)

Free a TestSuite structure.

Parameters
suitePointer to the test suite to free

Definition at line 304 of file db.c.

References TestSuite::description, TestSuite::model, TestSuite::system_prompt, and TestSuite::title.

Referenced by db_free_test_suites().

+ Here is the caller graph for this function:

◆ db_free_test_suites()

void db_free_test_suites ( TestSuite **  suites,
int  count 
)

Free an array of TestSuite structures.

Parameters
suitesArray of TestSuite pointers
countNumber of elements in the array

Definition at line 314 of file db.c.

References db_free_test_suite().

Referenced by db_get_all_test_suites().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ db_free_user_prompt()

void db_free_user_prompt ( UserPrompt prompt)

Free a UserPrompt structure.

Parameters
promptPointer to the user prompt to free

Definition at line 580 of file db.c.

References UserPrompt::prompt.

Referenced by db_free_user_prompts().

+ Here is the caller graph for this function:

◆ db_free_user_prompts()

void db_free_user_prompts ( UserPrompt **  prompts,
int  count 
)

Free an array of UserPrompt structures.

Parameters
promptsArray of UserPrompt pointers
countNumber of elements in the array

Definition at line 587 of file db.c.

References db_free_user_prompt().

Referenced by db_get_all_user_prompts(), and db_get_user_prompts_by_suite().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ db_get_all_test_suites()

TestSuite ** db_get_all_test_suites ( int *  count)

Retrieve all test suites.

Parameters
countOutput parameter receiving the number of test suites returned
Returns
Array of dynamically allocated pointers to TestSuite (caller must free using db_free_test_suites), or NULL on error

Definition at line 156 of file db.c.

References db, db_free_test_suites(), TestSuite::description, TestSuite::id, TestSuite::model, TestSuite::system_prompt, and TestSuite::title.

+ Here is the call graph for this function:

◆ db_get_all_user_prompts()

UserPrompt ** db_get_all_user_prompts ( int *  count)

Retrieve all user prompts.

Parameters
countOutput parameter receiving the number of user prompts returned
Returns
Array of dynamically allocated UserPrompt pointers (caller must free using db_free_user_prompts), or NULL on error

Definition at line 451 of file db.c.

References db, db_free_user_prompts(), UserPrompt::id, UserPrompt::prompt, and UserPrompt::test_suite_id.

+ Here is the call graph for this function:

◆ db_get_test_suite()

TestSuite * db_get_test_suite ( int  id)

Retrieve a test suite by ID.

Parameters
idThe test suite ID
Returns
Pointer to a dynamically allocated TestSuite (caller must free using db_free_test_suite), or NULL on error

Definition at line 117 of file db.c.

References db, TestSuite::description, TestSuite::id, TestSuite::model, TestSuite::system_prompt, and TestSuite::title.

◆ db_get_user_prompt()

UserPrompt * db_get_user_prompt ( int  id)

Retrieve a user prompt by ID.

Parameters
idThe user prompt ID
Returns
Pointer to a dynamically allocated UserPrompt (caller must free using db_free_user_prompt), or NULL on error

Definition at line 353 of file db.c.

References db, UserPrompt::id, UserPrompt::prompt, and UserPrompt::test_suite_id.

◆ db_get_user_prompts_by_suite()

UserPrompt ** db_get_user_prompts_by_suite ( int  test_suite_id,
int *  count 
)

Retrieve all user prompts for a specific test suite.

Parameters
test_suite_idThe test suite ID
countOutput parameter receiving the number of user prompts returned
Returns
Array of dynamically allocated UserPrompt pointers (caller must free using db_free_user_prompts), or NULL on error

Definition at line 389 of file db.c.

References db, db_free_user_prompts(), UserPrompt::id, UserPrompt::prompt, and UserPrompt::test_suite_id.

+ Here is the call graph for this function:

◆ db_init()

int db_init ( const char *  db_path)

Initialize the database.

Creates the database file if it does not exist and sets up required tables.

Parameters
db_pathPath to the database file
Returns
0 on success, -1 on error

Definition at line 35 of file db.c.

References CREATE_TABLES_SQL, and db.

◆ db_update_test_suite()

int db_update_test_suite ( int  id,
const char *  title,
const char *  description,
const char *  system_prompt,
const char *  model 
)

Update an existing test suite.

Parameters
idThe test suite ID
titleNew title (NULL to leave unchanged)
descriptionNew description (NULL to leave unchanged)
system_promptNew system prompt (NULL to leave unchanged)
modelNew model (NULL to leave unchanged)
Returns
0 on success, -1 on error

Definition at line 218 of file db.c.

References db.

◆ db_update_user_prompt()

int db_update_user_prompt ( int  id,
const char *  prompt,
int  test_suite_id 
)

Update an existing user prompt.

Parameters
idThe user prompt ID
promptNew prompt text (NULL to leave unchanged)
test_suite_idNew test suite ID (0 or negative to leave unchanged)
Returns
0 on success, -1 on error

Definition at line 511 of file db.c.

References db.