HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ORMModelMeta Class Referenceabstract

#include <UT_ORMModelMeta.h>

+ Inheritance diagram for UT_ORMModelMeta:

Classes

struct  Related
 

Public Member Functions

 UT_ORMModelMeta (const UT_StringHolder &name, UT_SqlOrm *orm=nullptr)
 
 UT_ORMModelMeta ()
 
virtual ~UT_ORMModelMeta ()=default
 
 UT_NON_COPYABLE (UT_ORMModelMeta)
 
void setTableName (const UT_StringHolder &name)
 
void setModelName (const UT_StringHolder &name)
 
void setVerboseName (const UT_StringHolder &name)
 
void setPluralVerboseName (const UT_StringHolder &name)
 
void build (UT_SqlOrm &orm)
 Call to build out all of your meta information. More...
 
void connectLinks ()
 Called after all models concrete information has been connected. More...
 
virtual void collectMigrations (UT_ORMMigrationBuilder &builder) const =0
 
virtual void preConnectLinks ()
 Called right before connecting the links on each model. More...
 
void postMigrate ()
 
template<typename Cls , typename FieldT >
void addAutoField (const UT_StringHolder &name, FieldT Cls::*field, unsigned props=UT_ORMColumn::Empty)
 
template<typename Cls , typename FieldT >
void addField (const UT_StringHolder &name, FieldT Cls::*field, unsigned props=UT_ORMColumn::Empty)
 
template<typename Cls , typename ForeignModel >
void addField (const UT_StringHolder &name, UT_ORMForeignKeyField< ForeignModel > Cls::*field, unsigned props=UT_ORMColumn::Empty, UT_ORMColumn::OnDelete ondelete_type=UT_ORMColumn::OnDelete::Cascade, const UT_StringHolder &related_name=UT_StringHolder::theEmptyString, const UT_ORMModelMeta &foreign_meta=ForeignModel::metaInfo())
 
template<typename Owner , typename OtherModel >
void addField (const UT_StringHolder &name, UT_ORMManyToManyField< Owner, OtherModel > Owner::*field, const UT_StringHolder &related_name=UT_StringHolder::theEmptyString)
 
const UT_StringHoldertableName () const
 
const UT_StringHoldermodelName () const
 
const UT_StringHolderverboseName () const
 
const UT_StringHolderpluralVerboseName () const
 
const UT_ORMFieldColumnprimaryKey () const
 
const UT_Array
< UT_ORMFieldColumn > & 
columns () const
 
const UT_Array< const
UT_ORMFieldColumn * > & 
foreignKeys () const
 
const UT_Array< const
UT_ORMFieldColumn * > & 
uniqueColumns () const
 
template<typename T >
bool save (T &obj, UT_ErrorCode &ec, bool force_insert=false, bool force_update=false) const
 
template<typename T >
void remove (T &obj, UT_ErrorCode &ec) const
 
template<typename T >
void remove (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
template<typename T , typename PK >
UT_Optional< Tfetch (const PK &pk, UT_ErrorCode &ec) const
 
template<typename T >
UT_Array< Tfetch (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
template<typename T >
UT_Array< TfetchAll (UT_ErrorCode &ec) const
 
template<typename T >
UT_Optional< Tfilter (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
template<typename T >
std::pair< T, bool > getOrCreate (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
template<typename T >
UT_Optional< Tcreate (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
template<typename T , typename ArrayT >
UT_Array< TbulkFetch (const ArrayT &pks, UT_ErrorCode &ec, const UT_StringRef &col_name=UT_StringHolder::theEmptyString) const
 
template<typename T >
void bulkSave (const UT_Array< T > &items, UT_ErrorCode &ec) const
 
template<typename T , typename... Args>
T fromDB (Args &&...args) const
 
template<typename T >
bool exists (const std::initializer_list< UT::orm::FilterArg > &args, UT_ErrorCode &ec) const
 
UT_SqlOrmorm () const
 
UT_SqlStatement cursor () const
 
UT_SqlDatabasedb ()
 
UT_SqlDatabasedb () const
 
template<typename T >
bool loadObject (T &obj, UT_SqlStatement &stmt, UT_ErrorCode &ec) const
 
template<typename T >
UT_Array< TloadAllObjects (UT_SqlStatement &stmt, UT_ErrorCode &ec)
 
void resetInternals ()
 
bool hasField (const UT_StringView &name) const
 
const UT_ORMFieldColumnfindField (const UT_StringView &name) const
 
const UT_ORMFieldColumnfindForeignRelatedField (const UT_StringView &name) const
 
bool registerRelated (const UT_SharedPtr< UT_ORMModelMeta > &related, const UT_StringHolder &related_name, const UT_StringHolder &fk_field_name=UT_StringHolder::theEmptyString)
 
UT_SharedPtr< UT_ORMModelMetafindRelated (const UT_StringView &name, UT_StringHolder &fk_field_name) const
 
void lookupTableColumns (const UT_StringRef &model_name, const UT_ORMFieldColumn *&fk_model, const UT_ORMFieldColumn *&fk_other_model) const
 
bool isThroughTable () const
 
UT_ORMQuerySet querySet () const
 

Protected Member Functions

virtual void doBuild ()=0
 
virtual void doPostBuild ()
 
virtual void doPostMigrate ()
 
void configureConcrete_ ()
 Configure any cacheable information that is used often. More...
 
void registerM2M_ (const UT_SharedPtr< UT_ORMModelMeta > &left, const UT_SharedPtr< UT_ORMModelMeta > &right, const UT_StringHolder &field_name, const UT_StringHolder &related_name)
 
UT_SharedPtr< UT_ORMModelMetalookupMetaFromORM_ (const UT_StringView &name) const
 
template<typename T >
bool doUpdate_ (T &obj, UT_ErrorCode &ec) const
 
template<typename T >
bool doInsert_ (T &obj, UT_ErrorCode &ec) const
 

Static Protected Member Functions

static void addDynamicColumn_ (UT_ORMModelMeta &meta, UT_ORMFieldColumn &&field)
 

Protected Attributes

bool myHasBuilt = false
 
bool myHasPostBuilt = false
 
bool myHasPostMigrate = false
 
bool myIsThroughTable = false
 
UT_StringHolder myTableName
 
UT_StringHolder myModelName
 
UT_StringHolder myVerboseName
 
UT_StringHolder myPluralVerboseName
 
const UT_ORMFieldColumnmyPrimaryKey = nullptr
 
UT_Array< const
UT_ORMFieldColumn * > 
myForeignKeys
 
UT_Array< const
UT_ORMFieldColumn * > 
myUniqueColumns
 
UT_Array< UT_ORMFieldColumnmyColumns
 
UT_Array< RelatedmyRelated
 
UT_SqlOrmmyORM = nullptr
 

Detailed Description

Definition at line 45 of file UT_ORMModelMeta.h.

Constructor & Destructor Documentation

UT_ORMModelMeta::UT_ORMModelMeta ( const UT_StringHolder name,
UT_SqlOrm orm = nullptr 
)
inline

Definition at line 48 of file UT_ORMModelMeta.h.

UT_ORMModelMeta::UT_ORMModelMeta ( )
inline

Definition at line 54 of file UT_ORMModelMeta.h.

virtual UT_ORMModelMeta::~UT_ORMModelMeta ( )
virtualdefault

Member Function Documentation

template<typename Cls , typename FieldT >
void UT_ORMModelMeta::addAutoField ( const UT_StringHolder name,
FieldT Cls::*  field,
unsigned  props = UT_ORMColumn::Empty 
)
inline

Definition at line 94 of file UT_ORMModelMeta.h.

static void UT_ORMModelMeta::addDynamicColumn_ ( UT_ORMModelMeta meta,
UT_ORMFieldColumn &&  field 
)
inlinestaticprotected

Definition at line 388 of file UT_ORMModelMeta.h.

template<typename Cls , typename FieldT >
void UT_ORMModelMeta::addField ( const UT_StringHolder name,
FieldT Cls::*  field,
unsigned  props = UT_ORMColumn::Empty 
)
inline

Definition at line 104 of file UT_ORMModelMeta.h.

template<typename Cls , typename ForeignModel >
void UT_ORMModelMeta::addField ( const UT_StringHolder name,
UT_ORMForeignKeyField< ForeignModel > Cls::*  field,
unsigned  props = UT_ORMColumn::Empty,
UT_ORMColumn::OnDelete  ondelete_type = UT_ORMColumn::OnDelete::Cascade,
const UT_StringHolder related_name = UT_StringHolder::theEmptyString,
const UT_ORMModelMeta foreign_meta = ForeignModel::metaInfo() 
)
inline

Definition at line 114 of file UT_ORMModelMeta.h.

template<typename Owner , typename OtherModel >
void UT_ORMModelMeta::addField ( const UT_StringHolder name,
UT_ORMManyToManyField< Owner, OtherModel > Owner::*  field,
const UT_StringHolder related_name = UT_StringHolder::theEmptyString 
)
inline

Definition at line 130 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::build ( UT_SqlOrm orm)

Call to build out all of your meta information.

template<typename T , typename ArrayT >
UT_Array< T > UT_ORMModelMeta::bulkFetch ( const ArrayT &  pks,
UT_ErrorCode ec,
const UT_StringRef col_name = UT_StringHolder::theEmptyString 
) const

Definition at line 778 of file UT_ORMModelMeta.h.

template<typename T >
void UT_ORMModelMeta::bulkSave ( const UT_Array< T > &  items,
UT_ErrorCode ec 
) const

Definition at line 846 of file UT_ORMModelMeta.h.

virtual void UT_ORMModelMeta::collectMigrations ( UT_ORMMigrationBuilder builder) const
pure virtual

Implemented in UT_ORMContentType::Meta.

const UT_Array<UT_ORMFieldColumn>& UT_ORMModelMeta::columns ( ) const
inline

Definition at line 150 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::configureConcrete_ ( )
protected

Configure any cacheable information that is used often.

void UT_ORMModelMeta::connectLinks ( )

Called after all models concrete information has been connected.

template<typename T >
UT_Optional< T > UT_ORMModelMeta::create ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 715 of file UT_ORMModelMeta.h.

UT_SqlStatement UT_ORMModelMeta::cursor ( ) const
UT_SqlDatabase& UT_ORMModelMeta::db ( )
UT_SqlDatabase& UT_ORMModelMeta::db ( ) const
virtual void UT_ORMModelMeta::doBuild ( )
protectedpure virtual

Implemented in UT_ORMContentType::Meta.

template<typename T >
bool UT_ORMModelMeta::doInsert_ ( T obj,
UT_ErrorCode ec 
) const
protected

Definition at line 471 of file UT_ORMModelMeta.h.

virtual void UT_ORMModelMeta::doPostBuild ( )
inlineprotectedvirtual

Definition at line 368 of file UT_ORMModelMeta.h.

virtual void UT_ORMModelMeta::doPostMigrate ( )
protectedvirtual

Reimplemented in UT_ORMContentType::Meta.

template<typename T >
bool UT_ORMModelMeta::doUpdate_ ( T obj,
UT_ErrorCode ec 
) const
protected

Definition at line 448 of file UT_ORMModelMeta.h.

template<typename T >
bool UT_ORMModelMeta::exists ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 915 of file UT_ORMModelMeta.h.

template<typename T , typename PK >
UT_Optional< T > UT_ORMModelMeta::fetch ( const PK &  pk,
UT_ErrorCode ec 
) const

Definition at line 653 of file UT_ORMModelMeta.h.

template<typename T >
UT_Array< T > UT_ORMModelMeta::fetch ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 628 of file UT_ORMModelMeta.h.

template<typename T >
UT_Array< T > UT_ORMModelMeta::fetchAll ( UT_ErrorCode ec) const

Definition at line 673 of file UT_ORMModelMeta.h.

template<typename T >
UT_Optional< T > UT_ORMModelMeta::filter ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 696 of file UT_ORMModelMeta.h.

const UT_ORMFieldColumn* UT_ORMModelMeta::findField ( const UT_StringView name) const
inline

Definition at line 289 of file UT_ORMModelMeta.h.

const UT_ORMFieldColumn* UT_ORMModelMeta::findForeignRelatedField ( const UT_StringView name) const
inline

Find a foreign concrete field based on the column name. The column name passed in must be for a local field that is a foreign key

Definition at line 300 of file UT_ORMModelMeta.h.

UT_SharedPtr<UT_ORMModelMeta> UT_ORMModelMeta::findRelated ( const UT_StringView name,
UT_StringHolder fk_field_name 
) const
const UT_Array<const UT_ORMFieldColumn*>& UT_ORMModelMeta::foreignKeys ( ) const
inline

Definition at line 151 of file UT_ORMModelMeta.h.

template<typename T , typename... Args>
T UT_ORMModelMeta::fromDB ( Args &&...  args) const
inline

Definition at line 201 of file UT_ORMModelMeta.h.

template<typename T >
std::pair< T, bool > UT_ORMModelMeta::getOrCreate ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 738 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::hasField ( const UT_StringView name) const
inline

Definition at line 279 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::isThroughTable ( ) const
inline

Definition at line 337 of file UT_ORMModelMeta.h.

template<typename T >
UT_Array<T> UT_ORMModelMeta::loadAllObjects ( UT_SqlStatement stmt,
UT_ErrorCode ec 
)
inline

Definition at line 247 of file UT_ORMModelMeta.h.

template<typename T >
bool UT_ORMModelMeta::loadObject ( T obj,
UT_SqlStatement stmt,
UT_ErrorCode ec 
) const
inline

Definition at line 218 of file UT_ORMModelMeta.h.

UT_SharedPtr<UT_ORMModelMeta> UT_ORMModelMeta::lookupMetaFromORM_ ( const UT_StringView name) const
protected
void UT_ORMModelMeta::lookupTableColumns ( const UT_StringRef model_name,
const UT_ORMFieldColumn *&  fk_model,
const UT_ORMFieldColumn *&  fk_other_model 
) const

On a lookup table split the two columns up based on the provided model. This is helpful for quickly determining which column on the lookup table belongs to the provided concrete model and the other model.

const UT_StringHolder& UT_ORMModelMeta::modelName ( ) const
inline

Definition at line 143 of file UT_ORMModelMeta.h.

UT_SqlOrm* UT_ORMModelMeta::orm ( ) const
inline

Definition at line 212 of file UT_ORMModelMeta.h.

const UT_StringHolder& UT_ORMModelMeta::pluralVerboseName ( ) const
inline

Definition at line 145 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::postMigrate ( )
virtual void UT_ORMModelMeta::preConnectLinks ( )
inlinevirtual

Called right before connecting the links on each model.

Definition at line 90 of file UT_ORMModelMeta.h.

const UT_ORMFieldColumn* UT_ORMModelMeta::primaryKey ( ) const
inline

Definition at line 149 of file UT_ORMModelMeta.h.

UT_ORMQuerySet UT_ORMModelMeta::querySet ( ) const
inline

Definition at line 339 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::registerM2M_ ( const UT_SharedPtr< UT_ORMModelMeta > &  left,
const UT_SharedPtr< UT_ORMModelMeta > &  right,
const UT_StringHolder field_name,
const UT_StringHolder related_name 
)
protected
bool UT_ORMModelMeta::registerRelated ( const UT_SharedPtr< UT_ORMModelMeta > &  related,
const UT_StringHolder related_name,
const UT_StringHolder fk_field_name = UT_StringHolder::theEmptyString 
)
template<typename T >
void UT_ORMModelMeta::remove ( T obj,
UT_ErrorCode ec 
) const

Definition at line 588 of file UT_ORMModelMeta.h.

template<typename T >
void UT_ORMModelMeta::remove ( const std::initializer_list< UT::orm::FilterArg > &  args,
UT_ErrorCode ec 
) const

Definition at line 617 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::resetInternals ( )
inline

Definition at line 265 of file UT_ORMModelMeta.h.

template<typename T >
bool UT_ORMModelMeta::save ( T obj,
UT_ErrorCode ec,
bool  force_insert = false,
bool  force_update = false 
) const

Definition at line 413 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::setModelName ( const UT_StringHolder name)
inline

Definition at line 62 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::setPluralVerboseName ( const UT_StringHolder name)
inline

Definition at line 76 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::setTableName ( const UT_StringHolder name)
inline

Definition at line 58 of file UT_ORMModelMeta.h.

void UT_ORMModelMeta::setVerboseName ( const UT_StringHolder name)
inline

Definition at line 72 of file UT_ORMModelMeta.h.

const UT_StringHolder& UT_ORMModelMeta::tableName ( ) const
inline

Definition at line 142 of file UT_ORMModelMeta.h.

const UT_Array<const UT_ORMFieldColumn*>& UT_ORMModelMeta::uniqueColumns ( ) const
inline

Definition at line 155 of file UT_ORMModelMeta.h.

UT_ORMModelMeta::UT_NON_COPYABLE ( UT_ORMModelMeta  )
const UT_StringHolder& UT_ORMModelMeta::verboseName ( ) const
inline

Definition at line 144 of file UT_ORMModelMeta.h.

Member Data Documentation

UT_Array<UT_ORMFieldColumn> UT_ORMModelMeta::myColumns
protected

Definition at line 406 of file UT_ORMModelMeta.h.

UT_Array<const UT_ORMFieldColumn*> UT_ORMModelMeta::myForeignKeys
protected

Definition at line 404 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::myHasBuilt = false
protected

Definition at line 395 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::myHasPostBuilt = false
protected

Definition at line 396 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::myHasPostMigrate = false
protected

Definition at line 397 of file UT_ORMModelMeta.h.

bool UT_ORMModelMeta::myIsThroughTable = false
protected

Definition at line 398 of file UT_ORMModelMeta.h.

UT_StringHolder UT_ORMModelMeta::myModelName
protected

Definition at line 400 of file UT_ORMModelMeta.h.

UT_SqlOrm* UT_ORMModelMeta::myORM = nullptr
protected

Definition at line 408 of file UT_ORMModelMeta.h.

UT_StringHolder UT_ORMModelMeta::myPluralVerboseName
protected

Definition at line 402 of file UT_ORMModelMeta.h.

const UT_ORMFieldColumn* UT_ORMModelMeta::myPrimaryKey = nullptr
protected

Definition at line 403 of file UT_ORMModelMeta.h.

UT_Array<Related> UT_ORMModelMeta::myRelated
protected

Definition at line 407 of file UT_ORMModelMeta.h.

UT_StringHolder UT_ORMModelMeta::myTableName
protected

Definition at line 399 of file UT_ORMModelMeta.h.

UT_Array<const UT_ORMFieldColumn*> UT_ORMModelMeta::myUniqueColumns
protected

Definition at line 405 of file UT_ORMModelMeta.h.

UT_StringHolder UT_ORMModelMeta::myVerboseName
protected

Definition at line 401 of file UT_ORMModelMeta.h.


The documentation for this class was generated from the following file: