X-Git-Url: https://git.jsancho.org/?p=mojodb.git;a=blobdiff_plain;f=connection.py;fp=connection.py;h=ca67b9e297cf4e1422bee2a8885a05a04d64379e;hp=0000000000000000000000000000000000000000;hb=792f961fb96bb8533e540970c54f43b958d77296;hpb=f63673b9ed08886c9ac1582f94f0e63103985497 diff --git a/connection.py b/connection.py new file mode 100644 index 0000000..ca67b9e --- /dev/null +++ b/connection.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# mojo, a Python library for implementing document based databases +# Copyright (C) 2013-2014 by Javier Sancho Fernandez +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +from database import Database + +class Connection(object): + def __init__(self, *args, **kwargs): + self._db_con = None + + def __getattr__(self, db_name): + return Database(self, db_name) + + def __getitem__(self, *args, **kwargs): + return self.__getattr__(*args, **kwargs) + + def __repr__(self): + return "Connection(%s)" % self._db_con + + def _get_databases(self): + return [] + + def database_names(self): + try: + return [unicode(x) for x in self._get_databases()] + except: + return [] + + def _get_tables(self, db_name): + return [] + + def collection_names(self, db_name): + try: + return list(set([unicode(x.split('$')[0]) for x in filter(lambda x: '$' in x, self._get_tables(db_name))])) + except: + return [] + + def _count_rows(self, db_name, table_name): + return 0 + + def _count(self, db_name, table_name): + try: + return self._count_rows(db_name, table_name + '$_id') + except: + return 0 + + def _create_database(self, db_name): + return None + + def _create_table(self, db_name, table_name, fields): + # [{'name': 'id', 'type': 'char', 'size': 20, 'primary': True}] + return None + + def _get_cursor(self, db_name, query): + # {'select': [('t1$_id', 'id'), {'select': [('t1$c1', 'value')], 'from': ['t1$c1'], 'where': [(('t1$c1', 'id'), '=', ('t1$_id', 'id'))]}], 'from': ['t1$_id']} + return None + + def _next(self, cursor): + return None + + def _insert(self, db_name, table_name, values): + return None + + def commit(self): + pass + + def rollback(self): + pass