database connection created

This commit is contained in:
2025-12-18 13:21:09 -06:00
parent fc02524fc1
commit c522e9abda
4 changed files with 56 additions and 11 deletions

View File

@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.20)
# -----------------------------
# Force Clang before project() is called
# Force Clang before project()
# -----------------------------
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER clang CACHE STRING "" FORCE)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE)
endif()
@@ -21,13 +22,20 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_BUILD_TYPE Release)
# -----------------------------
# Dependencies (local submodules / cloned repos)
# System dependency: libsodium
# -----------------------------
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSODIUM REQUIRED IMPORTED_TARGET libsodium)
# -----------------------------
# Dependencies (vendored)
# -----------------------------
add_subdirectory(external/spdlog)
add_subdirectory(external/cpr)
add_subdirectory(external/clickhouse-cpp)
add_subdirectory(external/tomlplusplus)
add_subdirectory(external/json)
# -----------------------------
# Executable
# -----------------------------
@@ -36,7 +44,10 @@ add_executable(${PROJECT_NAME} src/main.cpp)
# -----------------------------
# Auto-discover include dirs under src/
# -----------------------------
file(GLOB_RECURSE SRC_SUBDIRS LIST_DIRECTORIES true "${CMAKE_CURRENT_SOURCE_DIR}/src/*")
file(GLOB_RECURSE SRC_SUBDIRS LIST_DIRECTORIES true
"${CMAKE_CURRENT_SOURCE_DIR}/src/*"
)
set(SRC_INCLUDES "")
foreach(dir ${SRC_SUBDIRS})
if(IS_DIRECTORY ${dir})
@@ -45,10 +56,15 @@ foreach(dir ${SRC_SUBDIRS})
endforeach()
# -----------------------------
# Auto-discover all .cpp files except main.cpp
# Auto-discover all .cpp except main.cpp
# -----------------------------
file(GLOB_RECURSE ALL_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
list(REMOVE_ITEM ALL_CPP "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
file(GLOB_RECURSE ALL_CPP
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp"
)
list(REMOVE_ITEM ALL_CPP
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
)
# -----------------------------
# Apply sources and includes
@@ -65,15 +81,19 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
clickhouse-cpp-lib
tomlplusplus::tomlplusplus
nlohmann_json::nlohmann_json
PkgConfig::LIBSODIUM
)
# -----------------------------
# Compiler warnings (Clang/GCC)
# Compiler warnings (Clang / GCC)
# -----------------------------
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options(
-Wall -Wextra -Wpedantic
-Wconversion -Wshadow
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wshadow
-Wnull-dereference
-Wdouble-promotion
)

View File

@@ -1,14 +1,27 @@
#include "clickhouse/client.h"
#include "nlohmann/json_fwd.hpp"
#include "skwyward-api-utils.hpp"
#include "spdlog/spdlog.h"
#include <exception>
#include <memory>
#include <sodium.h>
#include <sodium/core.h>
#include <string_view>
#include <toml++/toml.h>
int main (int argc, char *argv[]) {
auto config = toml::parse_file("config.toml");
std::string base_uri = config["host"].value_or("");
std::string test_username = config["test_username"].value_or("");
std::string test_password = config["test_password"].value_or("");
// clickhouse creds
std::string clickhouse_host_name = config["clickhouse_host"].value_or("");
std::string clickhouse_username = config["clickhouse_username"].value_or("");
std::string clickhouse_schema = config["clickhouse_schema"].value_or("");
std::string clickhouse_password = config["clickhouse_password"].value_or("");
api_utils::StatusResponse health_check = api_methods::get_status(base_uri);
spdlog::info("Status response output: {}", health_check.status);
@@ -17,5 +30,15 @@ int main (int argc, char *argv[]) {
api_utils::GradesResponse test_grades = api_methods::get_grades(base_uri, test_username, test_password);
spdlog::info("Grades: {}", nlohmann::json {test_grades}.dump());
if(sodium_init()==-1){
spdlog::error("Sodium, the crypto lib, cannot be inited. bailing");
std::terminate();
}
std::shared_ptr<clickhouse::Client> client_shared_ptr = std::make_shared<clickhouse::Client>(clickhouse::ClientOptions().SetHost(clickhouse_host_name).SetPassword(clickhouse_password).SetUser(clickhouse_username).SetDefaultDatabase(clickhouse_schema));
spdlog::info("Connected to the database");
return 0;
}

View File

@@ -0,0 +1 @@
#include "types.hpp"

View File

@@ -0,0 +1 @@
#pragma once