from xdapy import Mapper, Connection, Entity connection = Connection.default() m = Mapper(connection) from objects import Experiment, Observer, Trial, Session m.register(Experiment, Observer, Trial, Session) print set(str(o.parent) for o in m.find_all("Session")) obs = m.find("Observer", {"name": "%Frank%"}).all() print obs[0].data import pdb pdb.set_trace() #print m.find_with("Session").parent(m.find("Observer", {"name": ["%Alex%", "%Frank%"]})).all() from xdapy.operators import gt, lt #trials = m.find_with("Trial", {"_id": lambda id: id*id < 300}).parent(m.find_with("Session", {"_id": lt(300)}).parent(m.find("Observer", {"name": "%Alex%"}))).all() trials = m.find_with("Trial", {"_id": lambda id: id*id < 300, "_parent": ("Session", {"_id": lt(300), "_parent": ("Observer", {"name": "%Alex%"})}), "_with": lambda entity: entity.id != 10}) # find_complex is more powerful but does not use SQLAlchemy
# -*- coding: utf-8 -*- from xdapy import Connection, Mapper, Entity connection = Connection.profile("demo") # use standard profile connection_2 = Connection.default() # use standard profile # drop the old database structure connection.create_tables() connection_2.create_tables() m = Mapper(connection) m_2 = Mapper(connection_2) # from objects import Experiment, ... class Experiment(Entity): """Concrete class for experiments""" declared_params = { 'experimenter': 'string', 'project': 'string' } Experiment_nodate = Experiment class Experiment(Entity): """Concrete class for experiments""" declared_params = { 'experimenter': 'string', 'project': 'string', 'date': 'date' }