Skip to content

Instantly share code, notes, and snippets.

@illia-v
Created Dec 15, 2018
Embed
What would you like to do?
How to limit results of a database query per group using SQLAlchemy and PostgreSQL
from faker import Faker
fake = Faker()
for _ in range(3):
query = authors_table.insert().values(name=fake.name())
engine.execute(query)
result = engine.execute(authors_table.select())
for author_id in (author.id for author in result):
for _ in range(5):
query = articles_table.insert().values(
author_id=author_id,
title=fake.text(15)[:-1],
text=fake.text(20) + '..',
views=fake.pyint(),
)
engine.execute(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment