pypicloud.cache.sql module¶
Store package data in a SQL database
-
class
pypicloud.cache.sql.
JSONEncodedDict
(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecorator
Represents an immutable structure as a json-encoded string.
-
process_bind_param
(value, dialect)[source]¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngine
object, and from there to the DBAPIexecute()
method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
Parameters: - value – Data to operate upon, of any type expected by
this method in the subclass. Can be
None
. - dialect – the
Dialect
in use.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
process_result_value
(value, dialect)[source]¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngine
object, originally from the DBAPI cursor methodfetchone()
or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
Parameters: - value – Data to operate upon, of any type expected by
this method in the subclass. Can be
None
. - dialect – the
Dialect
in use.
This operation should be designed to be reversible by the “process_bind_param” method of this class.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
-
class
pypicloud.cache.sql.
MutableDict
[source]¶ Bases:
sqlalchemy.ext.mutable.Mutable
,dict
SQLAlchemy dict field that tracks changes
-
class
pypicloud.cache.sql.
SQLCache
(request=None, dbmaker=None, graceful_reload=False, **kwargs)[source]¶ Bases:
pypicloud.cache.base.ICache
Caching database that uses SQLAlchemy
-
all
(name)[source]¶ Search for all versions of a package
Parameters: - name : str
The name of the package
Returns: - packages : list
List of all
Package
s with the given name
-
check_health
()[source]¶ Check the health of the cache backend
Returns: - (healthy, status) : (bool, str)
Tuple that describes the health status and provides an optional status message
-
fetch
(filename)[source]¶ Get matching package if it exists
Parameters: - filename : str
Name of the package file
Returns: - package :
Package
-
reload_if_needed
()[source]¶ Reload packages from storage backend if cache is empty
This will be called when the server first starts
-
search
(criteria, query_type)[source]¶ Perform a search.
Queries are performed as follows:
For the AND query_type, queries within a column will utilize the AND operator, but will not conflict with queries in another column.
(column1 LIKE ‘%a%’ AND column1 LIKE ‘%b%’) OR (column2 LIKE ‘%c%’ AND column2 LIKE ‘%d%’)For the OR query_type, all queries will utilize the OR operator:
(column1 LIKE ‘%a%’ OR column1 LIKE ‘%b%’) OR (column2 LIKE ‘%c%’ OR column2 LIKE ‘%d%’)
-
-
class
pypicloud.cache.sql.
SQLPackage
(name, version, filename, last_modified=None, summary=None, **kwargs)[source]¶ Bases:
pypicloud.models.Package
,sqlalchemy.orm.decl_api.Base
Python package stored in SQLAlchemy
-
class
pypicloud.cache.sql.
TZAwareDateTime
(*args, **kwargs)[source]¶ Bases:
sqlalchemy.sql.type_api.TypeDecorator
-
process_bind_param
(value, dialect)[source]¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngine
object, and from there to the DBAPIexecute()
method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
Parameters: - value – Data to operate upon, of any type expected by
this method in the subclass. Can be
None
. - dialect – the
Dialect
in use.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-
process_result_value
(value, dialect)[source]¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngine
object, originally from the DBAPI cursor methodfetchone()
or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
Parameters: - value – Data to operate upon, of any type expected by
this method in the subclass. Can be
None
. - dialect – the
Dialect
in use.
This operation should be designed to be reversible by the “process_bind_param” method of this class.
- value – Data to operate upon, of any type expected by
this method in the subclass. Can be
-