vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
vkdb::Database Class Reference

Represents a database in vkdb. More...

#include <database.h>

Public Types

using size_type = uint64_t
 
using error_callback = std::function<void(Token, const std::string&)>
 
using runtime_error_callback = std::function<void(const RuntimeError&)>
 

Public Member Functions

 Database ()=delete
 Deleted default constructor.
 
 Database (DatabaseName name, error_callback error=VQ::error, runtime_error_callback runtime_error=VQ::runtimeError)
 Construct a new Database object.
 
 Database (Database &&) noexcept=default
 Move-construct a new Database object.
 
Databaseoperator= (Database &&) noexcept=default
 Move-assign a new Database object.
 
 Database (const Database &)=delete
 Deleted copy constructor.
 
Databaseoperator= (const Database &)=delete
 Deleted copy assignment operator.
 
 ~Database () noexcept=default
 Destroy the Database object.
 
TablecreateTable (const TableName &table_name)
 Create a Table object.
 
TablegetTable (const TableName &table_name)
 Get the Table object.
 
void dropTable (const TableName &table_name)
 Drop the Table object.
 
void clear ()
 Clear the database.
 
DatabaseName name () const noexcept
 Get the name of the database.
 
FilePath path () const noexcept
 Get the path to the database directory.
 
std::vector< TableName > tables () const noexcept
 Get the names of the tables in the database.
 
Databaserun (const std::string &source, std::ostream &stream=std::cout) noexcept
 Run a source string.
 
DatabaserunFile (const std::filesystem::path path, std::ostream &stream=std::cout) noexcept
 Run a file.
 
DatabaserunPrompt () noexcept
 Run the prompt.
 

Detailed Description

Represents a database in vkdb.

Definition at line 20 of file database.h.

Member Typedef Documentation

◆ error_callback

using vkdb::Database::error_callback = std::function<void(Token, const std::string&)>

Definition at line 23 of file database.h.

◆ runtime_error_callback

using vkdb::Database::runtime_error_callback = std::function<void(const RuntimeError&)>

Definition at line 24 of file database.h.

◆ size_type

using vkdb::Database::size_type = uint64_t

Definition at line 22 of file database.h.

Constructor & Destructor Documentation

◆ Database()

vkdb::Database::Database ( DatabaseName name,
error_callback error = VQ::error,
runtime_error_callback runtime_error = VQ::runtimeError )
explicit

Construct a new Database object.

The constructor will load the database if it exists.

Parameters
nameName of the database.
errorError callback.
runtime_errorRuntime error callback.
Exceptions
std::runtime_errorIf loading the database fails.

Definition at line 8 of file database.cpp.

Member Function Documentation

◆ clear()

void vkdb::Database::clear ( )

Clear the database.

Removes the database directory and all its contents.

Exceptions
std::runtime_errorIf the database directory cannot be removed.

Definition at line 51 of file database.cpp.

◆ createTable()

Table & vkdb::Database::createTable ( const TableName & table_name)

Create a Table object.

Inserts new Table object into the table map and creates the directory for the table.

Parameters
table_nameName of the table.
Returns
Table& Reference to the created table.
Exceptions
std::runtime_errorIf the table already exists.

Definition at line 21 of file database.cpp.

◆ dropTable()

void vkdb::Database::dropTable ( const TableName & table_name)

Drop the Table object.

Removes the table directory and erases the table from the table map.

Parameters
table_nameName of the table.
Exceptions
std::runtime_errorIf the table does not exist.

Definition at line 41 of file database.cpp.

◆ getTable()

Table & vkdb::Database::getTable ( const TableName & table_name)
nodiscard

Get the Table object.

Parameters
table_nameName of the table.
Returns
Table& Reference to the table.
Exceptions
std::runtime_errorIf the table does not exist.

Definition at line 32 of file database.cpp.

◆ name()

DatabaseName vkdb::Database::name ( ) const
nodiscardnoexcept

Get the name of the database.

Returns
DatabaseName Name of the database.

Definition at line 55 of file database.cpp.

◆ path()

FilePath vkdb::Database::path ( ) const
nodiscardnoexcept

Get the path to the database directory.

Returns
FilePath Path to the database directory.

Definition at line 59 of file database.cpp.

◆ run()

Database & vkdb::Database::run ( const std::string & source,
std::ostream & stream = std::cout )
noexcept

Run a source string.

The source string is lexed, parsed, and interpreted.

Parameters
sourceSource string.
streamOutput stream.
Returns
Database& Reference to this Database object.

Definition at line 68 of file database.cpp.

◆ runFile()

Database & vkdb::Database::runFile ( const std::filesystem::path path,
std::ostream & stream = std::cout )
noexcept

Run a file.

The file is read, lexed, parsed, and interpreted.

Parameters
pathPath to the file.
streamOutput stream.
Returns
Database& Reference to this Database object.

Definition at line 92 of file database.cpp.

◆ runPrompt()

Database & vkdb::Database::runPrompt ( )
noexcept

Run the prompt.

The user can enter queries and commands interactively.

Returns
Database& Reference to this Database object.

Definition at line 122 of file database.cpp.

◆ tables()

std::vector< TableName > vkdb::Database::tables ( ) const
nodiscardnoexcept

Get the names of the tables in the database.

Returns
std::vector<TableName> Names of the tables.

Definition at line 63 of file database.cpp.


The documentation for this class was generated from the following files: