def testSubQuery(self): thread_pool = ThreadPoolExecutor(2) e = Engine(ThreadsExecutor(thread_pool)) def query_a(fields, ids): data = {1: {'f': 2}} return [[data[i][f] for f in fields] for i in ids] r = graph.Edge(None, [ graph.Edge('a', [ graph.Field('f', query_a), ]), ]) # ---------------------------------------------- @define('[[:f]]', _name='inc_f') def inc_f(obj): return obj['f'] + 1 r1 = graph.Edge(None, [ graph.Edge('a1', subquery_fields(r, 'a', { 'f1': inc_f(S.this), })), graph.Link('la1', None, 'a1', lambda: [1], True), ]) self.assertEqual( e.execute(r1, read('[{:la1 [:f1]}]'))['la1'], [{ 'f1': 3 }])
def setUp(self): sa_engine = create_engine( 'sqlite://', connect_args={'check_same_thread': False}, poolclass=StaticPool, ) metadata.create_all(sa_engine) session.configure(bind=sa_engine) def bar_insert(r): return sa_engine.execute(bar_table.insert(), r).lastrowid self.bar_ids = list(map(bar_insert, [ {'name': 'bar1', 'type': 1}, {'name': 'bar2', 'type': 2}, {'name': 'bar3', 'type': 3}, ])) def foo_insert(r): return sa_engine.execute(foo_table.insert(), r).lastrowid list(map(foo_insert, [ {'name': 'foo1', 'count': 5, 'bar_id': self.bar_ids[0]}, {'name': 'foo2', 'count': 10, 'bar_id': self.bar_ids[1]}, {'name': 'foo3', 'count': 15, 'bar_id': self.bar_ids[2]}, ])) self.engine = Engine(ThreadsExecutor(thread_pool))
def check(self, src, value): sa_engine = create_engine( 'sqlite://', connect_args={'check_same_thread': False}, poolclass=StaticPool, ) setup_db(sa_engine) engine = Engine(ThreadsExecutor(thread_pool)) result = engine.execute(self.graph, read(src), {SA_ENGINE_KEY: sa_engine}) check_result(result, value)
def _engine(): return Engine(ThreadsExecutor(ThreadPoolExecutor(2)))
def setUp(self): self.engine = Engine(ThreadsExecutor(thread_pool))
def setUp(self): self.engine = Engine(ThreadsExecutor(ThreadPoolExecutor(2)))