2018-10-31 08:45:27 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* create_model.h
|
|
|
|
* An Tao
|
|
|
|
*
|
|
|
|
* Copyright 2018, An Tao. All rights reserved.
|
2018-12-07 07:50:18 +00:00
|
|
|
* https://github.com/an-tao/drogon
|
2018-10-31 08:45:27 +00:00
|
|
|
* Use of this source code is governed by a MIT license
|
|
|
|
* that can be found in the License file.
|
|
|
|
*
|
2018-11-16 05:26:14 +00:00
|
|
|
* Drogon
|
2018-10-31 08:45:27 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <drogon/config.h>
|
|
|
|
#include <json/json.h>
|
2018-11-21 07:18:41 +00:00
|
|
|
#if USE_ORM
|
2018-11-11 04:02:48 +00:00
|
|
|
#include <drogon/orm/DbClient.h>
|
2018-11-02 02:03:50 +00:00
|
|
|
using namespace drogon::orm;
|
2018-10-31 08:45:27 +00:00
|
|
|
#endif
|
|
|
|
#include <drogon/DrObject.h>
|
|
|
|
#include "CommandHandler.h"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace drogon;
|
2018-11-02 02:03:50 +00:00
|
|
|
|
2018-10-31 08:45:27 +00:00
|
|
|
|
|
|
|
namespace drogon_ctl
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ColumnInfo
|
|
|
|
{
|
|
|
|
std::string _colName;
|
|
|
|
std::string _colValName;
|
|
|
|
std::string _colTypeName;
|
|
|
|
std::string _colType;
|
2018-11-05 08:00:49 +00:00
|
|
|
std::string _colDatabaseType;
|
|
|
|
std::string _dbType;
|
2018-12-07 11:08:17 +00:00
|
|
|
ssize_t _colLength = 0;
|
2018-12-04 14:46:33 +00:00
|
|
|
size_t _index = 0;
|
2018-10-31 08:45:27 +00:00
|
|
|
bool _isAutoVal = false;
|
|
|
|
bool _isPrimaryKey = false;
|
|
|
|
bool _notNull = false;
|
|
|
|
bool _hasDefaultVal = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
class create_model : public DrObject<create_model>, public CommandHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void handleCommand(std::vector<std::string> ¶meters) override;
|
|
|
|
virtual std::string script() override { return "create Model classes files"; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void createModel(const std::string &path);
|
|
|
|
void createModel(const std::string &path, const Json::Value &config);
|
|
|
|
#if USE_POSTGRESQL
|
2018-11-11 04:02:48 +00: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 03:38:05 +00:00
|
|
|
#endif
|
|
|
|
#if USE_MYSQL
|
|
|
|
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 10:22:02 +00:00
|
|
|
#endif
|
|
|
|
#if USE_SQLITE3
|
|
|
|
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 08:45:27 +00:00
|
|
|
#endif
|
|
|
|
std::string _dbname;
|
|
|
|
};
|
|
|
|
} // namespace drogon_ctl
|