Create Database
Create Database
Description:
Creates a new database entry in the catalog, persists the updated catalog to disk, and creates the corresponding database directory under database/base/.
Function:
pub fn create_database(
catalog: &mut Catalog,
db_name: &str,
) -> bool
Input:
catalog— In-memory catalog containing all database metadata.db_name— Name of the database to create. Must be non-empty and unique.
Output:
- Returns
trueif the database was successfully created. - Returns
falseif validation, catalog persistence, or directory creation fails.
Implementation:
- Validate that
db_nameis not empty. - Check whether a database with the same name already exists in the catalog.
- Create a new
Databaseobject with an empty table map. - Insert the database into
catalog.databases. - Serialize the entire catalog to JSON using
serde_json. - Persist the catalog to the catalog file (
catalog.json). - Create the database directory:
if it does not already exist.
database/base/{db_name}/ - Return
trueon success; otherwise returnfalseif any validation, serialization, file write, or directory creation step fails.