commit/galaxy-central: dannon: Merged in jjohnson/galaxy-central-7 (pull request #609)
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/ad28e42a8af3/ Changeset: ad28e42a8af3 User: dannon Date: 2014-12-15 12:43:42+00:00 Summary: Merged in jjohnson/galaxy-central-7 (pull request #609) Add dataproviders for SQlite datatype Affected #: 2 files diff -r ecac8a8679612d419347dcbedc398319418b077e -r ad28e42a8af34c81f0ebcbe6f3baef9bdcf80ae8 lib/galaxy/datatypes/binary.py --- a/lib/galaxy/datatypes/binary.py +++ b/lib/galaxy/datatypes/binary.py @@ -620,6 +620,16 @@ dataset_source = dataproviders.dataset.DatasetDataProvider( dataset ) return dataproviders.dataset.SQliteDataProvider( dataset_source, **settings ) + @dataproviders.decorators.dataprovider_factory( 'sqlite-table', dataproviders.dataset.SQliteDataTableProvider.settings ) + def sqlite_datatableprovider( self, dataset, **settings ): + dataset_source = dataproviders.dataset.DatasetDataProvider( dataset ) + return dataproviders.dataset.SQliteDataTableProvider( dataset_source, **settings ) + + @dataproviders.decorators.dataprovider_factory( 'sqlite-dict', dataproviders.dataset.SQliteDataDictProvider.settings ) + def sqlite_datadictprovider( self, dataset, **settings ): + dataset_source = dataproviders.dataset.DatasetDataProvider( dataset ) + return dataproviders.dataset.SQliteDataDictProvider( dataset_source, **settings ) + Binary.register_sniffable_binary_format("sqlite", "sqlite", SQlite) diff -r ecac8a8679612d419347dcbedc398319418b077e -r ad28e42a8af34c81f0ebcbe6f3baef9bdcf80ae8 lib/galaxy/datatypes/dataproviders/dataset.py --- a/lib/galaxy/datatypes/dataproviders/dataset.py +++ b/lib/galaxy/datatypes/dataproviders/dataset.py @@ -13,6 +13,7 @@ import external from galaxy.util import sqlite import re +import sys from galaxy import eggs eggs.require( 'bx-python' ) @@ -726,3 +727,55 @@ else: yield +class SQliteDataTableProvider( base.DataProvider ): + """ + Data provider that uses a sqlite database file as its source. + Allows any query to be run and returns the resulting rows as arrays of arrays + """ + settings = { + 'query': 'str', + 'headers': 'bool', + 'limit': 'int' + } + + def __init__( self, source, query=None, headers=False, limit=sys.maxint, **kwargs ): + self.query = query + self.headers = headers + self.limit = limit + self.connection = sqlite.connect(source.dataset.file_name) + super( SQliteDataTableProvider, self ).__init__( source, **kwargs ) + + def __iter__( self ): + if (self.query is not None) and sqlite.is_read_only_query(self.query): + cur = self.connection.cursor() + results = cur.execute(self.query) + if self.headers: + yield [col[0] for col in cur.description] + for i,row in enumerate(results): + if i >= self.limit: + break + yield [val for val in row] + else: + yield + +class SQliteDataDictProvider( base.DataProvider ): + """ + Data provider that uses a sqlite database file as its source. + Allows any query to be run and returns the resulting rows as arrays of dicts + """ + settings = { + 'query': 'str' + } + + def __init__( self, source, query=None, **kwargs ): + self.query = query + self.connection = sqlite.connect(source.dataset.file_name) + super( SQliteDataDictProvider, self ).__init__( source, **kwargs ) + + def __iter__( self ): + if (self.query is not None) and sqlite.is_read_only_query(self.query): + cur = self.connection.cursor() + for row in cur.execute(self.query): + yield [dict((cur.description[i][0], value) for i, value in enumerate(row))] + else: + yield Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org