ws.db.database module

Prerequisites:

  1. A pre-configured PostgreSQL database backend with separate database and user account. The database should be created with the “C” collation, e.g. create the database with createdb -E UNICODE -l C -T template0 -O username dbname

  2. One of the many drivers supported by sqlalchemy, e.g. psycopg2.

class ws.db.database.Database(engine_or_url)

Bases: object

Parameters

engine_or_url – either an existing sqlalchemy.engine.Engine instance or a str representing the URL created by make_url()

charset = 'utf8'
static set_argparser(argparser)

Add arguments for constructing a Database object to an instance of argparse.ArgumentParser.

See also the ws.config module.

Parameters

argparser – an instance of argparse.ArgumentParser

classmethod from_argparser(args)

Construct a Database object from arguments parsed by argparse.ArgumentParser.

Parameters

args – an instance of argparse.Namespace. It is assumed that it contains the arguments set by Connection.set_argparser().

Returns

an instance of Connection

sync_with_api(api, *, with_content=False, check_needs_update=True)

Sync the local data with a remote MediaWiki instance.

Parameters
  • api (ws.client.api.API) – interface to the remote MediaWiki instance

  • with_content (bool) – whether to synchronize the content of all revisions

  • check_needs_update (bool) – whether to use the recentchanges table to check if the synchronization is needed and otherwise exit early

sync_revisions_content(api, *, mode='latest')

Sync the revisions content with a remote MediaWiki instance.

Note that the method sync_with_api() should be called prior to calling this method.

Parameters
  • api (ws.client.api.API) – interface to the remote MediaWiki instance

  • mode (str) –

    the mode of operation:

    • ”latest”: the content of the latest revisions of all pags on the wiki will be synchronized

    • ”all”: the content of all revisions will be synchronized

query(*args, **kwargs)

Main interface for the MediaWiki-like database queries.

TODO: documentation of the parameters (or at least the differences from MediaWiki)

Title(title)

Parse a MediaWiki title.

Parameters

title (str) – page title to be parsed

Returns

a ws.parser_helpers.title.Title object

update_parser_cache()

Update the parser cache tables.

Note that the methods sync_with_api() and sync_latest_revisions_content() should be called prior to calling this method.

class ws.db.database.explain(stmt, analyze=False)

Bases: sqlalchemy.sql.base.Executable, sqlalchemy.sql.elements.ClauseElement

ws.db.database.visit_explain(element, compiler, **kw)