Simple example of how to use the ORM

Import necessary stuff


In [1]:
from modelmeta import v1 as modelmeta
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from optparse import OptionParser

Create the database session


In [4]:
engine = create_engine('postgresql://hiebert:mypass@windy.pcic.uvic.ca/pcic_meta?sslmode=require')
Session = sessionmaker(bind=engine)
session = Session()

Query all of some type of object


In [5]:
q = session.query(modelmeta.DataFile)
q.count()


Out[5]:
289L

In [6]:
myfile = q[0]

In [7]:
myfile.run.files[0].timeset.start_date


Out[7]:
datetime.datetime(1850, 1, 1, 12, 0)

In [8]:
myfile.run.driving_run, myfile.run.initialized_from_run


Out[8]:
([], [])

In [9]:
myfile.data_file_variables[0].variable


Out[9]:
<modelmeta.v1.Variable at 0x40552d0>