Commit 25eba018 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Folder: Use path as the cache key

parent 6d0b86eb
......@@ -6,8 +6,19 @@
namespace policy
{
const std::string FolderTable::Name = "Folder";
const std::string FolderTable::CacheColumn = "id_folder";
const std::string FolderTable::CacheColumn = "path";
unsigned int Folder::* const FolderTable::PrimaryKey = &Folder::m_id;
const FolderCache::KeyType&FolderCache::key(const std::shared_ptr<Folder>& self)
{
return self->path();
}
FolderCache::KeyType FolderCache::key( sqlite3_stmt* stmt )
{
return Traits<FolderCache::KeyType>::Load( stmt, 1 );
}
}
Folder::Folder( DBConnection dbConnection, sqlite3_stmt* stmt )
......@@ -25,7 +36,7 @@ Folder::Folder( const std::string& path )
bool Folder::createTable(DBConnection connection)
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FolderTable::Name + "("
+ policy::FolderTable::CacheColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "id_folder INTEGER PRIMARY KEY AUTOINCREMENT,"
"path TEXT UNIQUE ON CONFLICT FAIL"
")";
return SqliteTools::executeRequest( connection, req );
......
......@@ -15,11 +15,19 @@ struct FolderTable
static const std::string CacheColumn;
static unsigned int Folder::*const PrimaryKey;
};
struct FolderCache
{
using KeyType = std::string;
static const KeyType& key( const std::shared_ptr<Folder>& self );
static KeyType key( sqlite3_stmt* stmt );
};
}
class Folder : public IFolder, public Cache<Folder, IFolder, policy::FolderTable>
class Folder : public IFolder, public Cache<Folder, IFolder, policy::FolderTable, policy::FolderCache>
{
using _Cache = Cache<Folder, IFolder, policy::FolderTable>;
using _Cache = Cache<Folder, IFolder, policy::FolderTable, policy::FolderCache>;
public:
Folder(DBConnection dbConnection, sqlite3_stmt* stmt);
......@@ -38,6 +46,6 @@ private:
unsigned int m_id;
std::string m_path;
friend class Cache<Folder, IFolder, policy::FolderTable>;
friend _Cache;
friend struct policy::FolderTable;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment