Package advene :: Package model :: Package backends :: Module sqlite
[hide private]
[frames] | no frames]

Module sqlite

source code

I am the reference implementation for advene backends modules.

A backend module can be registered by invoking `advene.model.backends.register` with the module as its sole argument. It must implement 4 functions: `claims_for_create` , `claims_for_bind` , create_ and bind_ . The two latters return a *backend instance* with a standard API, for which `_SqliteBackend` provides a reference implementation.

Classes [hide private]
  _SqliteBackend
I am the reference implementation of advene backend instances.
  _FlushableIterator
Cursor based iterator that may flush the cursor whenever needed.
  _Query
I provide useful functionalities for building SQL queries to the backend schema.
Functions [hide private]
 
_get_module_debug()
Return the state of the module's debug flag.
source code
 
_set_module_debug(b)
Set the module's debug flaf.
source code
 
claims_for_create(url)
Is this backend able to create a package to the given URL ?
source code
 
create(package, force=False, url=None)
Creates a new package and return backend instance and package id.
source code
 
claims_for_bind(url)
Is this backend able to bind to the given URL ?
source code
 
bind(package, force=False, url=None)
Bind to an existing package at the given URL.
source code
 
_strip_url(url)
Strip URL from its scheme ("sqlite:") and separate path and fragment.
source code
 
_get_connection(path) source code
 
_contains_package(cx, pkgid) source code
 
_split_id_ref(id_ref)
Split an id_ref into a prefix and a suffix.
source code
 
_split_uri_ref(uri_ref)
Split a uri_ref into a URI and a fragment.
source code
Variables [hide private]
  BACKEND_VERSION = '1.2'
  IN_MEMORY_URL = 'sqlite:%3Amemory%3A'
  _DF = False
  _cache = <WeakValueDictionary at 148727692>
  _DEFAULT_PKGID = ''
Function Details [hide private]

_get_module_debug()

source code 

Return the state of the module's debug flag.

The debug flag enables a bunch of ``assert`` statements. See also `_set_module_debug`.

NB: The benefit of disabling debug is not highly significant with sqlite, but this would be different with a distant DBMS (because asserts often invoke backend methods, resulting on extra queries to the database). Since it is expected that a backend implementation over such a DBMS will be done by copying and adapting this module, it seems like a good idea to have it.

_set_module_debug(b)

source code 

Set the module's debug flaf. See _get_module_debug`.

claims_for_create(url)

source code 

Is this backend able to create a package to the given URL ?

Checks whether the URL is recognized, and whether the requested package does not already exist at that URL.

When the result of that method is False, it must be a `ClaimFailure` rather than a `bool`. If it has no exception, then the URL is not recognized at all. If it has an exception, then the URL is recognized, but attempting to create the package will raise that exception.

create(package, force=False, url=None)

source code 
Creates a new package and return backend instance and package id.

Parameters
----------
package
  an object with attribute ``url``, which will be used as the backend URL
  unless parameter `url` is also provided.
force
  should the package be created (i.e. re-initialized) even if it exists?
url
  URL to be used if ``package.url`` is not adapted to this backend (useful
  for parsed-into-backend packages)

claims_for_bind(url)

source code 

Is this backend able to bind to the given URL ?

Checks whether the URL is recognized, and whether the requested package does already exist in the database.

When the result of that method is False, it must be a `ClaimFailure` rather than a `bool`. If it has no exception, then the URL is not recognized at all. If it has an exception, then the URL is recognized, but attempting to create the package will raise that exception.

bind(package, force=False, url=None)

source code 
Bind to an existing package at the given URL.

Return the backend an the package id.

Parameters
----------
package
  an object with attributes ``readonly`` and ``url``, which will be used as
  the backend URL unless parameter `url` is also provided.
force
  should the package be opened even if it is being used?
url
  URL to be used if ``package.url`` is not adapted to this backend (useful
  for parsed-into-backend packages)

_strip_url(url)

source code 

Strip URL from its scheme ("sqlite:") and separate path and fragment. Also convert path from url to OS-specific pathname expression.

_split_id_ref(id_ref)

source code 

Split an id_ref into a prefix and a suffix. Return None prefix if id_ref is a plain id. Raise an AssertionError if id_ref has length > 2.