mewlo.mpacks.core.database.mdbmodel module

mdbmodel.py

This is our database object base class.

class mewlo.mpacks.core.database.mdbmodel.MewloDbModel[source]

Bases: object

An object that represents a database model.

UNUSED_save_ifdirty()[source]

Save only if dirty. ATTN: TODO improve dirty detection – right now this will not trigger on manually created items so we rely on manual setting of isdirty.

calc_gobtypename()[source]
classmethod classdumps(indent=0)[source]

Debug information for CLASS.

classmethod compute_tableprefix()[source]

Compute the tablename prefix now that dbmanager and tablename is set

classmethod create_mapper(dbmanager)[source]

Default way of creating sql alchemy mapper and relations for model.

classmethod create_prerequisites(dbmanager)[source]

Create and register with the dbmanager any prerequisites that this class uses.

classmethod create_sqlalchemy_columns_from_dbfields()[source]

Given a list of our internal fields, build sqlalchemy columns.

classmethod create_sqlalchemy_mapperproperties_from_dbfields(modeltable)[source]

Given a list of our internal fields, build sqlalchemy mapper properties.

classmethod create_table()[source]

Default way of creating sql alchemy columns for model.

classmethod dbm()[source]

Shortcut to get info from class object.

dbmanager = None
dbschemaname = None
classmethod dbsession()[source]

Shortcut to get info from class object.

dbsqlahelper = None
dbsqlatable = None
dbtablename = None
classmethod define_fields(dbmanager)[source]

This class-level function defines the database fields for this model – the columns, etc. The subclass will implement this function. Return a list of dbfields.

delete()[source]

Delete the model from database.

classmethod delete_all()[source]

Delete all items (rows) in the table.

classmethod delete_all_bywhereclause(whereclause)[source]

Delete all that match where clause.

classmethod delete_bykey(keydict)[source]

Delete all items (rows) matching key dictionary settings.

deletefield_serialized(serialized_dict_fieldname, keyname)[source]

Remove a SERIALIZED dictionary key value.

did_create_mapper = False
did_create_prerequisites = False
did_create_table = False
dumps(indent=0)[source]

Debug information for object.

classmethod extend_fields(addfieldlist, flag_front=False)[source]

Add fields.

fieldhash = {}
fieldlist = []
classmethod find_all()[source]

Load all rows and return them as array.

classmethod find_all_advanced(keydict)[source]

Find and return all instances of object specified by keydict. :return: defaultval if not found

classmethod find_all_bycnf(cnflist)[source]

Find and return all instances of object specified by cnf list of keydicts

classmethod find_all_bygobidlist(gobidlist)[source]

Find and return matches.

classmethod find_all_bykey(keydict)[source]

Find and return all instances of object specified by keydict. :return: defaultval if not found

classmethod find_all_byprimaryidlist(primaryidlist)[source]

Find and return matches.

classmethod find_one_byflexibleid(stringfieldname, nameorid)[source]

Lookup one by primary id or by field name value.

classmethod find_one_bykey(keydict, defaultval=None)[source]

Find and return an instance object for the single row specified by keydict. :return: defaultval if not found

classmethod find_one_byprimaryid(primaryid, defaultval=None)[source]

Find and return an instance object for the single row specified by keydict. :return: defaultval if not found

classmethod find_one_bywhereclause(whereclause)[source]

Find first item matching where clause.

flush_toupdate()[source]

Important: This needs to be called after saving a new object if we need to access the id of the object.

classmethod get_dbschemaname()[source]
classmethod get_dbsqlatable()[source]
classmethod get_dbtablename()[source]
classmethod get_dbtablename_pure()[source]
classmethod get_fieldlist()[source]

Return the database fields.

get_isdirty()[source]
classmethod get_isreadytodb()[source]

Return True if this class is ready to access the database (fields have been created, etc.).

classmethod get_nowtime()[source]
getcreate_serializedbdict_forfield(serialized_dict_fieldname)[source]

Lazy create and init the serialize helper for this field if it doesn’t exist.

getcreate_serializedbdictcollection(flag_createifmissing)[source]

Lazy get/create of SerializeableDbDictCollection.

getfield_serialized(serialized_dict_fieldname, keyname, defaultval)[source]

Return the value of a SERIALIZED dictionary by key.

getid_saveifneeded()[source]

Save the object if it’s not saved yet, because we need it’s id.

gobify()[source]

Create a gob global unique resource object for us. The gob table stores the type of object it refers to (but not the foreign id in order to stay normalized).

classmethod hash_fieldlist()[source]

hash fieldlist in dictionary.

isreadytodb = False
classmethod lookup_sqlacolumn_for_field(fieldid)[source]

Try to find the list of sqlacolumns associated with a field.

classmethod lookup_sqlacolumnlist_for_field(fieldid)[source]

Try to find the list of sqlacolumns associated with a field.

mewlosite = None
classmethod new()[source]

Make a new instance of the class.

classmethod nice_datestring(atime)[source]
objmanager = None
classmethod override_dbnames(tablename, schemaname)[source]
presavemodel()[source]

Called before any model is saved.

presavemodel_serializationhelpers_updatefields()[source]

If any serialization helpers were used and there are pending changes, update fields now.

classmethod reset_classdata()[source]

Reset calculcated class variables. This is kludgey and confusing. We use these class variables to track some sqlalchemy stuff, but when performing unit tests we need this to reset before each test.

save()[source]

Update/Save the model to database.

classmethod serialize_forstorage(obj)[source]

Helper function to serialize arbitrary object.

classmethod set_dbm(mewlosite, dbmanager)[source]

Set the dbmanager, to be used when creating tables, etc.

set_isdirty(val)[source]
classmethod set_isreadytodb(val)[source]

Return True if this class is ready to access the database (fields have been created, etc.).

classmethod set_objectmanager(objectmanager)[source]

Set some info.

classmethod setclass_dbinfo(sqlatable, sqlahelper)[source]

Store data in class regarding datbase access for it.

setdict_serialized(serialized_dict_fieldname, newdict)[source]

Set the value of a SERIALIZED dictionary.

setfield_serialized(serialized_dict_fieldname, keyname, val)[source]

Set the value of a SERIALIZED dictionary by key.

classmethod unserialize_fromstorage(serializedtext, defaultval=None)[source]

Helper function to unserialize arbitrary text.

classmethod update_all_dict_bywhereclause(updatedict, whereclause)[source]

Update all with dictionary using a where clause.

Table Of Contents

Previous topic

mewlo.mpacks.core.database.mdbmixins module

Next topic

mewlo.mpacks.core.database.mdbmodel_fieldset module

This Page