2021-05-17 11:02:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-07-08 13:27:30 +00:00
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include "config_core.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SQLITE
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/shared_ptr_helper.h>
|
2021-05-17 11:02:35 +00:00
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
|
2021-07-13 22:16:27 +00:00
|
|
|
#include <sqlite3.h> // Y_IGNORE
|
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
|
|
|
|
2021-07-07 20:39:41 +00:00
|
|
|
class StorageSQLite final : public shared_ptr_helper<StorageSQLite>, public IStorage, public WithContext
|
2021-05-17 11:02:35 +00:00
|
|
|
{
|
2021-07-10 08:05:23 +00:00
|
|
|
friend struct shared_ptr_helper<StorageSQLite>;
|
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,
|
|
|
|
const StorageMetadataPtr & /*metadata_snapshot*/,
|
|
|
|
SelectQueryInfo & query_info,
|
|
|
|
ContextPtr context,
|
|
|
|
QueryProcessingStage::Enum processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned num_streams) override;
|
|
|
|
|
2021-07-23 14:25:35 +00:00
|
|
|
SinkToStoragePtr write(const ASTPtr & query, const StorageMetadataPtr & /*metadata_snapshot*/, ContextPtr context) override;
|
2021-05-24 18:59:10 +00:00
|
|
|
|
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-05-17 11:02:35 +00:00
|
|
|
ContextPtr global_context;
|
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
|