Data_deduplication_service
Service that will use hashes to deduplicate files
db_services Namespace Reference

db_services namespace More...

Classes

class  dbManager
 Database manager that handles database management. More...
 
struct  myConnString
 Structure to store and format connection string. More...
 

Typedefs

using indexType = int64_t
 
using trasnactionType = pqxx::transaction< pqxx::isolation_level::read_committed >
 
using connectionType = pqxx::connection
 
using conPtr = std::shared_ptr< connectionType >
 
using resType = pqxx::result
 
using nonTransType = pqxx::nontransaction
 

Functions

std::string toSpacedPath (std::string_view path)
 
std::string fromSpacedPath (std::string_view path)
 
std::string toTsquerablePath (std::string_view path)
 
bool checkConnection (const conPtr &conn)
 
bool checkConnString (const myConnString &connString)
 
tl::expected< conPtr, returnCodes > connectIfPossible (std::string_view cString)
 
resType terminateAllDbConnections (nonTransType &noTransExec, std::string_view dbName)
 
resType checkDatabaseExistence (nonTransType &noTransExec, std::string_view dbName)
 
resType checkSchemas (trasnactionType &txn)
 
indexType checkSegmentCount (trasnactionType &txn)
 
resType deleteUnusedSegments (trasnactionType &txn)
 
resType checkFileExistence (trasnactionType &txn, std::string_view fileName)
 
resType checkFilesExistence (trasnactionType &txn, const std::vector< std::filesystem::path > &files)
 
indexType getFileId (trasnactionType &txn, std::string_view fileName)
 
bool doesFileExist (trasnactionType &txn, std::string_view fileName)
 
resType getEntriesForDirectory (trasnactionType &txn, std::string_view dirPath)
 
std::vector< indexTypegetFileIdVector (trasnactionType &txn, std::string_view dirPath)
 
tl::expected< indexType, int > getTotalFileSize (trasnactionType &txn)
 
resType getTotalSchemaSizes (trasnactionType &txn)
 
resType getDedupCharacteristics (trasnactionType &txn)
 
resType getFileSizes (trasnactionType &txn)
 
void printRes (resType &rss, std::ostream &out)
 
template<printable T>
std::string vecToString (std::vector< T > &vec)
 
void printRowsAffected (const resType &res)
 
resType checkTExistence (db_services::trasnactionType &txn, std::string_view fileName)
 
myConnString loadConfiguration (std::string_view filename)
 
template<typename T , unsigned long size>
std::array< T, size > fromString (std::basic_string< T > &string)
 
template<typename ResultType , typename ... Args>
tl::expected< ResultType, int > executeInTransaction (conPtr &conn, ResultType(*call)(trasnactionType &, Args ...), Args &&... args)
 
template<typename ResultType , typename ... Args>
tl::expected< ResultType, int > executeInTransaction (conPtr &conn, const std::function< ResultType(trasnactionType &, Args ...)> &call, Args &&... args)
 
void diconnect (conPtr &conn)
 

Detailed Description

db_services namespace

Typedef Documentation

◆ connectionType

using db_services::connectionType = typedef pqxx::connection

◆ conPtr

using db_services::conPtr = typedef std::shared_ptr<connectionType>

◆ indexType

using db_services::indexType = typedef int64_t

◆ nonTransType

using db_services::nonTransType = typedef pqxx::nontransaction

◆ resType

using db_services::resType = typedef pqxx::result

◆ trasnactionType

using db_services::trasnactionType = typedef pqxx::transaction<pqxx::isolation_level::read_committed>

Function Documentation

◆ checkConnection()

bool db_services::checkConnection ( const conPtr conn)

Checks that conn is not null and opened

Parameters
conn
+ Here is the caller graph for this function:

◆ checkConnString()

bool db_services::checkConnString ( const myConnString connString)

Checks connection for connString

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

◆ checkDatabaseExistence()

resType db_services::checkDatabaseExistence ( nonTransType noTransExec,
std::string_view  dbName 
)

Checks database existence

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

◆ checkFileExistence()

resType db_services::checkFileExistence ( trasnactionType txn,
std::string_view  fileName 
)

Checks file existence

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

◆ checkFilesExistence()

resType db_services::checkFilesExistence ( trasnactionType txn,
const std::vector< std::filesystem::path > &  files 
)

Multifile variant for checkFileExistence

Parameters
txn
files
+ Here is the call graph for this function:

◆ checkSchemas()

resType db_services::checkSchemas ( trasnactionType txn)

Returns all schemas for database

Parameters
txn
+ Here is the caller graph for this function:

◆ checkSegmentCount()

indexType db_services::checkSegmentCount ( trasnactionType txn)

Compares segments counts from segments table to total counst from data table

Parameters
txn

◆ checkTExistence()

resType db_services::checkTExistence ( db_services::trasnactionType txn,
std::string_view  fileName 
)

Checks whether temporary table was created for file

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

◆ connectIfPossible()

tl::expected< conPtr, returnCodes > db_services::connectIfPossible ( std::string_view  cString)

Connects to database with cString

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

◆ deleteUnusedSegments()

resType db_services::deleteUnusedSegments ( trasnactionType txn)

Deletes segments with count=0

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

◆ diconnect()

void db_services::diconnect ( db_services::conPtr conn)

Closes and deletes connection

Parameters
conn
+ Here is the caller graph for this function:

◆ doesFileExist()

bool db_services::doesFileExist ( trasnactionType txn,
std::string_view  fileName 
)

Bool variant for existence checks

Parameters
txn
fileName
See also
getFileId
+ Here is the call graph for this function:

◆ executeInTransaction() [1/2]

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

Functional variant of previous call

Template Parameters
ResultType
Args
Parameters
connnot null connection
call
args

◆ executeInTransaction() [2/2]

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

Wraps function in transaction block

Template Parameters
ResultType
Args
Parameters
connnot null connection
call
args
+ Here is the caller graph for this function:

◆ fromSpacedPath()

std::string db_services::fromSpacedPath ( std::string_view  path)

Swaps space syblos for /

Parameters
path
+ Here is the caller graph for this function:

◆ fromString()

template<typename T , unsigned long size>
std::array<T, size> db_services::fromString ( std::basic_string< T > &  string)

◆ getDedupCharacteristics()

resType db_services::getDedupCharacteristics ( trasnactionType txn)

Calculates main deduplication characteristics for files

Parameters
txn
+ Here is the caller graph for this function:

◆ getEntriesForDirectory()

resType db_services::getEntriesForDirectory ( trasnactionType txn,
std::string_view  dirPath 
)

Returns resType that contains all file/subdirectory entries for the selected directory

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

◆ getFileId()

indexType db_services::getFileId ( trasnactionType txn,
std::string_view  fileName 
)

Parses one file id from request

Parameters
txn
fileName
See also
checkFileExistence
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFileIdVector()

std::vector< indexType > db_services::getFileIdVector ( trasnactionType txn,
std::string_view  dirPath 
)

Vector returning wrapper for getEntriesForDirectory

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

◆ getFileSizes()

resType db_services::getFileSizes ( trasnactionType txn)

◆ getTotalFileSize()

tl::expected< indexType, int > db_services::getTotalFileSize ( trasnactionType txn)

Calculates sum of files sizes

Parameters
txn

◆ getTotalSchemaSizes()

resType db_services::getTotalSchemaSizes ( trasnactionType txn)

Gets table thta contains schemas sizes for database

Parameters
txn

◆ loadConfiguration()

myConnString db_services::loadConfiguration ( std::string_view  filename)

Loads configuration from file

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

◆ printRes()

void db_services::printRes ( resType rss,
std::ostream &  out 
)

Peinrst resType to ostream

Parameters
rss
out

◆ printRowsAffected()

void db_services::printRowsAffected ( const resType res)

Gets affected rows for delete/update query result

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

◆ terminateAllDbConnections()

resType db_services::terminateAllDbConnections ( nonTransType noTransExec,
std::string_view  dbName 
)

Terminates all connections to dbName via sql query

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

◆ toSpacedPath()

std::string db_services::toSpacedPath ( std::string_view  path)

Swaps / symbols for spaces

Parameters
path
+ Here is the caller graph for this function:

◆ toTsquerablePath()

std::string db_services::toTsquerablePath ( std::string_view  path)

Replaces symbols in path to cast it to tsquery

Parameters
path

◆ vecToString()

template<printable T>
std::string db_services::vecToString ( std::vector< T > &  vec)
Template Parameters
T
Parameters
vec
+ Here is the caller graph for this function: