Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLalchemy: Mapping columns into different properties
    text
    copied!<p>I am trying to store some simulation measurements (times and values) using sqlalchemy. Here are the relevant table definitions. If there is a more sensible table definition, I'd love to see it.</p> <pre><code>from sqlalchemy import create_engine, schema, orm engine = create_engine('sqlite:///:memory:', echo=True) metadata = schema.MetaData(bind=engine) container_table = schema.Table('containers', metadata, schema.Column('id', schema.types.Integer, primary_key=True)) measurement_table = schema.Table('measurements', metadata, schema.Column('id', schema.types.Integer, primary_key=True), schema.Column('container_id', schema.types.Integer, schema.ForeignKey('containers.id')), schema.Column('time', schema.types.Float), schema.Column('value', schema.types.Float)) metadata.create_all() </code></pre> <p>The times will be unique for each container, and the below properties should be ordered by time.</p> <p>I would like to be able to both read and assign these properties:</p> <pre><code>c = Container() times = range(10) values = [t**2 for t in times] c.times = times c.values = values </code></pre> <p>But I don't know how to do the mapping. I assume that if it's possible, it will look something like this:</p> <pre><code>class Container(object): times = some_sort_of_proxy() values = some_sort_of_proxy() orm.mapper(Container, container_table, properties={ # Magic }) </code></pre> <p>How do I go about doing this? Is this a reasonable mapping, or do I need to have a different underlying table structure?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload