예제 #1
0
파일: client.py 프로젝트: iceseismic/pisces
    def load_tables(self, **tables):
        """
        Load core tables.

        Tables are given as key=value pairs as in:
        load_tables(wfdisc='global.wfdisc_raw', origin='location.origin')

        Raises
        ------
        sqlalchemy.exc.NoSuchTableError
            Table doesn't exist.

        """
        #XXX: fails for no primary key.  use get_tables syntax.
        for coretable, tablename in tables.iteritems():
            self.tables[coretable] = ps.get_tables(self.session.bind, 
                                                   [tablename], 
                                                   metadata=self.metadata)[0]
예제 #2
0
def reflect_or_create_tables(options):
    """
    returns a dict of classes
     make 'em if they don't exist
     "tables" is {'wfdisc': mapped table class, ...}
     """
    tables = {}
    # this list should mirror the command line table options
    for table in mapfns.keys() + ['lastid']:
        #if options.all_tables:
        fulltabnm = getattr(options, table, None)
        if fulltabnm:
            try:
                tables[table] = ps.get_tables(session.bind, [fulltabnm])[0]
            except NoSuchTableError:
                print "{0} doesn't exist. Adding it.".format(fulltabnm)
                tables[table] = ps.make_table(fulltabnm, PROTOTYPES[table])
                tables[table].__table__.create(session.bind, checkfirst=True)

    return tables
예제 #3
0
def reflect_or_create_tables(options):
    """
    returns a dict of classes
     make 'em if they don't exist
     "tables" is {'wfdisc': mapped table class, ...}
     """
    tables = {}
    # this list should mirror the command line table options
    for table in mapfns.keys() + ['lastid']:
        #if options.all_tables:
        fulltabnm = getattr(options, table, None)
        if fulltabnm:
            try:
                tables[table] = ps.get_tables(session.bind, [fulltabnm])[0]
            except NoSuchTableError:
                print "{0} doesn't exist. Adding it.".format(fulltabnm)
                tables[table] = ps.make_table(fulltabnm, PROTOTYPES[table])
                tables[table].__table__.create(session.bind, checkfirst=True)

    return tables
예제 #4
0
    def load_tables(self, **tables):
        """
        Load core tables.

        Tables are given as key=value pairs as in:
        load_tables(wfdisc='global.wfdisc_raw', origin='location.origin')

        Raises
        ------
        sqlalchemy.exc.NoSuchTableError
            Table doesn't exist.

        """
        # TODO: add the tables as attributes?
        # TODO: if isinstance(table, DeclarativeBase): just set it as attribute
        # XXX: fails for no primary key.  use get_tables syntax.
        for coretable, tablename in tables.iteritems():
            self.tables[coretable] = ps.get_tables(self.session.bind,
                                                   [tablename],
                                                   metadata=self.metadata)[0]