drogon/drogon_ctl/create_model.h

80 lines
2.2 KiB
C
Raw Normal View History

/**
*
* create_model.h
* An Tao
*
* Copyright 2018, An Tao. All rights reserved.
2018-12-07 15:50:18 +08:00
* https://github.com/an-tao/drogon
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
2018-11-16 13:26:14 +08:00
* Drogon
*
*/
#pragma once
#include <drogon/config.h>
#include <json/json.h>
2018-11-11 12:02:48 +08:00
#include <drogon/orm/DbClient.h>
using namespace drogon::orm;
#include <drogon/DrObject.h>
#include "CommandHandler.h"
#include <string>
using namespace drogon;
namespace drogon_ctl
{
struct ColumnInfo
{
2019-05-18 20:39:57 +08:00
std::string _colName;
std::string _colValName;
std::string _colTypeName;
std::string _colType;
std::string _colDatabaseType;
std::string _dbType;
ssize_t _colLength = 0;
size_t _index = 0;
bool _isAutoVal = false;
bool _isPrimaryKey = false;
bool _notNull = false;
bool _hasDefaultVal = false;
};
class create_model : public DrObject<create_model>, public CommandHandler
{
2019-05-18 20:39:57 +08:00
public:
virtual void handleCommand(std::vector<std::string> &parameters) override;
virtual std::string script() override
{
return "create Model classes files";
}
2019-05-18 20:39:57 +08:00
protected:
void createModel(const std::string &path);
void createModel(const std::string &path, const Json::Value &config);
#if USE_POSTGRESQL
2019-05-18 20:39:57 +08:00
void createModelClassFromPG(const std::string &path,
const DbClientPtr &client,
const std::string &tableName);
void createModelFromPG(const std::string &path, const DbClientPtr &client);
2018-12-01 11:38:05 +08:00
#endif
#if USE_MYSQL
2019-05-18 20:39:57 +08:00
void createModelClassFromMysql(const std::string &path,
const DbClientPtr &client,
const std::string &tableName);
void createModelFromMysql(const std::string &path,
const DbClientPtr &client);
2018-12-28 18:22:02 +08:00
#endif
#if USE_SQLITE3
2019-05-18 20:39:57 +08:00
void createModelClassFromSqlite3(const std::string &path,
const DbClientPtr &client,
const std::string &tableName);
void createModelFromSqlite3(const std::string &path,
const DbClientPtr &client);
#endif
2019-05-18 20:39:57 +08:00
std::string _dbname;
};
2019-05-18 20:39:57 +08:00
} // namespace drogon_ctl