def test_factory(self): self.ctx.default_factory = dbkit.dict_set with self.ctx: row = dbkit.query_row(""" SELECT counter, value FROM counters WHERE counter = ? """, ('foo',)) self.assertTrue(isinstance(row, dict)) self.assertEqual(len(row), 2) self.assertTrue('counter' in row) self.assertTrue('value' in row) self.assertEqual(row['counter'], 'foo') self.assertEqual(row['value'], 42) row = dbkit.query_row(""" SELECT counter, value FROM counters WHERE counter = ? """, ('bar',)) self.assertTrue(row is None)
def test_factory(): with setup() as ctx: ctx.default_factory = dbkit.dict_set row = dbkit.query_row(""" SELECT counter, value FROM counters WHERE counter = ? """, ('foo',)) assert isinstance(row, dict) assert len(row) == 2 assert 'counter' in row assert 'value' in row assert row['counter'] == 'foo' assert row['value'] == 42 row = dbkit.query_row(""" SELECT counter, value FROM counters WHERE counter = ? """, ('bar',)) assert row is None
def get_paste(paste_id): """ Get a paste by ID. """ return dbkit.query_row(""" SELECT paste_id, created, poster, title, body, syntax FROM pastes WHERE paste_id = ? """, (paste_id,))
def get_chunk(chunk_id): """ Get a paste chunk by ID. """ return dbkit.query_row(""" SELECT body, syntax FROM chunks WHERE chunk_id = ? """, (chunk_id,))
def get_paste(paste_id): """ Get a paste by ID. """ paste = dbkit.query_row(""" SELECT paste_id, created, poster, title FROM pastes WHERE paste_id = ? """, (paste_id,)) if paste is not None: paste['chunks'] = dbkit.query(""" SELECT chunk_id, body, syntax FROM chunks WHERE paste_id = ? ORDER BY chunk_id """, (paste_id,)) return paste
def get_project(slug): return dbkit.query_row(""" SELECT project_id, slug, project, overview FROM projects WHERE slug = ? """, (slug,))