diff --git a/src/pglab/CodeBuilderConfiguration.cpp b/src/pglab/CodeBuilderConfiguration.cpp new file mode 100644 index 0000000..1cb8dae --- /dev/null +++ b/src/pglab/CodeBuilderConfiguration.cpp @@ -0,0 +1,8 @@ +#include "CodeBuilderConfiguration.h" +#include "Pgsql_Result.h" + + +QString CodeBuilder::GenClassDefinition(const Pgsql::Result &result) const +{ + +} diff --git a/src/pglab/CodeBuilderConfiguration.h b/src/pglab/CodeBuilderConfiguration.h new file mode 100644 index 0000000..f247769 --- /dev/null +++ b/src/pglab/CodeBuilderConfiguration.h @@ -0,0 +1,120 @@ +#pragma once + +#include +#include +#include + +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; +};