Data_deduplication_service
Service that will use hashes to deduplicate files
db_services::dbManager Class Reference

Database manager that handles database management. More...

#include <dbManager.h>

Public Member Functions

 dbManager ()
 
 dbManager (myConnString &ss)
 
void setCString (myConnString &ss)
 
const myConnStringgetCString () const
 
int connectToDb ()
 
void disconnect ()
 
int createDatabase (std::string_view dbName)
 
int dropDatabase (std::string_view dbName)
 
int fillSchemas ()
 
int clearSegments ()
 
std::vector< std::pair< indexType, std::string > > getAllFiles (std::string_view dirPath)
 
indexType createFile (std::string_view filePath, uintmax_t fileSize=0, size_t segmentSize=0, hash_function hash=SHA_256)
 
indexType createDirectory (std::string_view dirPath)
 
int deleteFile (std::string_view filePath, indexType fileId=paramType::EmptyParameterValue)
 
int deleteDirectory (std::string_view directoryPath)
 
int getFileStreamed (std::string_view fileName, std::ostream &output, indexType fileId=paramType::EmptyParameterValue)
 
int insertFileFromStream (std::string_view fileName, std::istream &in, size_t segmentSize, std::size_t fileSize, const hash_function &hash=SHA_256)
 
int finishFileProcessing (std::string_view filePath, indexType fileId)
 
bool checkConnection ()
 
 ~dbManager ()
 
template<typename ResultType , typename ... Args>
tl::expected< ResultType, int > executeInTransaction (ResultType(*call)(trasnactionType &, Args ...), Args &&... args)
 
template<typename ResultType , typename ... Args>
tl::expected< ResultType, int > executeInTransaction (const std::function< ResultType(trasnactionType &, Args ...)> &call, Args &&... args)
 

Detailed Description

Database manager that handles database management.

This class is designed to handle main interactions for database.

You can connect/create/deelte databases.

You can send requests for file load/delete/export.

Some external helper functions can be found in dbCommon.h

Constructor & Destructor Documentation

◆ dbManager() [1/2]

db_services::dbManager::dbManager ( )
inline

◆ dbManager() [2/2]

db_services::dbManager::dbManager ( myConnString ss)
inlineexplicit

◆ ~dbManager()

db_services::dbManager::~dbManager ( )
inline

Member Function Documentation

◆ checkConnection()

bool db_services::dbManager::checkConnection ( )
inline
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearSegments()

int db_services::dbManager::clearSegments ( )

Removes segments that are not used in files

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

◆ connectToDb()

int db_services::dbManager::connectToDb ( )
+ Here is the call graph for this function:

◆ createDatabase()

int db_services::dbManager::createDatabase ( std::string_view  dbName)

Creates database entry and connect to it

Parameters
dbName
+ Here is the call graph for this function:

◆ createDirectory()

indexType db_services::dbManager::createDirectory ( std::string_view  dirPath)

Creates entry for directory

Parameters
dirPath
Returns
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFile()

indexType db_services::dbManager::createFile ( std::string_view  filePath,
uintmax_t  fileSize = 0,
size_t  segmentSize = 0,
hash_function  hash = SHA_256 
)

Creates entry for a given file

Parameters
filePath
fileSize
Returns
+ Here is the call graph for this function:

◆ deleteDirectory()

int db_services::dbManager::deleteDirectory ( std::string_view  directoryPath)

Recursively deletes all file data for selected directory

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

◆ deleteFile()

int db_services::dbManager::deleteFile ( std::string_view  filePath,
indexType  fileId = paramType::EmptyParameterValue 
)

Recursively deletes all file data

Parameters
filePath
fileId
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnect()

void db_services::dbManager::disconnect ( )
inline
+ Here is the call graph for this function:

◆ dropDatabase()

int db_services::dbManager::dropDatabase ( std::string_view  dbName)

Deletes database entry

Parameters
dbName
+ Here is the call graph for this function:

◆ executeInTransaction() [1/2]

template<typename ResultType , typename ... Args>
tl::expected<ResultType, int> db_services::dbManager::executeInTransaction ( const std::function< ResultType(trasnactionType &, Args ...)> &  call,
Args &&...  args 
)
inline

Functional variant of previous function

Template Parameters
ResultType
Args
Parameters
call
args
+ Here is the call graph for this function:

◆ executeInTransaction() [2/2]

template<typename ResultType , typename ... Args>
tl::expected<ResultType, int> db_services::dbManager::executeInTransaction ( ResultType(*)(trasnactionType &, Args ...)  call,
Args &&...  args 
)
inline

Wraps function in transaction block

Template Parameters
ResultType
Args
Parameters
call
args
+ Here is the call graph for this function:

◆ fillSchemas()

int db_services::dbManager::fillSchemas ( )

Create main database tables and indexes

+ Here is the call graph for this function:

◆ finishFileProcessing()

int db_services::dbManager::finishFileProcessing ( std::string_view  filePath,
indexType  fileId 
)

Process bulk inserted file data

Parameters
filePath
fileId
+ Here is the call graph for this function:

◆ getAllFiles()

std::vector< std::pair< indexType, std::string > > db_services::dbManager::getAllFiles ( std::string_view  dirPath)

Get vector of pairs of file_names and file ids for directory

Parameters
dirPath
+ Here is the call graph for this function:

◆ getCString()

const myConnString& db_services::dbManager::getCString ( ) const
inline

◆ getFileStreamed()

int db_services::dbManager::getFileStreamed ( std::string_view  fileName,
std::ostream &  output,
indexType  fileId = paramType::EmptyParameterValue 
)

Recreates file contents and bulk insert them in out stream

Parameters
fileName
output
fileId
+ Here is the call graph for this function:

◆ insertFileFromStream()

int db_services::dbManager::insertFileFromStream ( std::string_view  fileName,
std::istream &  in,
size_t  segmentSize,
std::size_t  fileSize,
const hash_function hash = SHA_256 
)

Bulk insert file segments into temporary table

Parameters
fileName
in
fileSize
hashhash function that will be used for hashing
+ Here is the call graph for this function:

◆ setCString()

void db_services::dbManager::setCString ( myConnString ss)
inline

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