RestOC.Record_ReDB module¶
Record ReDB Module
Extends Record module to add support for RethinkDB tables
-
class
RestOC.Record_ReDB.
Record
(record={}, custom={})¶ Bases:
RestOC.Record_Base.Record
Extends the base Record class
-
classmethod
addChanges
(_id, changes, customer={})¶ Add Changes
Adds a record to the tables associated _changes table. Useful for Record types that can’t handle multiple levels and have children tables that shouldn’t be updated for every change in a single record
- Parameters
_id (mixed) – The ID of the record the change is associated with
changes (dict) – The dictionary of changes to add
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
append
(_id, array, item, custom={})¶ Append
Adds an item to a given array/list for a specific record
- Parameters
_id (mixed) – The ID of the record to append to
array (str) – The name of the field with the array
item (mixed) – The value to append to the array
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
config
()¶ Config
Returns the configuration data associated with the record type
- Returns
dict
-
classmethod
contains
(_id, array, item, custom={})¶ Contains
Checks if a specific item exist inside a given array/list
- Parameters
_id (mixed) – The ID of the record to check
array (str) – The name of the field with the array
item (mixed) – The value to check for in the array
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
count
(_id=None, index=None, filter=None, custom={})¶ Count
Returns the number of records associated with index or filter
- Parameters
_ids (mixed) – The ID to check
index (str) – Used as the index instead of the primary key
filter (dict) – Additional filter
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
create
(conflict='error', changes=None)¶ Create
Adds the record to the DB and returns the primary key
- Parameters
conflict (str) – Must be one of ‘error’, ‘replace’, or ‘update’
changes (dict) – Data needed to store a change record, is dependant on the ‘changes’ config value
- Returns
mixed|None
-
classmethod
createMany
(records, conflict='error', custom={})¶ Create Many
Inserts multiple records at once, returning all their primary keys if auto_primary is true, else just returning the number of records inserted (or replaced if replace is set to True)
- Parameters
records (Record_ReDB.Record[]) – A list of Record instances to insert
conflict (str) – Must be one of ‘error’, ‘replace’, or ‘update’
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
mixed[]
-
delete
(changes=None)¶ Delete
Deletes the record represented by the instance
- Parameters
changes (dict) – Data needed to store a change record, is dependant on the ‘changes’ config value
- Returns
bool
-
classmethod
deleteGet
(_id=None, index=None, custom={})¶ Delete Get
Deletes one or many records by primary key or index and returns how many were found/deleted
- Parameters
_id (mixed|mixed[]) – The primary key(s) to delete or None for all records
index (str) – Used as the index instead of the primary key
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
int
-
classmethod
exists
(_id, index=None, custom={})¶ Exists
Returns true if the specified primary key or unique index value exists
- Parameters
_id (mixed) – The primary key to check
index (str) – Used as the index instead of the primary key
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
filter
(fields, raw=None, distinct=False, orderby=None, limit=None, custom={})¶ Filter
Finds records based on the specific fields and values passed
- Parameters
fields (dict) – A dictionary of field names to the values they should match
raw (bool|list) – Return raw data (dict) for all or a set list of fields
distinct (bool) – Only return distinct data
orderby (str|str[]) – A field or fields to order the results by
limit (int|tuple) – The limit and possible starting point
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
Record[]|dict[]
-
classmethod
generateConfig
(tree, special='rethinkdb', db=None)¶ Generate Config
Generates record specific config based on the Format-OC tree passed
- Parameters
tree (FormatOC.Tree) – the tree associated with the record type
special (str) – The special section used to identify the child info
- Returns
dict
-
classmethod
get
(_id=None, index=None, filter=None, match=None, raw=None, distinct=False, orderby=None, limit=None, custom={})¶ Get
Returns records by primary key or index, can also be given an extra filter
- Parameters
_id (str|str[]) – The primary key(s) to fetch from the table
index (str) – Index to use instead of primary key
filter (dict) – Additional filter
match (tuple) – Name/Match filter
raw (bool|list) – Return raw data (dict) for all or a set list of fields
distinct (bool) – Only return distinct data
orderby (str|str[]) – A field or fields to order the results by
limit (int|tuple) – The limit and possible starting point
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
Record|Record[]|dict|dict[]
-
classmethod
getChanges
(_id, orderby=None, custom={})¶ Get Changes
Returns the changes record associated with the primary record and table. Used by Record types that have the ‘changes’ flag set
- Parameters
_id (mixed) – The of the primary record to fetch changes for
orderby (str|str[]) – A field or fields to order the results by
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
dict
-
classmethod
remove
(_id, array, index, custom={})¶ Remove
Removes an item from a given array/list for a specific record
- Parameters
_id (mixed) – The ID of the record to remove from
array (str) – The name of the field with the array
index (uint) – The index of the array to remove
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
save
(replace=False, changes=None)¶ Save
Updates the record in the DB and returns true if anything has changed, or a new revision number of the record is revisionable
- Parameters
replace (bool) – If true, replace all fields instead of updating
changes (dict) – Data needed to store a change record, is dependant on the ‘changes’ config value
- Returns
bool
-
classmethod
tableCreate
(custom={})¶ Table Create
Creates the record’s table/collection/etc in the DB
- Parameters
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
tableDrop
(custom={})¶ Table Drop
Deletes the record’s table/collection/etc in the DB
- Parameters
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
bool
-
classmethod
updateField
(field, value, _id=None, index=None, filter=None, custom={})¶ Updated Field
Updates a specific field to the value for an ID, many IDs, or the entire table
- Parameters
field (str) – The name of the field to update
value (mixed) – The value to set the field to
_id (mixed) – Optional ID(s) to filter by
index (str) – Optional name of the index to use instead of primary
filter (dict) – Optional filter list to decide what records get updated
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
uint – Number of records altered
-
classmethod
uuid
(custom={})¶ UUID
Returns a universal unique ID
- Parameters
custom (dict) – Custom Host and DB info ‘host’ the name of the host to get/set data on ‘append’ optional postfix for dynamic DBs
- Returns
str
-
classmethod
-
RestOC.Record_ReDB.
addHost
(name, info, update=False)¶ Add Host
Add a host that can be used by Records
- Parameters
name (str) – The name that will be used to fetch the host credentials
info (dict) – The necessary credentials to connect to the host
- Returns
bool
-
RestOC.Record_ReDB.
dbCreate
(name, host='primary')¶ DB Create
Creates a DB on the given host
- Parameters
name (str) – The name of the DB to create
host (str) – The name of the host the DB will be on
- Returns
bool
-
RestOC.Record_ReDB.
dbDrop
(name, host='primary')¶ DB Drop
Drops a DB on the given host
- Parameters
name (str) – The name of the DB to delete
host (str) – The name of the host the DB is on
- Returns
bool