Source code for bw2data.backends.schema

from peewee import DoesNotExist, TextField

from bw2data.errors import UnknownObject
from bw2data.snowflake_ids import SnowflakeIDBaseClass
from bw2data.sqlite import PickleField


[docs] class ActivityDataset(SnowflakeIDBaseClass):
[docs] data = PickleField() # Canonical, except for other C fields
[docs] code = TextField() # Canonical
[docs] database = TextField() # Canonical
[docs] location = TextField(null=True) # Reset from `data`
[docs] name = TextField(null=True) # Reset from `data`
[docs] product = TextField(null=True) # Reset from `data`
[docs] type = TextField(null=True) # Reset from `data`
@property
[docs] def key(self): return (self.database, self.code)
[docs] class ExchangeDataset(SnowflakeIDBaseClass):
[docs] data = PickleField() # Canonical, except for other C fields
[docs] input_code = TextField() # Canonical
[docs] input_database = TextField() # Canonical
[docs] output_code = TextField() # Canonical
[docs] output_database = TextField() # Canonical
[docs] type = TextField() # Reset from `data`
[docs] def get_id(key): if isinstance(key, int): try: ActivityDataset.get(ActivityDataset.id == key) except DoesNotExist: raise UnknownObject return key else: try: return ActivityDataset.get( ActivityDataset.database == key[0], ActivityDataset.code == key[1] ).id except DoesNotExist: raise UnknownObject