Explicitly pass database pointers to repository methods

This commit is contained in:
Akkadius
2021-02-05 23:00:27 -06:00
parent 7fe0bbacd4
commit e8ab176d4a
167 changed files with 2738 additions and 1938 deletions
@@ -132,10 +132,11 @@ public:
}
static Buyer FindOne(
Database& db,
int buyer_id
)
{
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
@@ -161,10 +162,11 @@ public:
}
static int DeleteOne(
Database& db,
int buyer_id
)
{
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
@@ -177,6 +179,7 @@ public:
}
static int UpdateOne(
Database& db,
Buyer buyer_entry
)
{
@@ -191,7 +194,7 @@ public:
update_values.push_back(columns[4] + " = " + std::to_string(buyer_entry.quantity));
update_values.push_back(columns[5] + " = " + std::to_string(buyer_entry.price));
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
@@ -205,6 +208,7 @@ public:
}
static Buyer InsertOne(
Database& db,
Buyer buyer_entry
)
{
@@ -236,6 +240,7 @@ public:
}
static int InsertMany(
Database& db,
std::vector<Buyer> buyer_entries
)
{
@@ -256,7 +261,7 @@ public:
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
@@ -267,11 +272,11 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Buyer> All()
static std::vector<Buyer> All(Database& db)
{
std::vector<Buyer> all_entries;
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
@@ -296,11 +301,11 @@ public:
return all_entries;
}
static std::vector<Buyer> GetWhere(std::string where_filter)
static std::vector<Buyer> GetWhere(Database& db, std::string where_filter)
{
std::vector<Buyer> all_entries;
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE {}",
BaseSelect(),
@@ -326,9 +331,9 @@ public:
return all_entries;
}
static int DeleteWhere(std::string where_filter)
static int DeleteWhere(Database& db, std::string where_filter)
{
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {}",
TableName(),
@@ -339,9 +344,9 @@ public:
return (results.Success() ? results.RowsAffected() : 0);
}
static int Truncate()
static int Truncate(Database& db)
{
auto results = database.QueryDatabase(
auto results = db.QueryDatabase(
fmt::format(
"TRUNCATE TABLE {}",
TableName()