Skip to content

Commit

Permalink
Fix compilation and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Jul 24, 2024
1 parent f1b7ce4 commit c10a87a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libstuff/SQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using namespace std;

class SQuery {
using QuerySerializable = variant<const char*, string&, int, unsigned, uint64_t, int64_t, double>;
public:
using QuerySerializable = variant<const char*, string, int, unsigned, uint64_t, int64_t, double>;
static string prepare(const string& query, const map<string, QuerySerializable>& params);
};
20 changes: 20 additions & 0 deletions test/tests/SQueryTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <libstuff/SQuery.h>
#include <test/lib/BedrockTester.h>

struct SQueryTest : tpunit::TestFixture {
SQueryTest() : tpunit::TestFixture(true, "SQuery",
TEST(SQueryTest::testPrepare)
)
{}

void testPrepare() {
// single param
ASSERT_EQUAL(SQuery::prepare("SELECT * FROM accounts WHERE accountID = {accountID};", {{"accountID", 42}}), "SELECT * FROM accounts WHERE accountID = 42;");

// multiple params
ASSERT_EQUAL(SQuery::prepare("SELECT * FROM reports WHERE accountID = {accountID} AND reportID = {reportID};", {{"accountID", 42}, {"reportID", 52}}), "SELECT * FROM reports WHERE accountID = 42 AND reportID = 52;");

// multiple params, multiple instances
ASSERT_EQUAL(SQuery::prepare("SELECT * FROM reportActions WHERE action == {actionCreated} OR (action != {actionCreated} AND created < {timestamp});", {{"actionCreated", "CREATED"}, {"timestamp", "2024-01-01 12:00:00"}}), "SELECT * FROM reportActions WHERE action == 'CREATED' OR (action != 'CREATED' AND created < '2024-01-01 12:00:00');");
}
} __SQueryTest;

0 comments on commit c10a87a

Please sign in to comment.