66 lines
2.2 KiB
C++
66 lines
2.2 KiB
C++
#pragma once
|
|
#include <string_view>
|
|
|
|
#include "global.h"
|
|
|
|
#include <SQLiteCpp/Statement.h>
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <iosfwd>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace External_Database_Utils {
|
|
|
|
struct Header_Csv_Resource_Config {
|
|
std::string name;
|
|
std::string cache_file_name;
|
|
std::string download_url;
|
|
std::string description;
|
|
std::uint64_t update_interval_seconds{};
|
|
std::vector<std::string> columns;
|
|
std::vector<std::string> primary_key_columns;
|
|
char delimiter = ',';
|
|
};
|
|
|
|
struct Schema_Only_Resource_Config {
|
|
std::string name;
|
|
std::string description;
|
|
std::uint64_t update_interval_seconds{};
|
|
std::string create_table_sql;
|
|
std::vector<std::string> primary_key_columns;
|
|
};
|
|
|
|
std::string quote_identifier(std::string_view value);
|
|
std::string normalize_key(std::string_view value);
|
|
std::optional<std::string> normalize_field(std::string_view value);
|
|
void bind_optional(SQLite::Statement &statement, int index,
|
|
const std::optional<std::string> &value);
|
|
bool read_csv_row(std::istream &input, std::vector<std::string> &fields,
|
|
char delimiter);
|
|
std::string
|
|
make_upsert_sql(std::string_view table_name,
|
|
const std::vector<std::string> &columns,
|
|
const std::vector<std::string> &primary_key_columns);
|
|
void download_to_file(std::string_view url,
|
|
const std::filesystem::path &target_file);
|
|
void decompress_gzip(const std::filesystem::path &gzip_file,
|
|
const std::filesystem::path &target_file);
|
|
std::size_t import_header_csv(
|
|
SQLite::Database &db, const std::filesystem::path &source_file,
|
|
std::string_view table_name, const std::vector<std::string> &columns,
|
|
const std::vector<std::string> &primary_key_columns, char delimiter = ',');
|
|
|
|
std::unique_ptr<External_Resources>
|
|
make_header_csv_resource(Header_Csv_Resource_Config config);
|
|
std::unique_ptr<External_Resources>
|
|
make_schema_only_resource(Schema_Only_Resource_Config config);
|
|
std::unique_ptr<External_Resources>
|
|
make_tar1090_aircraft_resource(std::string_view name, std::string_view description,
|
|
std::uint64_t update_interval_seconds);
|
|
|
|
} // namespace External_Database_Utils
|