Codegen now supports the database column type in the field template.
This allows for inserting it as a comment which is very useful while tweaking your typemappings as you can see what the input was.
This commit is contained in:
parent
be0064f730
commit
104ab5de1e
8 changed files with 49 additions and 19 deletions
|
|
@ -20,11 +20,17 @@ TypeMappings::TypeMappings(std::shared_ptr<const PgTypeContainer> types, std::in
|
|||
m_typeMap.insert(mappings.begin(), mappings.end());
|
||||
}
|
||||
|
||||
QString TypeMappings::getTypeForOid(Oid oid) const
|
||||
TypeMappingResult TypeMappings::getTypeForOid(Oid oid) const
|
||||
{
|
||||
auto res = m_typeMap.find(oid);
|
||||
if (res != m_typeMap.end()) {
|
||||
return res->second;
|
||||
QString dbtypename;
|
||||
if (m_types) {
|
||||
PgType type = m_types->getByKey(oid);
|
||||
dbtypename = type.name;
|
||||
}
|
||||
|
||||
return { res->second, dbtypename };
|
||||
}
|
||||
|
||||
if (m_types) {
|
||||
|
|
@ -35,6 +41,7 @@ QString TypeMappings::getTypeForOid(Oid oid) const
|
|||
// for the language config. If that isn't right the end user should create a specific mapping for
|
||||
// that array type.
|
||||
res = m_typeMap.find(type.elem);
|
||||
PgType elem_type = m_types->getByKey(type.elem);
|
||||
QString type_string;
|
||||
if (res == m_typeMap.end()) {
|
||||
type_string = m_defaultStringType;
|
||||
|
|
@ -42,10 +49,17 @@ QString TypeMappings::getTypeForOid(Oid oid) const
|
|||
else {
|
||||
type_string = res->second;
|
||||
}
|
||||
return QString(m_defaultContainerType).arg(type_string);
|
||||
return {
|
||||
QString(m_defaultContainerType).arg(type_string),
|
||||
elem_type.name + "[]"
|
||||
};
|
||||
}
|
||||
else {
|
||||
return { m_defaultStringType, type.name };
|
||||
}
|
||||
}
|
||||
return m_defaultStringType;
|
||||
// We shouldn't get here unless m_types is empty
|
||||
return { m_defaultStringType, QString() };
|
||||
}
|
||||
|
||||
void TypeMappings::setTypes(std::shared_ptr<const PgTypeContainer> types)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue