First attempt at configuration for code generation.
This commit is contained in:
parent
976623ca9b
commit
ee353d7da8
2 changed files with 128 additions and 0 deletions
8
src/pglab/CodeBuilderConfiguration.cpp
Normal file
8
src/pglab/CodeBuilderConfiguration.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "CodeBuilderConfiguration.h"
|
||||||
|
#include "Pgsql_Result.h"
|
||||||
|
|
||||||
|
|
||||||
|
QString CodeBuilder::GenClassDefinition(const Pgsql::Result &result) const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
120
src/pglab/CodeBuilderConfiguration.h
Normal file
120
src/pglab/CodeBuilderConfiguration.h
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
#include <libpq-fe.h>
|
||||||
|
|
||||||
|
namespace Pgsql { class Result; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
class PgAuthId {
|
||||||
|
public:
|
||||||
|
PgAuthId();
|
||||||
|
|
||||||
|
Oid oid = InvalidOid;
|
||||||
|
QString name;
|
||||||
|
bool super;
|
||||||
|
bool inherit;
|
||||||
|
bool createRole;
|
||||||
|
bool createDB;
|
||||||
|
bool canlogin;
|
||||||
|
bool replication;
|
||||||
|
bool bypassRls;
|
||||||
|
int connLimit;
|
||||||
|
QDateTime validUntil;*/
|
||||||
|
|
||||||
|
/** Defines how a database result fieldname should be converted into a variable
|
||||||
|
* name in the target language.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class VarNameManglingRules {
|
||||||
|
public:
|
||||||
|
enum class CollisionHandling {
|
||||||
|
Restrict, ///< An error will be reported and no code generated
|
||||||
|
Fqn, ///< Turn into fully qualified name (table_column)
|
||||||
|
Number ///< A number will be appended to fields that have the same name
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class CaseConversion {
|
||||||
|
AsIs,
|
||||||
|
Upper,
|
||||||
|
Lower
|
||||||
|
};
|
||||||
|
|
||||||
|
QString replaceSpaceWith; ///< default is empty string which means remove spaces
|
||||||
|
CollisionHandling CollisionHandling = CollisionHandling::Restrict;
|
||||||
|
CaseConversion caseConversion = CaseConversion::AsIs; ///< overall case conversion rule
|
||||||
|
CaseConversion caseFirstChar = CaseConversion::AsIs; ///< case of the first char
|
||||||
|
bool underscoreToCamel = false; ///< remove underscores and make first char after underscore uppercase
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class LanguageConfig {
|
||||||
|
public:
|
||||||
|
/** Default template for declaring a variable of the correct type.
|
||||||
|
* exmaple: "{$type} {$varname};"
|
||||||
|
*/
|
||||||
|
QString varDeclTemplate;
|
||||||
|
VarNameManglingRules varNaming;
|
||||||
|
|
||||||
|
enum class VariableStrategy {
|
||||||
|
UseLocalVariables,
|
||||||
|
DeclareClass
|
||||||
|
};
|
||||||
|
|
||||||
|
QString classStartTemplate;
|
||||||
|
QString classEndTemplate;
|
||||||
|
QString classFieldTemplate;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* There are some default fallbacks in place
|
||||||
|
* - smallint > integer
|
||||||
|
* - integer > bigint
|
||||||
|
* - int2 > smallint
|
||||||
|
* - int4 > integer
|
||||||
|
* - int8 > bigint
|
||||||
|
*
|
||||||
|
* - float > double
|
||||||
|
* - text > varchar
|
||||||
|
*/
|
||||||
|
class TypeConfig {
|
||||||
|
public:
|
||||||
|
/** The following template allows you to derive the variable name from the result fieldname.
|
||||||
|
*
|
||||||
|
* {$} in the suplied value will be replaced with the name of the result field.
|
||||||
|
*
|
||||||
|
* example: {$}
|
||||||
|
*/
|
||||||
|
QString varNameTemplate;
|
||||||
|
QString typeIdent;
|
||||||
|
QString varDeclTemplate; ///< Overrules the default template in the language config
|
||||||
|
|
||||||
|
// Mapping() = default;
|
||||||
|
// Mapping(Oid oid, QString lang_type_ident)
|
||||||
|
// : db_oid(oid), lang_type(lang_type_ident)
|
||||||
|
// {}
|
||||||
|
//
|
||||||
|
// bool operator < (const Mapping &rhs) const
|
||||||
|
// {
|
||||||
|
// return db_oid < rhs.db_oid;
|
||||||
|
// }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TypeMappings {
|
||||||
|
public:
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
class CodeBuilderConfiguration {
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
|
class CodeBuilder {
|
||||||
|
public:
|
||||||
|
QString GenClassDefinition(const Pgsql::Result &result) const;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue