2 How to Define a Data Class

To define a PyDO data class, the first thing to do is inherit from the PyDO base class. From there, you define a series of class attributes to configure the object.

The connectionAlias attribute specifies the connection alias mentioned above to determine which connection to use.

The table attribute specifies what database table this object maps to. Multiple dataclasses may point at the same database table.

The fields attribute is a tuple of two-tuples of column name (or field name)/database type. The case of the field name is significant. For all intents and purposes, use upper case unless the documentation for your database driver says otherwise (none of them currently do, or even have docs either for that matter). If you have multiple data classes pointing at the same database table, they need not specify the same field tuples (they can though).

Data class instances are mutable unless you say mutable = 0 in the definition of your data class.

If you would like for fields in rows to be populated with values from sequences (on databases that have named sequences, i.e. oracle) when creating new rows, this can be done by specifying the sequenced attribute as a dictionary of fieldname:sequence name pairs.

If you would like to fetch fields that are populated via the auto-increment feature of your database (if it has one, like MySQL, oracle doesn't) on insert, this can be done by specifying the auto_increment attribute as a dictionary of fieldname:autoincname pairs. In the case that autoincrement field fetches aren't named (i.e. MySQL), just specify 1 as the autoincname, and beware then that you can have only one item in the dictionary.

For some methods (i.e. getUnique, delete, refresh, etc.) that PyDO has, it requires that it be able to obtain a unique row given a set of column names/values. The way to specify this is to set the unique attribute on your data class to a list of strings or tuples of strings (can mix and match) that identify that either this column (in the case of a string) or this set of columns (tuple of strings) uniquely identifies a row.

Other attributes defined in a data class definition are ignored and will not be present in the actual class.

If you want to add attributes into a data class instance, define the __init__ method (it will have no argument other than self) and it can define whatever other instance attributes it likes, although redefining data class attributes will have undefined behavior (it might work *shrug*).