AccountsDBase additions/corrections (can now retrieve all accounts)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#include "Active/Database/Storage/SQLiteEngine.h"
|
||||
#include "Active/Database/Storage/Storage.h"
|
||||
#include "Active/Serialise/JSON/JSONTransport.h"
|
||||
#include "Active/Setting/ValueSetting.h"
|
||||
#include "Active/Setting/Values/StringValue.h"
|
||||
#include "Speckle/Database/AccountDBase.h"
|
||||
|
||||
using namespace active::container;
|
||||
using namespace active::database;
|
||||
using namespace active::serialise::json;
|
||||
using namespace active::setting;
|
||||
@@ -10,8 +13,6 @@ using namespace speckle::record::cred;
|
||||
using namespace speckle::database;
|
||||
using namespace speckle::utility;
|
||||
|
||||
using AccountsEngine = SQLiteEngine<Account, Account, JSONTransport, active::utility::String, active::utility::String>;
|
||||
|
||||
namespace {
|
||||
|
||||
enum Fields {
|
||||
@@ -25,17 +26,35 @@ namespace {
|
||||
const char* contentFieldName = "content";
|
||||
|
||||
}
|
||||
// template<typename Obj, typename ObjWrapper, typename Transport, typename DocID = utility::Guid, typename ObjID = utility::Guid>
|
||||
|
||||
namespace speckle::database {
|
||||
|
||||
///Accounts database engine declaration
|
||||
using AccountsEngine = SQLiteEngine<Account, Account, JSONTransport, active::utility::String, active::utility::String>;
|
||||
|
||||
///Accounts database storage declaration
|
||||
class AccountDBase::Store : public active::database::Storage<speckle::record::cred::Account, active::serialise::json::JSONTransport,
|
||||
active::utility::String, active::utility::String, active::utility::String, active::utility::String> {
|
||||
using base = active::database::Storage<speckle::record::cred::Account, active::serialise::json::JSONTransport,
|
||||
active::utility::String, active::utility::String, active::utility::String, active::utility::String>;
|
||||
using base::base;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Constructor
|
||||
|
||||
path: Path to the database file
|
||||
--------------------------------------------------------------------*/
|
||||
AccountDBase::AccountDBase(const active::file::Path& path) : base{
|
||||
std::make_unique<AccountsEngine>(
|
||||
path, DBaseSchema{
|
||||
accountsDBaseName, {
|
||||
AccountDBase::AccountDBase(const active::file::Path& path) {
|
||||
m_store = std::make_unique<Store>(
|
||||
//Engine
|
||||
std::make_unique<AccountsEngine>(path,
|
||||
//Schema
|
||||
DBaseSchema{active::utility::String{accountsDBaseName},
|
||||
//Tables
|
||||
{
|
||||
{
|
||||
accountsTableName, Fields::hashID, Fields::contentID, {
|
||||
ValueSetting{StringValue{}, hashFieldName},
|
||||
@@ -45,6 +64,15 @@ AccountDBase::AccountDBase(const active::file::Path& path) : base{
|
||||
}
|
||||
}
|
||||
)
|
||||
} {
|
||||
|
||||
);
|
||||
} //AccountDBase::AccountDBase
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------
|
||||
Get all accounts
|
||||
|
||||
return: All the accounts
|
||||
--------------------------------------------------------------------*/
|
||||
Vector<Account> AccountDBase::getAccounts() const {
|
||||
return m_store->getObjects();
|
||||
} //AccountDBase::getAccounts
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
#ifndef SPECKLE_DATABASE_ACCOUNT_DBASE
|
||||
#define SPECKLE_DATABASE_ACCOUNT_DBASE
|
||||
|
||||
#include "Active/Database/Storage/SQLiteEngine.h"
|
||||
#include "Active/Database/Storage/Storage.h"
|
||||
#include "Active/File/Path.h"
|
||||
#include "Active/Serialise/JSON/JSONTransport.h"
|
||||
#include "Speckle/Record/Credentials/Account.h"
|
||||
#include "Speckle/Utility/String.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace speckle::database {
|
||||
|
||||
/*!
|
||||
A base class for an addon
|
||||
*/
|
||||
class AccountDBase : public active::database::Storage<speckle::record::cred::Account, active::serialise::json::JSONTransport,
|
||||
active::utility::String, active::utility::String, active::utility::String, active::utility::String> {
|
||||
class AccountDBase {
|
||||
public:
|
||||
|
||||
// MARK: - Types
|
||||
|
||||
using base = active::database::Storage<speckle::record::cred::Account, active::serialise::json::JSONTransport,
|
||||
active::utility::String, active::utility::String, active::utility::String, active::utility::String>;
|
||||
|
||||
using type_identity_t = std::type_identity<active::database::Storage<speckle::record::cred::Account, active::serialise::json::JSONTransport,
|
||||
active::utility::String, active::utility::String, active::utility::String, active::utility::String>>::type;
|
||||
|
||||
// MARK: - Constructors
|
||||
|
||||
/*!
|
||||
@@ -38,7 +23,7 @@ namespace speckle::database {
|
||||
Copy constructor
|
||||
@param source The object to copy
|
||||
*/
|
||||
AccountDBase(const AccountDBase& source) : base{source} {}
|
||||
AccountDBase(const AccountDBase& source) {}
|
||||
/*!
|
||||
Destructor
|
||||
*/
|
||||
@@ -46,9 +31,18 @@ namespace speckle::database {
|
||||
|
||||
// MARK: - Functions (const)
|
||||
|
||||
/*!
|
||||
Get all accounts
|
||||
@return All the accounts
|
||||
*/
|
||||
active::container::Vector<record::cred::Account> getAccounts() const;
|
||||
|
||||
// MARK: - Functions (mutating)
|
||||
|
||||
|
||||
private:
|
||||
class Store;
|
||||
///Accounts database storage
|
||||
std::unique_ptr<Store> m_store;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user