Simpycity Modules¶
-
simpycity.config.port= None¶ libpq connection parameter
-
simpycity.config.database= None¶ libpq connection parameter
-
simpycity.config.debug= False¶ print debug output
-
simpycity.config.dsn()¶ Return a libpq connection string using the variables defined in this file.
-
simpycity.config.handle_factory(*args, **kwargs)¶ Simpycity calls this to get a handle when it needs one. It may be useful to redefine this function with one that returns an existing instance of Handle, so that your application only opens one – or a controlled number of – database connections.
Returns: instance of simpycity.handle.Handle
-
simpycity.config.host= None¶ libpq connection parameter
-
simpycity.config.password= None¶ libpq connection parameter
-
simpycity.config.port= None libpq connection parameter
-
simpycity.config.user= None¶ libpq connection parameter
-
class
simpycity.handle.Cursor(*args, **kwargs)¶ Bases:
psycopg2.extras.DictCursorAdd per-row callback option to standard cursor.
-
class
simpycity.handle.Handle(dsn=None, config=None, isolation_level=None)¶ Bases:
objectA base Simpycity handle. a Handle is the wrapper object around a psycopg connection.
-
cursor(*args, **kwargs)¶ Parameters: cursor_factory – Override default Cursor Returns: psycopg2 cursor
-
open¶ Open the connection if not already open.
Returns: True
-
transaction()¶ A generator function
-
-
class
simpycity.handle.TypedCursor(*args, **kwargs)¶ Bases:
simpycity.handle.CursorA cursor for result sets having only a single (typically composite) column. Rather than a row being a tuple, it is simply the value of the one column.
-
class
simpycity.core.Function(*args, **kwargs)¶ Bases:
simpycity.core.meta_queryAbstract a Postgresql function.
-
form_query(columns, options={})¶ Parameters: - columns (str) – literal sql string for list of columns
- options (dict) – dict supporting a single key “direct” as in the constructor
Returns: sql string
-
-
exception
simpycity.core.FunctionError¶ Bases:
BaseExceptionBare exception, used for naming purposes only.
-
class
simpycity.core.FunctionSingle(*args, **kwargs)¶ Bases:
simpycity.core.FunctionA Postgresql function that returns a single value.
-
class
simpycity.core.FunctionTyped(*args, **kwargs)¶ Bases:
simpycity.core.FunctionA Postgresql function that returns row(s) having only a single (typically composite) column
-
class
simpycity.core.FunctionTypedSingle(*args, **kwargs)¶ Bases:
simpycity.core.FunctionSingle,simpycity.core.FunctionTypedA Postgresql function that returns a single row having a single (typically composite) column
-
class
simpycity.core.Property(*args, **kwargs)¶ Bases:
simpycity.core.FunctionTypedSingleEnjoys special handling in SimpleModel.__getattribute__ When a SimpleModel attribute references an instance of this class, its __call__ attribute is executed immediately and the result returned. That means in __init__, args must be empty, or the args must be mappable by name to the model’s table attribute.
-
class
simpycity.core.Query(name, args=[], handle=None, callback=None)¶ Bases:
simpycity.core.meta_queryselect query access to a Postgresql table or view.
-
class
simpycity.core.QuerySingle(name, args=[], handle=None, callback=None)¶ Bases:
simpycity.core.QueryA select query on a table or view that returns a single row
-
class
simpycity.core.QueryTyped(*args, **kwargs)¶ Bases:
simpycity.core.QueryA select query on a table or view that returns composite row values
-
class
simpycity.core.QueryTypedSingle(*args, **kwargs)¶ Bases:
simpycity.core.QuerySingle,simpycity.core.QueryTypedA select query on a table or view that returns a single composite row value
-
class
simpycity.core.Raw(name, args=[], handle=None, callback=None)¶ Bases:
simpycity.core.meta_queryExecute arbitrary sql.
-
class
simpycity.core.meta_query(name, args=[], handle=None, callback=None)¶ Bases:
objectBase object for sql query-like objects For internal use only.
-
commit()¶ Commits the query, using the internal self.handle.
-
form_query(columns, options={})¶ Subclass function to create the query based on the columns provided at instance time. :param list columns: List of columns to return :param dict options: A dict, which responds to the following keys:
- columns: Alters what columns are selected by the query.
- handle: Overrides the instance handle with a customized version.
- callback: Override the instance callback with a customized version.
Returns: sql string
-
handle(handle)¶ Permanently resets the handle.
-
is_property¶ Override this for special handling in simpycity.model.SimpleModel.__getattribute__ If
True, __call__ will be executed if a reference is made to a SimpleModel attribute that is this instance.
-
rollback()¶ Rolls back the query, using the internal self.handle.
-
-
class
simpycity.model.SimpleModel(*args, **kwargs)¶ Bases:
simpycity.model.ConstructThe basic simple model class. Implements the barest minimum of Model functionality to operate. SimpleModel expects one of:
- __load__ to be a FunctionSingle or QuerySingle that loads an instance, based on primary key, from the database.
- __lazyload__ to be a FunctionSingle that loads an instance from the database, depending on the existance of a value for loaded_indicator, which should be a member of table that will only be populated after the instance is fully loaded.
-
static
merge_base_attrs(attrs)¶ Parameters: attrs (dict) – If one of the attrs is named “base_”, assume that attribute is an instance of SimpleModel mapped on a Postgresql composite type, and that the base_ instance is of a superclass of this class. Expand the attributes of the base_ type and assign to class attributes. psycopg2’s type casting uses namedtuple() and that forbids a name to start with underscore, so we end it with _ instead
-
pg_type= None¶ If table is empty and this is a tuple of two members (schema, type) then register_composite() will calculate table by executing a query to Postgres at runtime.
-
classmethod
register_composite(name, handle=None, factory=None)¶ Maps a Postgresql type to this class. If the class’s table attribute is empty, and the class has an attribute pg_type of tuple (schema, type), it is calculated and set by querying Postgres. Register inherited/inheriting classes in heirarchical order. Every time a SQL function returns a registered type (including array elements and individual columns, recursively), this class will be instantiated automatically.
The object attributes will be passed to the provided callable in a form of keyword arguments.
Parameters: - name (str) – the name of a PostgreSQL composite type, e.g. created using the CREATE TYPE command
- handle (simpycity.handle.Handle) –
- factory (psycopg2.extras.CompositeCaster) – use it to customize how to cast composite types
Returns: the registered CompositeCaster instance responsible for the conversion
-
save()¶ DEPRECATED
Performs the __save__ method, if it has been declared. If not, this function raises a CannotSave exception. .save() does not implicitly commit the model. To commit, it must be done manually.
-
table= []¶ Declare a list of columns to become class attributes. Or leave empty, and define pg_type.