logilab.database package¶
Submodules¶
logilab.database.fti module¶
- class logilab.database.fti.FTIndexerMixIn[source]¶
Bases:
object
The base full-text indexer mixin. To be mixed with advanced functionnality helper.
Provide an inefficient but generic indexing method which can be overridden.
- fti_need_distinct = True¶
- fti_sql_schema = '\n%s\n\nCREATE TABLE word (\n word_id INTEGER PRIMARY KEY NOT NULL,\n word VARCHAR(100) NOT NULL UNIQUE\n);\n\nCREATE TABLE appears(\n uid INTEGER,\n word_id INTEGER REFERENCES word ON DELETE CASCADE,\n pos INTEGER NOT NULL\n);\n\nCREATE INDEX appears_uid ON appears (uid);\nCREATE INDEX appears_word_id ON appears (word_id);\n'¶
- fti_table = 'appears'¶
- fti_uid_attr = 'uid'¶
- fulltext_search(query_string, cursor=None)[source]¶
execute a full text query and return a list of 2-uple (rating, uid)
- index_object(uid, obj, cnx=None)[source]¶
index an object with the given uid the object should inherit from or be compatible with Indexable object
- init_fti_extensions(cursor, owner=None)[source]¶
if necessary, install extensions at database creation time
- exception logilab.database.fti.StopWord[source]¶
Bases:
Exception
Raised to indicate that a stop word has been encountered.
- logilab.database.fti.normalize(word)[source]¶
Return the normalized form for a word.
The word given in argument should be unicode !
- currently normalized word are :
_ in lower case _ without any accent
This function may raise StopWord if the word shouldn’t be indexed
- stop words are :
_ single letter
- logilab.database.fti.tokenize(string, pos=0, endpos=9223372036854775807)¶
Return a list of all non-overlapping matches of pattern in string.
- logilab.database.fti.tokenize_query(string, pos=0, endpos=9223372036854775807)¶
Return a list of all non-overlapping matches of pattern in string.
logilab.database.ftiparser module¶
Yapps input grammar for indexer queries.
- class logilab.database.ftiparser.IndexerQuery(scanner)[source]¶
Bases:
Parser
logilab.database.ftiquery module¶
Query objects for Generic Indexer.
- class logilab.database.ftiquery.KeywordsQuery(words)[source]¶
Bases:
object
a keywords query’ll look for uid matching all those words in any order
- class logilab.database.ftiquery.PhraseQuery(tokens)[source]¶
Bases:
object
a phrase query’ll look for uid matching all phrase’s tokens in the same order
- class logilab.database.ftiquery.Query(normalize)[source]¶
Bases:
object
a query is the object manipulated by the indexer the query parser’ll call add_word and add_phrase on this object accoring to the query string (see query.g for the query string’s grammar)
- logilab.database.ftiquery.tokenize(string, pos=0, endpos=9223372036854775807)¶
Return a list of all non-overlapping matches of pattern in string.
logilab.database.postgres module¶
Postgres RDBMS support
Supported drivers, in order of preference: - psycopg2 - psycopg2ct
Full-text search based on the tsearch2 extension from the openfts project (see http://openfts.sourceforge.net/)
Warning: you will need to run the tsearch2.sql script with super user privileges on the database.
- logilab.database.postgres.tokenize_query(string, pos=0, endpos=9223372036854775807)¶
Return a list of all non-overlapping matches of pattern in string.
logilab.database.sqlite module¶
Sqlite RDBMS support
Supported driver: sqlite3
Module contents¶
Wrappers to get actually replaceable DBAPI2 compliant modules and database connection whatever the database and client lib used.
Currently support:
postgresql (pgdb, psycopg, psycopg2, pyPgSQL)
sqlite (pysqlite2, sqlite, sqlite3)
just use the get_connection function from this module to get a wrapped connection. If multiple drivers for a database are available, you can control which one you want to use using the set_prefered_driver function.
Additional helpers are also provided for advanced functionalities such as listing existing users or databases, creating database… Get the helper for your database using the get_db_helper function.
- class logilab.database.ABS(name=None)[source]¶
Bases:
FunctionDescr
- rtype = 'Float'¶
- class logilab.database.AT_TZ(TZDatetime, timezone)[source]¶
Bases:
FunctionDescr
- maxargs = 2¶
- minargs = 2¶
- supported_backends = ('postgres',)¶
- class logilab.database.AVG(name=None)[source]¶
Bases:
AggrFunctionDescr
- rtype = 'Float'¶
- class logilab.database.AggrFunctionDescr(name=None)[source]¶
Bases:
FunctionDescr
- aggregat = True¶
- rtype = None¶
- class logilab.database.CAST(name=None)[source]¶
Bases:
FunctionDescr
usage is CAST(datatype, expression)
sql-92 standard says (CAST <expr> as <type>)
- maxargs = 2¶
- minargs = 2¶
- rtype = <object object>¶
- supported_backends = ('postgres', 'sqlite')¶
- class logilab.database.COUNT(name=None)[source]¶
Bases:
AggrFunctionDescr
- maxargs = 2¶
- rtype = 'Int'¶
- class logilab.database.COUNTDISTINCT(name=None)[source]¶
Bases:
AggrFunctionDescr
- rtype = 'Int'¶
- class logilab.database.DATE(name=None)[source]¶
Bases:
FunctionDescr
- rtype = 'Date'¶
- class logilab.database.DAY(name=None)[source]¶
Bases:
ExtractDateField
- field = 'DAY'¶
- class logilab.database.DBAPIAdapter(native_module, pywrap=False)[source]¶
Bases:
object
Base class for all DBAPI adapters
- UNKNOWN = None¶
- connect(host='', database='', user='', password='', port='', schema=None, extra_args=None)[source]¶
Wraps the native module connect method
- process_cursor(cursor, encoding, binarywrap=None)[source]¶
return an iterator on results.
Each record is returned a list (not a tuple) and each element of the record is processed : - database strings are all unicode - database booleans are python boolean objects - if binarywrap is provided, it is used to wrap binary data
- returns_unicode = False¶
- row_is_mutable = False¶
- support_copy_from = False¶
- class logilab.database.EPOCH(name=None)[source]¶
Bases:
ExtractDateField
Return EPOCH timestamp from a datetime/date ; return number of seconds for an interval.
- field = 'EPOCH'¶
- class logilab.database.ExtractDateField(name=None)[source]¶
Bases:
FunctionDescr
- field = None¶
- maxargs = 1¶
- minargs = 1¶
- rtype = 'Int'¶
- class logilab.database.FunctionDescr(name=None)[source]¶
Bases:
object
- aggregat = False¶
- maxargs = 1¶
- minargs = 1¶
- name_mapping = {}¶
- rtype = None¶
- supported_backends = <object object>¶
- class logilab.database.HOUR(name=None)[source]¶
Bases:
ExtractDateField
- field = 'HOUR'¶
- class logilab.database.IN(name=None)[source]¶
Bases:
FunctionDescr
this is actually a ‘keyword’ function…
- maxargs = None¶
- class logilab.database.LENGTH(name=None)[source]¶
Bases:
FunctionDescr
- rtype = 'Int'¶
- class logilab.database.LOWER(name=None)[source]¶
Bases:
FunctionDescr
- rtype = 'String'¶
- class logilab.database.MAX(name=None)[source]¶
Bases:
AggrFunctionDescr
- class logilab.database.MIN(name=None)[source]¶
Bases:
AggrFunctionDescr
- class logilab.database.MINUTE(name=None)[source]¶
Bases:
ExtractDateField
- field = 'MINUTE'¶
- class logilab.database.MONTH(name=None)[source]¶
Bases:
ExtractDateField
- field = 'MONTH'¶
- exception logilab.database.NoAdapterFound(obj, objname=None, protocol='DBAPI')[source]¶
Bases:
Exception
Raised when no Adapter to DBAPI was found
- class logilab.database.PyConnection(cnx)[source]¶
Bases:
_SimpleConnectionWrapper
A simple connection wrapper in python, generating wrapper for cursors as well (useful for profiling)
- class logilab.database.PyCursor(cursor)[source]¶
Bases:
object
A simple cursor wrapper in python (useful for profiling)
- class logilab.database.RANDOM(name=None)[source]¶
Bases:
FunctionDescr
- maxargs = 0¶
- minargs = 0¶
- name_mapping = {'postgres': 'RANDOM'}¶
- rtype = 'Float'¶
- class logilab.database.SECOND(name=None)[source]¶
Bases:
ExtractDateField
- field = 'SECOND'¶
- class logilab.database.SUBSTRING(name=None)[source]¶
Bases:
FunctionDescr
- maxargs = 3¶
- minargs = 3¶
- name_mapping = {'postgres': 'SUBSTR', 'sqlite': 'SUBSTR'}¶
- rtype = 'String'¶
- class logilab.database.SUM(name=None)[source]¶
Bases:
AggrFunctionDescr
- class logilab.database.UPPER(name=None)[source]¶
Bases:
FunctionDescr
- rtype = 'String'¶
- exception logilab.database.UnknownDriver[source]¶
Bases:
Exception
raised when a unknown driver is given to get connection
- class logilab.database.WEEKDAY(name=None)[source]¶
Bases:
FunctionDescr
Return the day of the week represented by the date.
Sunday == 1, Saturday = 7
(pick those values since it’s recommended by in the ODBC standard)
- maxargs = 1¶
- minargs = 1¶
- rtype = 'Int'¶
- class logilab.database.YEAR(name=None)[source]¶
Bases:
ExtractDateField
- field = 'YEAR'¶
- logilab.database.get_connection(driver='postgres', host='', database='', user='', password='', port='', quiet=False, drivers={'postgres': ['psycopg2', 'psycopg2ct', 'psycopg2cffi'], 'sqlite': ['sqlite3']}, pywrap=False, schema=None, extra_args=None)[source]¶
return a db connection according to given arguments
extra_args is an optional string that is appended to the DSN
- logilab.database.get_db_helper(driver)[source]¶
returns an advanced function helper for the given driver
- logilab.database.get_dbapi_compliant_module(driver, prefered_drivers=None, quiet=False, pywrap=False)[source]¶
returns a fully dbapi compliant module
- logilab.database.register_function(funcdef)[source]¶
register the function funcdef on supported backends
- logilab.database.set_prefered_driver(driver, module, _drivers={'postgres': ['psycopg2', 'psycopg2ct', 'psycopg2cffi'], 'sqlite': ['sqlite3']})[source]¶
sets the preferred driver module for driver driver is the name of the db engine (postgresql,…) module is the name of the module providing the connect function syntax is (params_func, post_process_func_or_None) _drivers is a optional dictionary of drivers