2021-05-17 11:02:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-28 13:29:29 +00:00
|
|
|
#include "config.h"
|
2021-07-08 13:27:30 +00:00
|
|
|
|
|
|
|
#if USE_SQLITE
|
2021-05-17 11:02:35 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
|
2021-10-27 23:10:39 +00:00
|
|
|
#include <sqlite3.h>
|
2021-05-17 11:02:35 +00:00
|
|
|
|
2021-09-28 22:17:26 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
|
|
|
class Logger;
|
|
|
|
}
|
2021-05-17 11:02:35 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-07-10 08:05:23 +00:00
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StorageSQLite final : public IStorage, public WithContext
|
2021-05-17 11:02:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-07-10 08:05:23 +00:00
|
|
|
using SQLitePtr = std::shared_ptr<sqlite3>;
|
|
|
|
|
2021-05-17 11:02:35 +00:00
|
|
|
StorageSQLite(
|
|
|
|
const StorageID & table_id_,
|
2021-07-10 08:05:23 +00:00
|
|
|
SQLitePtr sqlite_db_,
|
2021-07-26 07:05:28 +00:00
|
|
|
const String & database_path_,
|
2021-05-17 11:02:35 +00:00
|
|
|
const String & remote_table_name_,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const ConstraintsDescription & constraints_,
|
2021-06-01 20:52:12 +00:00
|
|
|
ContextPtr context_);
|
2021-05-17 11:02:35 +00:00
|
|
|
|
|
|
|
std::string getName() const override { return "SQLite"; }
|
|
|
|
|
|
|
|
Pipe read(
|
|
|
|
const Names & column_names,
|
2021-07-20 15:20:21 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2021-05-17 11:02:35 +00:00
|
|
|
SelectQueryInfo & query_info,
|
|
|
|
ContextPtr context,
|
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
2022-10-07 10:46:45 +00:00
|
|
|
size_t num_streams) override;
|
2021-05-17 11:02:35 +00:00
|
|
|
|
2023-06-07 18:33:08 +00:00
|
|
|
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, ContextPtr context, bool async_insert) override;
|
2021-05-24 18:59:10 +00:00
|
|
|
|
2023-05-19 00:44:27 +00:00
|
|
|
static ColumnsDescription getTableStructureFromData(
|
|
|
|
const SQLitePtr & sqlite_db_,
|
|
|
|
const String & table);
|
|
|
|
|
2021-05-17 11:02:35 +00:00
|
|
|
private:
|
|
|
|
String remote_table_name;
|
2021-07-26 11:26:06 +00:00
|
|
|
String database_path;
|
2021-07-10 08:05:23 +00:00
|
|
|
SQLitePtr sqlite_db;
|
2021-09-28 22:17:26 +00:00
|
|
|
Poco::Logger * log;
|
2021-05-17 11:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2021-07-08 13:27:30 +00:00
|
|
|
|
|
|
|
#endif
|