BigFile/Sasquatch #1
@@ -64,6 +64,22 @@ BigFile::~BigFile()
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::optional<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffer(const UUID& p_uuid) const
|
||||
{
|
||||
BigFile::Request assetRequest {*this, "SELECT Asset FROM Asset WHERE UUID = ?1;"};
|
||||
assetRequest.Bind(1, p_uuid.ToBytes());
|
||||
|
||||
if (!assetRequest.Step())
|
||||
{
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
const eastl::span<const std::byte> flatbuffer = assetRequest.Get(0);
|
||||
return eastl::vector<std::byte> {flatbuffer.begin(), flatbuffer.end()};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl::span<const UUID> p_uuids) const
|
||||
{
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers;
|
||||
@@ -77,6 +93,7 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
|
||||
uniqueUUIDs.erase(eastl::unique(uniqueUUIDs.begin(), uniqueUUIDs.end()), uniqueUUIDs.end());
|
||||
|
||||
eastl::string placeholders;
|
||||
placeholders.reserve(uniqueUUIDs.size() * 3);
|
||||
for (std::size_t i = 0; i < uniqueUUIDs.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -84,13 +101,9 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
|
||||
placeholders += ", ";
|
||||
}
|
||||
placeholders += "?";
|
||||
placeholders += std::to_string(i + 1).c_str();
|
||||
}
|
||||
|
||||
const std::string sqlRequest = fmt::format("SELECT Asset.Asset FROM Asset "
|
||||
"JOIN AssetMetadata ON AssetMetadata.UUID = Asset.UUID "
|
||||
"WHERE Asset.UUID IN ({});",
|
||||
placeholders);
|
||||
const std::string sqlRequest = fmt::format("SELECT Asset FROM Asset WHERE UUID IN ({});", placeholders);
|
||||
|
||||
BigFile::Request assetRequest {*this, sqlRequest.c_str()};
|
||||
for (std::size_t i = 0; i < uniqueUUIDs.size(); ++i)
|
||||
@@ -115,6 +128,30 @@ eastl::vector<eastl::vector<std::byte>> BigFile::GetAssetFlatbuffers(const eastl
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::optional<AssetMetadata> BigFile::GetAssetMetadata(const UUID& p_uuid) const
|
||||
{
|
||||
BigFile::Request assetRequest {
|
||||
*this,
|
||||
"SELECT UUID, Name, TypeID, TypeName, CreateTime, ModificationTime FROM AssetMetadata WHERE UUID = ?1;"};
|
||||
assetRequest.Bind(1, p_uuid.ToBytes());
|
||||
|
||||
if (!assetRequest.Step())
|
||||
{
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
return AssetMetadata {.m_uuid = UUID {std::span<const std::byte, UUID::UUID_BYTE_SIZE> {
|
||||
static_cast<eastl::span<const std::byte>>(assetRequest.Get(0)).data(),
|
||||
UUID::UUID_BYTE_SIZE}},
|
||||
.m_name = eastl::string {static_cast<eastl::string_view>(assetRequest.Get(1))},
|
||||
.m_typeID = assetRequest.Get(2),
|
||||
.m_typeName = eastl::string {static_cast<eastl::string_view>(assetRequest.Get(3))},
|
||||
.m_creationTime = Time {static_cast<std::uint64_t>(assetRequest.Get(4))},
|
||||
.m_modificationTime = Time {static_cast<std::uint64_t>(assetRequest.Get(5))}};
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
eastl::vector<AssetMetadata> BigFile::GetAssetMetadatas(const eastl::span<const UUID> p_uuids) const
|
||||
{
|
||||
eastl::vector<AssetMetadata> metadatas;
|
||||
@@ -128,6 +165,7 @@ eastl::vector<AssetMetadata> BigFile::GetAssetMetadatas(const eastl::span<const
|
||||
uniqueUUIDs.erase(eastl::unique(uniqueUUIDs.begin(), uniqueUUIDs.end()), uniqueUUIDs.end());
|
||||
|
||||
eastl::string placeholders;
|
||||
placeholders.reserve(uniqueUUIDs.size() * 3);
|
||||
for (std::size_t i = 0; i < uniqueUUIDs.size(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -135,7 +173,6 @@ eastl::vector<AssetMetadata> BigFile::GetAssetMetadatas(const eastl::span<const
|
||||
placeholders += ", ";
|
||||
}
|
||||
placeholders += "?";
|
||||
placeholders += std::to_string(i + 1).c_str();
|
||||
}
|
||||
|
||||
const std::string sqlRequest = fmt::format("SELECT UUID, Name, TypeID, TypeName, CreateTime, ModificationTime "
|
||||
|
||||
@@ -2,7 +2,7 @@ PRAGMA journal_mode=WAL;
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS AssetMetadata (
|
||||
UUID BLOB NOT NULL UNIQUE,
|
||||
UUID BLOB NOT NULL,
|
||||
Name TEXT NOT NULL UNIQUE,
|
||||
TypeID INTEGER NOT NULL,
|
||||
TypeName TEXT NOT NULL,
|
||||
@@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS AssetMetadata (
|
||||
ModificationTime INTEGER NOT NULL DEFAULT(CAST(unixepoch('subsec') * 1000000 AS INTEGER)),
|
||||
|
||||
PRIMARY KEY(UUID)
|
||||
);
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS AssetMetadata_UpdateTime
|
||||
AFTER UPDATE OF Name, TypeID, TypeName ON AssetMetadata FOR EACH ROW
|
||||
@@ -22,13 +22,13 @@ BEGIN
|
||||
END;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Asset (
|
||||
UUID BLOB NOT NULL UNIQUE,
|
||||
UUID BLOB NOT NULL,
|
||||
|
||||
Asset BLOB NOT NULL,
|
||||
|
||||
PRIMARY KEY(UUID),
|
||||
FOREIGN KEY(UUID) REFERENCES AssetMetadata(UUID) ON DELETE CASCADE
|
||||
);
|
||||
) WITHOUT ROWID;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS Asset_UpdateTime
|
||||
AFTER UPDATE OF Asset ON Asset FOR EACH ROW
|
||||
|
||||
@@ -51,6 +51,14 @@ class BigFile: public DataAccessor
|
||||
|
||||
~BigFile();
|
||||
|
||||
/**
|
||||
* Get an Asset flatbuffer
|
||||
*
|
||||
* \param p_uuid The asset to get the flatbuffer of
|
||||
* \return The flatbuffer, or nullopt if the asset was not found
|
||||
*/
|
||||
eastl::optional<eastl::vector<std::byte>> GetAssetFlatbuffer(const UUID& p_uuid) const override;
|
||||
|
||||
/**
|
||||
* Get several Asset flatbuffers
|
||||
*
|
||||
@@ -59,6 +67,14 @@ class BigFile: public DataAccessor
|
||||
*/
|
||||
eastl::vector<eastl::vector<std::byte>> GetAssetFlatbuffers(eastl::span<const UUID> p_uuids) const override;
|
||||
|
||||
/**
|
||||
* Get an Asset metadata
|
||||
*
|
||||
* \param p_uuid The asset to get the metadata of
|
||||
* \return The metadata, or nullopt if the asset was not found
|
||||
*/
|
||||
eastl::optional<AssetMetadata> GetAssetMetadata(const UUID& p_uuid) const override;
|
||||
|
||||
/**
|
||||
* Get several Asset metadatas
|
||||
*
|
||||
|
||||
@@ -46,16 +46,7 @@ class DataAccessor
|
||||
* \param p_uuid The asset to get the flatbuffer of
|
||||
* \return The flatbuffer, or nullopt if the asset was not found
|
||||
*/
|
||||
eastl::optional<eastl::vector<std::byte>> GetAssetFlatbuffer(const UUID& p_uuid) const
|
||||
{
|
||||
eastl::vector<eastl::vector<std::byte>> flatbuffers = GetAssetFlatbuffers(eastl::span<const UUID> {&p_uuid, 1});
|
||||
if (flatbuffers.empty())
|
||||
{
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
return std::move(flatbuffers.front());
|
||||
}
|
||||
virtual eastl::optional<eastl::vector<std::byte>> GetAssetFlatbuffer(const UUID& p_uuid) const = 0;
|
||||
|
||||
/**
|
||||
* Get several Asset flatbuffers
|
||||
@@ -71,16 +62,7 @@ class DataAccessor
|
||||
* \param p_uuid The asset to get the metadata of
|
||||
* \return The metadata, or nullopt if the asset was not found
|
||||
*/
|
||||
eastl::optional<AssetMetadata> GetAssetMetadata(const UUID& p_uuid) const
|
||||
{
|
||||
eastl::vector<AssetMetadata> metadatas = GetAssetMetadatas(eastl::span<const UUID> {&p_uuid, 1});
|
||||
if (metadatas.empty())
|
||||
{
|
||||
return eastl::nullopt;
|
||||
}
|
||||
|
||||
return std::move(metadatas.front());
|
||||
}
|
||||
virtual eastl::optional<AssetMetadata> GetAssetMetadata(const UUID& p_uuid) const = 0;
|
||||
|
||||
/**
|
||||
* Get several Asset metadatas
|
||||
|
||||
@@ -17,10 +17,15 @@ class DataAccessorFixture: public ::testing::Test
|
||||
class DataAccessorMock: public DataAccessor
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD(eastl::optional<eastl::vector<std::byte>>,
|
||||
GetAssetFlatbuffer,
|
||||
(const UUID& p_uuid),
|
||||
(const, override));
|
||||
MOCK_METHOD(eastl::vector<eastl::vector<std::byte>>,
|
||||
GetAssetFlatbuffers,
|
||||
(eastl::span<const UUID> p_uuids),
|
||||
(const, override));
|
||||
MOCK_METHOD(eastl::optional<AssetMetadata>, GetAssetMetadata, (const UUID& p_uuid), (const, override));
|
||||
MOCK_METHOD(eastl::vector<AssetMetadata>,
|
||||
GetAssetMetadatas,
|
||||
(eastl::span<const UUID> p_uuids),
|
||||
|
||||
Reference in New Issue
Block a user