Function create_table

Source
pub fn create_table(
    db_path: &str,
    table_name: &str,
    columns: &str,
) -> Result<()>
Expand description

Creates a new table in the specified database.

This function adds a new table to the database with the given name and column definitions. It includes validation to:

  • Ensure the database file exists.
  • Check if a table with the same name already exists.
  • Perform basic validation on the column definition syntax.
  • Verify that the table was actually created after execution.

§Arguments

  • db_path - The path to the database file.
  • table_name - The name of the table to create.
  • columns - A string defining the table’s columns (e.g., “id INTEGER PRIMARY KEY, name TEXT”).

§Returns

A Result which is Ok(()) on successful table creation, or an Err with context if it fails.