pyre.db¶
Submodules¶
pyre.db.Backuppyre.db.Clientpyre.db.Collationpyre.db.DataStorepyre.db.FieldReferencepyre.db.FieldSelectorpyre.db.ForeignKeypyre.db.Measurepyre.db.Objectpyre.db.Persistentpyre.db.Postgrespyre.db.Querypyre.db.Referencepyre.db.SQLpyre.db.SQLitepyre.db.Schemerpyre.db.Selectorpyre.db.Serverpyre.db.Tablepyre.db.actionspyre.db.exceptionspyre.db.expressionspyre.db.literals
Package Contents¶
-
pyre.db.null¶
-
pyre.db.default¶
-
pyre.db.noAction= NO ACTION¶
-
pyre.db.restrict= RESTRICT¶
-
pyre.db.cascade= CASCADE¶
-
pyre.db.setNull= SET NULL¶
-
pyre.db.setDefault= SET DEFAULT¶
-
class
pyre.db.collation(fieldref, collation=collation, **kwds)¶ An encapsulation of the collation sequence
-
fieldref¶
-
collation= ASC¶
-
sql(self, context=None)¶ Render me as an SQL expression
-
-
pyre.db.ascending(fieldref)¶ Build a clause for the {ORDER} expression that marks {fieldref} as sorted in ascending order
-
pyre.db.descending(fieldref)¶ Build a clause for the {ORDER} expression that marks {fieldref} as sorted in descending order
-
class
pyre.db.isNull¶ Bases:
pyre.db.expressions.UnaryPostfixA node factory that takes a field reference {op} and builds the expression {op IS NULL}
-
operator= IS NULL¶
-
-
class
pyre.db.isNotNull¶ Bases:
pyre.db.expressions.UnaryPostfixA node factory that takes a field reference {op} and builds the expression {op IS NOT NULL}
-
operator= IS NOT NULL¶
-
-
class
pyre.db.cast(field, targetType, **kwds)¶ Implementation of the {CAST} expression
-
sql(self, **kwds)¶ SQL rendering of the expression I represent
-
-
class
pyre.db.like(field, regex, **kwds)¶ Implementation of the LIKE operator
-
sql(self, **kwds)¶ SQL rendering of the expression I represent
-
-
pyre.db.field¶
-
class
pyre.db.measure¶ Bases:
pyre.records.measureThe base class for table field descriptors
-
class
measure¶ The base class of the local mixins.
Its purpose is to trap value coercion and skip it for the special values {NULL} and {DEFAULT} that show up as {literals} instances
-
coerce(self, value, **kwds)¶
-
-
class
bool¶ Bases:
pyre.db.Measure.measureMixin for booleans
-
decl= BOOLEAN¶
-
sql(self, value)¶ SQL rendering of {value}
-
-
class
date(default=None, **kwds)¶ Bases:
pyre.db.Measure.measureMixin for dates
-
decl= DATE¶
-
sql(self, value)¶ SQL rendering of {value}
-
-
class
decimal(precision, scale, **kwds)¶ Bases:
pyre.db.Measure.measureMixin for fixed point numbers
-
sql(self, value)¶ SQL rendering of {value}
-
-
class
float¶ Bases:
pyre.db.Measure.measureMixin for floating point numbers
-
decl= DOUBLE PRECISION¶
-
sql(self, value)¶ SQL rendering of my value
-
-
class
int¶ Bases:
pyre.db.Measure.measureMixin for integers
-
decl= INTEGER¶
-
sql(self, value)¶ SQL rendering of my value
-
-
class
str(maxlen=None, **kwds)¶ Bases:
pyre.db.Measure.measureMixin for strings
-
sql(self, value)¶ SQL rendering of my value
-
-
class
time(default=None, timezone=False, **kwds)¶ Bases:
pyre.db.Measure.measureMixin for timestamps
-
sql(self, value)¶ SQL rendering of {value}
-
-
_primary¶
-
_unique¶
-
_notNull¶
-
_foreign¶
-
setDefault(self, value)¶ Set a new default value
-
primary(self)¶ Mark a field as a primary key
-
unique(self)¶ Mark a field as containing values that are unique across the table rows
-
notNull(self)¶ Mark a field as not accepting a NULL value
-
references(self, **kwds)¶ Mark a field as a foreign key
-
decldefault(self)¶ Invoked by the SQL mill to create the declaration of the default value
-
class
-
pyre.db.bool¶
-
pyre.db.date¶
-
pyre.db.decimal¶
-
pyre.db.float¶
-
pyre.db.int¶
-
pyre.db.str¶
-
pyre.db.time¶
-
class
pyre.db.reference(**kwds)¶ Bases:
pyre.db.Measure.MeasureRepresentation of foreign keys
-
sql(self, value)¶ SQL rendering of {value}
-
onDelete(self, action)¶ Set the action to perform when the target record is deleted. See {pyre.db.actions} for details
-
onUpdate(self, action)¶ Set the action to perform when the target record is updated. See {pyre.db.actions} for details
-
-
class
pyre.db.table¶ Bases:
pyre.records.recordBase class for database table declarations
-
_pyre_primaryKeys¶
-
_pyre_uniqueFields¶
-
_pyre_foreignKeys¶
-
_pyre_constraints¶
-
-
class
pyre.db.query¶ Bases:
pyre.records.recordBase class for describing database queries
-
where¶
-
order¶
-
group¶
-
pyre_tables¶
-
-
class
pyre.db.object¶ Bases:
pyre.framework.Dashboard.DashboardThe base class of classes whose instances store part of their attributes in relational database tables.
{Object} and its class {Persistent} provide the necessary layer to bridge object oriented semantics with the relational model. The goal is to make the existence of the relational tables more transparent to the developer of database applications by removing as much of the grunt work of storing and retrieving object state as possible.
-
pyre_extent¶
-
pyre_primaryTable¶
-
-
class
pyre.db.datastore¶ Bases:
pyre.protocolProtocol declaration for database managers
-
attach(self)¶ Establish a connection to the data store
-
detach(self)¶ Close a connection to the data store
-
execute(self, *sql)¶ Execute the sequence of SQL statements in {sql} as a single command
-
-
class
pyre.db.sql(**kwds)¶ Bases:
pyre.weaver.SQL.SQLGenerate SQL statements
-
INDENTER¶
-
select(self, query)¶ Generate the SELECT statement described by {query}
-
transaction(self)¶ Generate the SQL statement that initiates a transaction block
-
commit(self)¶ Generate the SQL statement that closes a transaction block
-
rollback(self)¶ Generate the SQL statement that rolls back a transaction
-
createDatabase(self, name)¶ Generate the SQL statement to create the database {name}
-
dropDatabase(self, name)¶ Generate the SQL statement to drop the database {name}
-
createTable(self, table)¶ Generate the SQL statement to create a database table given its description
The {table} specification is expected to be a {Table} subclass, with the necessary column information provided by the decorated field descriptors
-
dropTable(self, table)¶ Build the statement to drop the given {table}
-
insertRecords(self, *records)¶ Insert {records}, an iterable of table records, into their corresponding table
-
deleteRecords(self, table, condition)¶ Remove all {table} records that match {condition}
If condition is {None}, this routine will remove all records from the given {table}
-
updateRecords(self, template, condition)¶ Update all table rows that match {condition} using information from {template}, a prototype row of a table. The update operation sets the fields in these rows to their corresponding values in {template}; fields set to {None} in {template} are not affected.
-
_collationRenderer(self, order, context=None, **kwds)¶ Render the collation order specification
-
_fieldReferenceRenderer(self, node, context=None, **kwds)¶ Render {node} as reference to a field
-
_primitiveSQLExpressionRenderer(self, node, context=None, **kwds)¶ Render {node} as a unary postfix operator
-
_fieldDeclaration(self, field, comma)¶ Build the declaration lines for a given table field
-
_referenceDeclaration(self, foreign, comma)¶ Build a declaration for a foreign key
-
-
class
pyre.db.server¶ Bases:
pyre.componentAbstract component that encapsulates the connection to a database back end
This class is meant to be used as the base class for back end specific component implementations. It provides a complete but trivial implementation of the {DataStore} interface.
-
providesHeaders= True¶
-
sql¶
-
doc= the generator of the SQL statements¶
-
createDatabase(self, name)¶ Build and execute the SQL statement to create the database {name}
-
dropDatabase(self, name)¶ Build and execute the SQL statement to drop the database {name}
-
createTable(self, table)¶ Build and execute the SQL statement necessary to create {table}
-
dropTable(self, table)¶ Build and execute the SQL statement necessary to delete {table} from the datastore
-
insert(self, *records)¶ Insert {records} into the database
-
update(self, *specifications)¶ Use {specifications} to update the database
Each item in {specifications} is a pair of a {template} and a {condition}. The {template} is an instance of a table row with all fields that require update having values that are not {None}. The {condition} is an expression that identifies the portion of the table that will be affected
-
delete(self, table, condition)¶ Delete all {table} records that match {condition}
-
select(self, query)¶ Execute the given {query} and return the retrieved data
-
__enter__(self)¶ Hook invoked when the context manager is entered
-
__exit__(self, exc_type, exc_instance, exc_traceback)¶ Hook invoked when the context manager’s block exits
-
-
class
pyre.db.client¶ Bases:
pyre.componentThe base class for components that connect to data stores
-
server¶
-
-
class
pyre.db.backup¶ Bases:
pyre.db.Server.ServerComponent that saves SQL statement in a stream
-
database¶
-
doc= the name of the database to connect to¶
-
stream¶
-
doc= the stream in which to place SQL statements
-
attach(self)¶ Connect to the database
-
detach(self)¶ Close the connection to the database
-
execute(self, *sql)¶ Execute the sequence of SQL statements in {sql} as a single command
-
__enter__(self)¶ Hook invoked when the context manager is entered
-
__exit__(self, exc_type, exc_instance, exc_traceback)¶ Hook invoked when the context manager’s block exits
-
-
class
pyre.db.sqlite¶ Bases:
pyre.db.Server.ServerComponent that manages the connection to a sqlite database
-
providesHeaders= False¶
-
database¶
-
doc= the path to the sqlite database¶
-
cursor¶
-
connection¶
-
attach(self)¶ Connect to the database
-
detach(self)¶ Close the connection to the database
-
execute(self, *sql)¶ Execute the sequence of SQL statements in {sql} as a single command
-
-
class
pyre.db.postgres¶ Bases:
pyre.db.Server.ServerComponent that manages the connection to a Postgres database
-
database¶
-
doc= the name of the database to connect to¶
-
username¶
-
doc= the database user name to use during authentication
-
password¶
-
doc= the password of the database user
-
application¶
-
doc= the application name to use for the connection
-
quiet¶
-
doc= control whether certain postgres informationals are shown
-
postgres¶
-
connection¶
-
attach(self)¶ Connect to the database
-
detach(self)¶ Close the connection to the database
Closing a connection makes it unsuitable for any further database access. This applies to all objects that may retain a reference to the connection being closed. Any uncommitted changes will be lost
-
execute(self, *sql)¶ Execute the sequence of SQL statements in {sql} as a single command
-
__enter__(self)¶ Hook invoked when the context manager is entered
-
__exit__(self, exc_type, exc_instance, exc_traceback)¶ Hook invoked when the context manager’s block exits
-
-
pyre.db.template(table)¶ Build a row of {table} with all its fields set to {None}.