First ideas over transaction
This commit is contained in:
parent
4914a467e5
commit
973deaefd9
6 changed files with 133 additions and 0 deletions
|
@ -31,6 +31,10 @@ constexpr const char* removeAsset = "DELETE FROM assets where `id` = ? AND `owne
|
|||
constexpr const char* selectUsedCurrencies = "SELECT DISTINCT c.id, c.code, c.title, c.manual, c.icon FROM currencies c"
|
||||
" JOIN assets a ON c.id = a.currency"
|
||||
" WHERE a.owner = ?";
|
||||
constexpr const char* addTransactionQuery = "INSERT INTO transactions"
|
||||
" (`initiator`, `type`, `asset`, `parent`, `value`, `performed`)"
|
||||
" VALUES (?, 1, ?, ?, ?, ?)";
|
||||
|
||||
|
||||
static const std::filesystem::path buildSQLPath = "database";
|
||||
|
||||
|
@ -409,3 +413,30 @@ std::vector<DB::Currency> DB::MySQL::listUsedCurrencies(uint32_t owner) {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
DB::Transaction DB::MySQL::addTransaction(const DB::Transaction& transaction) {
|
||||
MYSQL* con = &connection;
|
||||
DB::Transaction result = transaction;
|
||||
|
||||
std::string value = std::to_string(result.value);
|
||||
|
||||
Statement add(con, addTransactionQuery);
|
||||
add.bind(&result.initiator, MYSQL_TYPE_LONG, true);
|
||||
add.bind(&result.asset, MYSQL_TYPE_LONG, true);
|
||||
add.bind(&result.parent, MYSQL_TYPE_LONG, true);
|
||||
add.bind(value.data(), MYSQL_TYPE_STRING);
|
||||
add.bind(&result.performed, MYSQL_TYPE_LONG, true);
|
||||
add.execute();
|
||||
|
||||
result.id = lastInsertedId();
|
||||
//todo retreive timestamp and actual value which could have changed after insertion
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DB::MySQL::updateTransaction(const DB::Transaction& transaction) {
|
||||
}
|
||||
|
||||
std::vector<DB::Transaction> DB::MySQL::listTransactions(uint32_t owner) {
|
||||
return std::vector<DB::Transaction>();
|
||||
}
|
||||
|
|
|
@ -32,14 +32,21 @@ public:
|
|||
|
||||
uint32_t registerAccount (const std::string& login, const std::string& hash) override;
|
||||
std::string getAccountHash (const std::string& login) override;
|
||||
|
||||
Session createSession (const std::string& login, const std::string& access, const std::string& renew) override;
|
||||
Session findSession (const std::string& accessToken) override;
|
||||
|
||||
std::vector<Asset> listAssets (uint32_t owner) override;
|
||||
Asset addAsset (const Asset& asset) override;
|
||||
void updateAsset (const Asset& asset) override;
|
||||
bool deleteAsset(uint32_t assetId, uint32_t actorId) override;
|
||||
|
||||
std::vector<Currency> listUsedCurrencies(uint32_t owner) override;
|
||||
|
||||
DB::Transaction addTransaction(const DB::Transaction& transaction) override;
|
||||
void updateTransaction(const DB::Transaction& transaction) override;
|
||||
std::vector<DB::Transaction> listTransactions(uint32_t owner) override;
|
||||
|
||||
private:
|
||||
void executeFile (const std::filesystem::path& relativePath);
|
||||
static std::optional<std::string> getComment (std::string& string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue