2018-10-31 16:45:27 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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
|
2018-10-31 16:45:27 +08:00
|
|
|
* 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
|
2018-10-31 16:45:27 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <drogon/config.h>
|
|
|
|
#include <json/json.h>
|
2018-11-11 12:02:48 +08:00
|
|
|
#include <drogon/orm/DbClient.h>
|
2018-11-02 10:03:50 +08:00
|
|
|
using namespace drogon::orm;
|
2018-10-31 16:45:27 +08:00
|
|
|
#include <drogon/DrObject.h>
|
|
|
|
#include "CommandHandler.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace drogon;
|
2018-11-02 10:03:50 +08:00
|
|
|
|
2018-10-31 16:45:27 +08:00
|
|
|
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;
|
2018-10-31 16:45:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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> ¶meters) override;
|
|
|
|
virtual std::string script() override
|
|
|
|
{
|
|
|
|
return "create Model classes files";
|
|
|
|
}
|
2018-10-31 16:45:27 +08:00
|
|
|
|
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);
|
2018-10-31 16:45:27 +08:00
|
|
|
#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);
|
2018-10-31 16:45:27 +08:00
|
|
|
#endif
|
2019-05-18 20:39:57 +08:00
|
|
|
std::string _dbname;
|
2018-10-31 16:45:27 +08:00
|
|
|
};
|
2019-05-18 20:39:57 +08:00
|
|
|
} // namespace drogon_ctl
|