#pragma once #include #include "global.h" #include #include #include #include #include #include #include #include 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 columns; std::vector 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 primary_key_columns; }; std::string quote_identifier(std::string_view value); std::string normalize_key(std::string_view value); std::optional normalize_field(std::string_view value); void bind_optional(SQLite::Statement &statement, int index, const std::optional &value); bool read_csv_row(std::istream &input, std::vector &fields, char delimiter); std::string make_upsert_sql(std::string_view table_name, const std::vector &columns, const std::vector &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 &columns, const std::vector &primary_key_columns, char delimiter = ','); std::unique_ptr make_header_csv_resource(Header_Csv_Resource_Config config); std::unique_ptr make_schema_only_resource(Schema_Only_Resource_Config config); std::unique_ptr make_tar1090_aircraft_resource(std::string_view name, std::string_view description, std::uint64_t update_interval_seconds); } // namespace External_Database_Utils