362 lines
12 KiB
C
362 lines
12 KiB
C
|
/**
|
||
|
*
|
||
|
* User.h
|
||
|
* DO NOT EDIT. This file is generated by drogon_ctl
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
#include <drogon/orm/Result.h>
|
||
|
#include <drogon/orm/Row.h>
|
||
|
#include <drogon/orm/Field.h>
|
||
|
#include <drogon/orm/SqlBinder.h>
|
||
|
#include <drogon/orm/Mapper.h>
|
||
|
#ifdef __cpp_impl_coroutine
|
||
|
#include <drogon/orm/CoroMapper.h>
|
||
|
#endif
|
||
|
#include <trantor/utils/Date.h>
|
||
|
#include <trantor/utils/Logger.h>
|
||
|
#include <json/json.h>
|
||
|
#include <string>
|
||
|
#include <memory>
|
||
|
#include <vector>
|
||
|
#include <tuple>
|
||
|
#include <stdint.h>
|
||
|
#include <iostream>
|
||
|
|
||
|
namespace drogon
|
||
|
{
|
||
|
namespace orm
|
||
|
{
|
||
|
class DbClient;
|
||
|
using DbClientPtr = std::shared_ptr<DbClient>;
|
||
|
}
|
||
|
}
|
||
|
namespace drogon_model
|
||
|
{
|
||
|
namespace sqlite3
|
||
|
{
|
||
|
|
||
|
class User
|
||
|
{
|
||
|
public:
|
||
|
struct Cols
|
||
|
{
|
||
|
static const std::string _id;
|
||
|
static const std::string _gitlab;
|
||
|
static const std::string _name;
|
||
|
static const std::string _password;
|
||
|
static const std::string _role;
|
||
|
static const std::string _root_id;
|
||
|
static const std::string _tfa_type;
|
||
|
static const std::string _tfa_secret;
|
||
|
static const std::string _gitlab_at;
|
||
|
static const std::string _gitlab_rt;
|
||
|
};
|
||
|
|
||
|
const static int primaryKeyNumber;
|
||
|
const static std::string tableName;
|
||
|
const static bool hasPrimaryKey;
|
||
|
const static std::string primaryKeyName;
|
||
|
using PrimaryKeyType = uint64_t;
|
||
|
const PrimaryKeyType &getPrimaryKey() const;
|
||
|
|
||
|
/**
|
||
|
* @brief constructor
|
||
|
* @param r One row of records in the SQL query result.
|
||
|
* @param indexOffset Set the offset to -1 to access all columns by column names,
|
||
|
* otherwise access all columns by offsets.
|
||
|
* @note If the SQL is not a style of 'select * from table_name ...' (select all
|
||
|
* columns by an asterisk), please set the offset to -1.
|
||
|
*/
|
||
|
explicit User(const drogon::orm::Row &r, const ssize_t indexOffset = 0) noexcept;
|
||
|
|
||
|
/**
|
||
|
* @brief constructor
|
||
|
* @param pJson The json object to construct a new instance.
|
||
|
*/
|
||
|
explicit User(const Json::Value &pJson) noexcept(false);
|
||
|
|
||
|
/**
|
||
|
* @brief constructor
|
||
|
* @param pJson The json object to construct a new instance.
|
||
|
* @param pMasqueradingVector The aliases of table columns.
|
||
|
*/
|
||
|
User(const Json::Value &pJson, const std::vector<std::string> &pMasqueradingVector) noexcept(false);
|
||
|
|
||
|
User() = default;
|
||
|
|
||
|
void updateByJson(const Json::Value &pJson) noexcept(false);
|
||
|
void updateByMasqueradedJson(const Json::Value &pJson,
|
||
|
const std::vector<std::string> &pMasqueradingVector) noexcept(false);
|
||
|
static bool validateJsonForCreation(const Json::Value &pJson, std::string &err);
|
||
|
static bool validateMasqueradedJsonForCreation(const Json::Value &,
|
||
|
const std::vector<std::string> &pMasqueradingVector,
|
||
|
std::string &err);
|
||
|
static bool validateJsonForUpdate(const Json::Value &pJson, std::string &err);
|
||
|
static bool validateMasqueradedJsonForUpdate(const Json::Value &,
|
||
|
const std::vector<std::string> &pMasqueradingVector,
|
||
|
std::string &err);
|
||
|
static bool validJsonOfField(size_t index,
|
||
|
const std::string &fieldName,
|
||
|
const Json::Value &pJson,
|
||
|
std::string &err,
|
||
|
bool isForCreation);
|
||
|
|
||
|
/** For column id */
|
||
|
///Get the value of the column id, returns the default value if the column is null
|
||
|
const uint64_t &getValueOfId() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<uint64_t> &getId() const noexcept;
|
||
|
///Set the value of the column id
|
||
|
void setId(const uint64_t &pId) noexcept;
|
||
|
|
||
|
/** For column gitlab */
|
||
|
///Get the value of the column gitlab, returns the default value if the column is null
|
||
|
const uint64_t &getValueOfGitlab() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<uint64_t> &getGitlab() const noexcept;
|
||
|
///Set the value of the column gitlab
|
||
|
void setGitlab(const uint64_t &pGitlab) noexcept;
|
||
|
|
||
|
/** For column name */
|
||
|
///Get the value of the column name, returns the default value if the column is null
|
||
|
const std::string &getValueOfName() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<std::string> &getName() const noexcept;
|
||
|
///Set the value of the column name
|
||
|
void setName(const std::string &pName) noexcept;
|
||
|
void setName(std::string &&pName) noexcept;
|
||
|
|
||
|
/** For column password */
|
||
|
///Get the value of the column password, returns the default value if the column is null
|
||
|
const std::string &getValueOfPassword() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<std::string> &getPassword() const noexcept;
|
||
|
///Set the value of the column password
|
||
|
void setPassword(const std::string &pPassword) noexcept;
|
||
|
void setPassword(std::string &&pPassword) noexcept;
|
||
|
|
||
|
/** For column role */
|
||
|
///Get the value of the column role, returns the default value if the column is null
|
||
|
const uint64_t &getValueOfRole() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<uint64_t> &getRole() const noexcept;
|
||
|
///Set the value of the column role
|
||
|
void setRole(const uint64_t &pRole) noexcept;
|
||
|
|
||
|
/** For column root_id */
|
||
|
///Get the value of the column root_id, returns the default value if the column is null
|
||
|
const uint64_t &getValueOfRootId() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<uint64_t> &getRootId() const noexcept;
|
||
|
///Set the value of the column root_id
|
||
|
void setRootId(const uint64_t &pRootId) noexcept;
|
||
|
|
||
|
/** For column tfa_type */
|
||
|
///Get the value of the column tfa_type, returns the default value if the column is null
|
||
|
const uint64_t &getValueOfTfaType() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<uint64_t> &getTfaType() const noexcept;
|
||
|
///Set the value of the column tfa_type
|
||
|
void setTfaType(const uint64_t &pTfaType) noexcept;
|
||
|
|
||
|
/** For column tfa_secret */
|
||
|
///Get the value of the column tfa_secret, returns the default value if the column is null
|
||
|
const std::vector<char> &getValueOfTfaSecret() const noexcept;
|
||
|
///Return the column value by std::string with binary data
|
||
|
std::string getValueOfTfaSecretAsString() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<std::vector<char>> &getTfaSecret() const noexcept;
|
||
|
///Set the value of the column tfa_secret
|
||
|
void setTfaSecret(const std::vector<char> &pTfaSecret) noexcept;
|
||
|
void setTfaSecret(const std::string &pTfaSecret) noexcept;
|
||
|
void setTfaSecretToNull() noexcept;
|
||
|
|
||
|
/** For column gitlab_at */
|
||
|
///Get the value of the column gitlab_at, returns the default value if the column is null
|
||
|
const std::string &getValueOfGitlabAt() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<std::string> &getGitlabAt() const noexcept;
|
||
|
///Set the value of the column gitlab_at
|
||
|
void setGitlabAt(const std::string &pGitlabAt) noexcept;
|
||
|
void setGitlabAt(std::string &&pGitlabAt) noexcept;
|
||
|
void setGitlabAtToNull() noexcept;
|
||
|
|
||
|
/** For column gitlab_rt */
|
||
|
///Get the value of the column gitlab_rt, returns the default value if the column is null
|
||
|
const std::string &getValueOfGitlabRt() const noexcept;
|
||
|
///Return a shared_ptr object pointing to the column const value, or an empty shared_ptr object if the column is null
|
||
|
const std::shared_ptr<std::string> &getGitlabRt() const noexcept;
|
||
|
///Set the value of the column gitlab_rt
|
||
|
void setGitlabRt(const std::string &pGitlabRt) noexcept;
|
||
|
void setGitlabRt(std::string &&pGitlabRt) noexcept;
|
||
|
void setGitlabRtToNull() noexcept;
|
||
|
|
||
|
|
||
|
static size_t getColumnNumber() noexcept { return 10; }
|
||
|
static const std::string &getColumnName(size_t index) noexcept(false);
|
||
|
|
||
|
Json::Value toJson() const;
|
||
|
Json::Value toMasqueradedJson(const std::vector<std::string> &pMasqueradingVector) const;
|
||
|
/// Relationship interfaces
|
||
|
private:
|
||
|
friend drogon::orm::Mapper<User>;
|
||
|
#ifdef __cpp_impl_coroutine
|
||
|
friend drogon::orm::CoroMapper<User>;
|
||
|
#endif
|
||
|
static const std::vector<std::string> &insertColumns() noexcept;
|
||
|
void outputArgs(drogon::orm::internal::SqlBinder &binder) const;
|
||
|
const std::vector<std::string> updateColumns() const;
|
||
|
void updateArgs(drogon::orm::internal::SqlBinder &binder) const;
|
||
|
///For mysql or sqlite3
|
||
|
void updateId(const uint64_t id);
|
||
|
std::shared_ptr<uint64_t> id_;
|
||
|
std::shared_ptr<uint64_t> gitlab_;
|
||
|
std::shared_ptr<std::string> name_;
|
||
|
std::shared_ptr<std::string> password_;
|
||
|
std::shared_ptr<uint64_t> role_;
|
||
|
std::shared_ptr<uint64_t> rootId_;
|
||
|
std::shared_ptr<uint64_t> tfaType_;
|
||
|
std::shared_ptr<std::vector<char>> tfaSecret_;
|
||
|
std::shared_ptr<std::string> gitlabAt_;
|
||
|
std::shared_ptr<std::string> gitlabRt_;
|
||
|
struct MetaData
|
||
|
{
|
||
|
const std::string colName_;
|
||
|
const std::string colType_;
|
||
|
const std::string colDatabaseType_;
|
||
|
const ssize_t colLength_;
|
||
|
const bool isAutoVal_;
|
||
|
const bool isPrimaryKey_;
|
||
|
const bool notNull_;
|
||
|
};
|
||
|
static const std::vector<MetaData> metaData_;
|
||
|
bool dirtyFlag_[10]={ false };
|
||
|
public:
|
||
|
static const std::string &sqlForFindingByPrimaryKey()
|
||
|
{
|
||
|
static const std::string sql="select * from " + tableName + " where id = ?";
|
||
|
return sql;
|
||
|
}
|
||
|
|
||
|
static const std::string &sqlForDeletingByPrimaryKey()
|
||
|
{
|
||
|
static const std::string sql="delete from " + tableName + " where id = ?";
|
||
|
return sql;
|
||
|
}
|
||
|
std::string sqlForInserting(bool &needSelection) const
|
||
|
{
|
||
|
std::string sql="insert into " + tableName + " (";
|
||
|
size_t parametersCount = 0;
|
||
|
needSelection = false;
|
||
|
if(dirtyFlag_[1])
|
||
|
{
|
||
|
sql += "gitlab,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[2])
|
||
|
{
|
||
|
sql += "name,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[3])
|
||
|
{
|
||
|
sql += "password,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[4])
|
||
|
{
|
||
|
sql += "role,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[5])
|
||
|
{
|
||
|
sql += "root_id,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[6])
|
||
|
{
|
||
|
sql += "tfa_type,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[7])
|
||
|
{
|
||
|
sql += "tfa_secret,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[8])
|
||
|
{
|
||
|
sql += "gitlab_at,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(dirtyFlag_[9])
|
||
|
{
|
||
|
sql += "gitlab_rt,";
|
||
|
++parametersCount;
|
||
|
}
|
||
|
if(parametersCount > 0)
|
||
|
{
|
||
|
sql[sql.length()-1]=')';
|
||
|
sql += " values (";
|
||
|
}
|
||
|
else
|
||
|
sql += ") values (";
|
||
|
|
||
|
if(dirtyFlag_[1])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[2])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[3])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[4])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[5])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[6])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[7])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[8])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(dirtyFlag_[9])
|
||
|
{
|
||
|
sql.append("?,");
|
||
|
|
||
|
}
|
||
|
if(parametersCount > 0)
|
||
|
{
|
||
|
sql.resize(sql.length() - 1);
|
||
|
}
|
||
|
sql.append(1, ')');
|
||
|
LOG_TRACE << sql;
|
||
|
return sql;
|
||
|
}
|
||
|
};
|
||
|
} // namespace sqlite3
|
||
|
} // namespace drogon_model
|