taco-db  0.1.0
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
taco::Database Class Reference

The class for a database instance. More...

#include <dbmain/Database.h>

Public Member Functions

 Database ()
 A trivial constructor. More...
 
 ~Database ()
 Automatically closes the database if not closed. More...
 
void open (const std::string &path, size_t bpool_size, bool create, bool allow_overwrite=false)
 Initializes the database components and opens or creates the database at the specified path. More...
 
constexpr bool is_open () const
 
void close ()
 Closes the database. More...
 
FileManagerfile_manager () const
 
BufferManagerbuf_manager () const
 
CatCachecatcache () const
 
Schemaactres_schema () const
 
void CreateTable (absl::string_view tabname, std::vector< Oid > coltypid, std::vector< uint64_t > coltypparam={}, const std::vector< absl::string_view > &field_names={}, std::vector< bool > colisnullable={}, std::vector< bool > colisarray={})
 Creates a table named tabname'', withcoltypid.size()'' columns. More...
 
void CreateIndex (absl::string_view idxname, Oid idxtabid, IdxType idxtyp, bool idxunique, std::vector< FieldId > idxcoltabcolids, std::vector< Oid > idxcolltfuncids={}, std::vector< Oid > idxcoleqfuncids={})
 Createa an index named idxname'' and inserts into the catalog. More...
 
const std::string & GetLastDBPath () const
 

Static Public Member Functions

static void init_global ()
 Initializes all the global objects that are not associated with a particular database. More...
 

Private Attributes

bool m_initialized
 
std::string m_db_path
 
FileManagerm_file_manager
 
BufferManagerm_buf_manager
 
CatCachem_catcache
 
Schemam_actres_schema
 

Detailed Description

The class for a database instance.

There may only be one global database instance g_db'' at any time (see below). The constructor and destructor of theDatabase'' class must be trivial because of the existence of the global variable. To initialize/destroy a database, call g_db->open(...)'' and g_db->close()''.

Constructor & Destructor Documentation

◆ Database()

taco::Database::Database ( )
inline

A trivial constructor.

◆ ~Database()

taco::Database::~Database ( )
inline

Automatically closes the database if not closed.

Member Function Documentation

◆ actres_schema()

Schema * taco::Database::actres_schema ( ) const

◆ buf_manager()

BufferManager* taco::Database::buf_manager ( ) const
inline

◆ catcache()

CatCache* taco::Database::catcache ( ) const
inline

◆ close()

void taco::Database::close ( )

Closes the database.

This also releases all the resources even if the database ends up in an error state.

◆ CreateIndex()

void taco::Database::CreateIndex ( absl::string_view  idxname,
Oid  idxtabid,
IdxType  idxtyp,
bool  idxunique,
std::vector< FieldId idxcoltabcolids,
std::vector< Oid idxcolltfuncids = {},
std::vector< Oid idxcoleqfuncids = {} 
)

Createa an index named idxname'' and inserts into the catalog.

Ifidxname'' is an empty string, a default name will be generated.

The caller may optionally provide non-default < and = operators, as specified in CatCacheBase::AddIndex(). Both idxcolltfuncids and idxcoleqfuncids may be shorter than idxcoltabcolids and may have InvalidOid. Missing values and InvalidOid are looked up from the catalog using the default operators for the type.

◆ CreateTable()

void taco::Database::CreateTable ( absl::string_view  tabname,
std::vector< Oid coltypid,
std::vector< uint64_t >  coltypparam = {},
const std::vector< absl::string_view > &  field_names = {},
std::vector< bool >  colisnullable = {},
std::vector< bool >  colisarray = {} 
)

Creates a table named tabname'', withcoltypid.size()'' columns.

All the remaining vectors may be empty or of the same size as `‘coltypid’'. We will assign default values to the remainder of the parameters if they are empty. More specifically, the default type parameter is 0. The default field name for the ith column (starting from 0) is `‘col_i’'. By default, none of the field is nullable or is an array.

◆ file_manager()

FileManager* taco::Database::file_manager ( ) const
inline

◆ GetLastDBPath()

const std::string& taco::Database::GetLastDBPath ( ) const
inline

◆ init_global()

void taco::Database::init_global ( )
static

Initializes all the global objects that are not associated with a particular database.

This must be called the first thing in main() and this may not be called more than once.

◆ is_open()

constexpr bool taco::Database::is_open ( ) const
inlineconstexpr

◆ open()

void taco::Database::open ( const std::string &  path,
size_t  bpool_size,
bool  create,
bool  allow_overwrite = false 
)

Initializes the database components and opens or creates the database at the specified path.

If allow_overwrite and create are both true and the specified path already exists, it silently removes the existing directory before opens the database.

Member Data Documentation

◆ m_actres_schema

Schema* taco::Database::m_actres_schema
private

◆ m_buf_manager

BufferManager* taco::Database::m_buf_manager
private

◆ m_catcache

CatCache* taco::Database::m_catcache
private

◆ m_db_path

std::string taco::Database::m_db_path
private

◆ m_file_manager

FileManager* taco::Database::m_file_manager
private

◆ m_initialized

bool taco::Database::m_initialized
private

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