Emulates a python object for the data which is returned from rethinkdb and the official Python client driver. Raw data from the database is stored in _data to keep the objects namespace clean. For more information look at how _get() and _set() function in order to keep the namespace cleaner but still provide easy access to data.
This object has a __repr__ method which can be used with print or logging statements. It will give the id and a representation of the internal _data dict for debugging purposes.
The table which this document object will be stored in
The current primary key of the table
Can either be Hard or Soft, and is passed to RethinkDB
Determins if the transaction can be non atomic or not
Will either update, or create a new object if true and a primary key is given.
Initializes the main object, if id is in kwargs, then we assume this is already in the database, and will try to pull its data, if not, then we assume this is a new entry that will be inserted.
(Optional, only if not using .repl()) conn or connection can also be passed, which will be used in all the .run() clauses.
A hook called at the end of the main __init__ to allow for custom inherited classes to customize their init process without having to redo all of the existing int. This should accept nothing besides self and nothing should be returned.
Deletes the given item from the objects _data dict, or if from the objects namespace, if it does not exist in _data.
Allows for the use of syntax similar to:
if "blah" in model:
This only works with the internal _data, and does not include other properties in the objects namepsace.
Creates a new instance, filling out the models data with the keyword arguments passed, so long as those keywords are not in the protected items array.
Similar to new() however this calls save() on the object before returning it.
Loads an existing entry if one can be found, otherwise an exception is raised.
Parameters: | id (Str) – The id of the given entry |
---|---|
Returns: | cls instance of the given id entry |
If an id exists in the database, we assume we’ll update it, and if not then we’ll insert it. This could be a problem with creating your own id’s on new objects, however luckily, we keep track of if this is a new object through a private _new variable, and use that to determine if we insert or update.
A way to fetch groupings of documents that meet a criteria and have them in an iterable storage object, with each document represented by RethinkModel objects
Instantiates a new collection, using the given models table, and wrapping all documents with the given model.
Filter can be a dictionary or lambda, similar to the filters for the RethinkDB drivers filters.
Performs an eqJoin on with the given model. The resulting join will be accessible through the models name.
Like joinOn but allows setting the joined results name to access it from.
Performs an eqJoin on with the given model. The resulting join will be accessible through the given name.