Ejemplo n.º 1
0
    def chianti_ions_table(self):

        if self._chianti_ions_table is None:

            chianti_ions_table_name = "ChiantiIonList" + str(
                hash(frozenset(self.chianti_ions)))

            try:
                chianti_ions_table = Base.metadata.tables[convert_camel2snake(
                    chianti_ions_table_name)]
            except KeyError:
                chianti_ions_table = type(chianti_ions_table_name,
                                          (Base, IonListMixin),
                                          dict()).__table__

            try:
                # To create the temporary table use the session's current transaction-bound connection
                chianti_ions_table.create(self.session.connection())
            except OperationalError:  # Raised if the table already exists
                pass
            else:
                # Insert values from `ions` into the table
                if self.chianti_ions:
                    self.session.execute(
                        chianti_ions_table.insert(), [{
                            "atomic_number": atomic_number,
                            "ion_charge": ion_charge
                        } for atomic_number, ion_charge in self.chianti_ions])

            self._chianti_ions_table = chianti_ions_table
        return self._chianti_ions_table
Ejemplo n.º 2
0
    def chianti_ions_table(self):

        if self._chianti_ions_table is None:

            chianti_ions_table_name = "ChiantiIonList" + str(hash(frozenset(self.chianti_ions)))

            try:
                chianti_ions_table = Base.metadata.tables[convert_camel2snake(chianti_ions_table_name)]
            except KeyError:
                chianti_ions_table = type(chianti_ions_table_name, (Base, IonListMixin), dict()).__table__

            try:
                # To create the temporary table use the session's current transaction-bound connection
                chianti_ions_table.create(self.session.connection())
            except OperationalError:  # Raised if the table already exists
                pass
            else:
                # Insert values from `ions` into the table
                if self.chianti_ions:
                    self.session.execute(chianti_ions_table.insert(),
                                         [{"atomic_number": atomic_number, "ion_charge": ion_charge}
                                          for atomic_number, ion_charge in self.chianti_ions])

            self._chianti_ions_table = chianti_ions_table
        return self._chianti_ions_table
Ejemplo n.º 3
0
 def __tablename__(cls):
     return convert_camel2snake(cls.__name__)
Ejemplo n.º 4
0
 def __tablename__(cls):
     return convert_camel2snake(cls.__name__)