|
def | __del__ (self) |
| Standard destructor to automatically close the database connection. More...
|
|
def | __getitem__ (self, key, value=None) |
| Utility function to allow the database object itself to work like a big DB2 store. More...
|
|
def | __init__ (self, connectionname=None, dbname=None, dbhost='localhost', dbtype='sqlite', dbuser=None, dbpassword=None, dbflags=DB_SECURE|DB_TRACK_CHANGES|DB_TRACK_VALUES, closeondelete=1) |
| Basic database constructor. More...
|
|
def | __setitem__ (self, key, value) |
| Utility function to allow the database object itself to work like a big DB2 store. More...
|
|
def | ApplyAccess (self, origaccess, newaccess) |
| Utility function to calculate access control. More...
|
|
def | ApplyACL (self, access, aclid) |
| Get the rules for the given ACL. More...
|
|
def | Begin (self) |
| Begins a transaction. More...
|
|
def | Close (self) |
| Close the database connection. More...
|
|
def | Commit (self) |
| Commits the current transaction. More...
|
|
def | CreateLinkTable (self, obj1, obj2) |
| Creates the link table if necessary. More...
|
|
def | Debug (self, state) |
| Enable or disable query debugging. More...
|
|
def | Delete (self, model, cond='', params=[]) |
| Deletes the given object or objects of the same type matching cond and params. More...
|
|
def | Execute (self, query, params=[], many=0, returndict=0) |
| Executes a query upon the database. More...
|
|
def | ExecuteMany (self, query, params=[]) |
| Convenience function to execute many statements at once. More...
|
|
def | Find (self, model, cond='', params=[], **kwargs) |
| The Pafera equivalent to SQL SELECT. More...
|
|
def | GetAccess (self, obj) |
| Utility function to calculate the current user's access to the given database object. More...
|
|
def | GetACL (self, aclid) |
| Get the rules for the given ACL. More...
|
|
def | GetLinkTable (self, obj1, obj2) |
| Utility function to get the name of the database table between two objects. More...
|
|
def | HasGroup (self, groupname) |
| Returns true if the current user belongs to the given group. More...
|
|
def | HasLink (self, model1, model1id, model2, model2id, linktype=0) |
| Convenience function to check if two objects are linked without actually loading the objects themselves. More...
|
|
def | HasTable (self, table) |
| Quick utility function to see if a table exists. More...
|
|
def | Insert (self, obj) |
| db.Insert(), db.Update(), and db.Replace() are all convenient wrappers to the underlying db.Save() function for easier readability of code. More...
|
|
def | Link (self, obj1, obj2, linktype=0, linknum=0, comment='', flags=0) |
| Linking is one of the fundamental concepts in Pafera. More...
|
|
def | LinkArray (self, obj1, obj2list, linktype=0, comment='', flags=0) |
| A version of db.Link() that will erase all previous links of the same type and store the given links as an array. More...
|
|
def | Linked (self, obj1, model2, linktype=0, start=0, limit=1000, fields=' *', orderby='', cond='', params=[]) |
| Return the list of objects linked to this object with the given linktype. More...
|
|
def | LinkedToID (self, model1, model1id, model2, linktype=0, start=0, limit=1000, fields=' *', orderby='', cond='', params=[]) |
| Convenience function for checking what objects are linked to model1id without having to load the object itself. More...
|
|
def | Load (self, model, objid, fields=' *') |
| Loads an object given its ID. More...
|
|
def | LoadMany (self, model, ids, fields=' *') |
| Does the same thing as db.Load(), only you can load a number of objects at once. More...
|
|
def | MapFieldType (self, fieldtype) |
| This function is responsible for mapping python types to their database representations. More...
|
|
def | Query (self, query, params=[]) |
| Convenience function to execute many statements at once. More...
|
|
def | RegisterModel (self, model) |
| All models must be registered before use, which means creating the table, indexes, and storing a record of the model for use in the web database management interface. More...
|
|
def | Replace (self, obj) |
| db.Insert(), db.Update(), and db.Replace() are all convenient wrappers to the underlying db.Save() function for easier readability of code. More...
|
|
def | RequireGroup (self, groupname, errmsg) |
| Throws an exception if the current user does not belong to one of the groups listed in groupname. More...
|
|
def | Rollback (self) |
| Rolls back the current transaction. More...
|
|
def | Save (self, obj, method='') |
| This is the function where we convert python types and store them into the database. More...
|
|
def | Sudo (self, state) |
| Enable or disable administrator mode, bypassing security for the current user. More...
|
|
def | Unlink (self, obj1, obj2, linktype=0) |
| Unlink two objects, or if obj2 is a model, unlink every object of the given linktype. More...
|
|
def | UnregisterModel (self, model) |
| Removes the model from the system registry. More...
|
|
def | Update (self, obj) |
| db.Insert(), db.Update(), and db.Replace() are all convenient wrappers to the underlying db.Save() function for easier readability of code. More...
|
|
The main database object.
Note that Pafera allows you to create as many database objects as you want, so you can keep one part of your logic in a MySQL database, one part in an Sqlite database, and so forth.
The current access is saved in db.userid and db.groups. Root access can be enabled at any time by calling db.Sudo(), while debugging is enabled through db.Debug().
Definition at line 163 of file db.py.
def pafera.db.DB.Link |
( |
|
self, |
|
|
|
obj1, |
|
|
|
obj2, |
|
|
|
linktype = 0 , |
|
|
|
linknum = 0 , |
|
|
|
comment = '' , |
|
|
|
flags = 0 |
|
) |
| |
Linking is one of the fundamental concepts in Pafera.
It's essentially a foreign key mechanism that can link two arbitary objects via their database IDs, thus you can do things like
u = new user g = new group
Link the user and group
db.Link(u, g)
prints g's information
print(db.Linked(u, group))
Linking is a bidirectional operation, meaning that both db.Linked(u, group) and db.Linked(g, user) will work. For unidirectional links, it's suggested to store the linked IDs in a NEWLINELIST field in an object itself.
Behind the scenes, linking works by create a separate table that connects IDs between one table and other. Any attempt to find links are returned in a DBList() object which performs a SQL JOIN for one query results.
Linking supports different types of links via the linktype parameter.
The linknum parameter is used to create results that are returned in order of linknum, guaranteeing that the same sequence will be returned every time.
flags can be used to store application-specific meanings outside of linktype.
Definition at line 1204 of file db.py.