Changed poems adding to packet add_all
This commit is contained in:
parent
860ea43091
commit
1f7f69e933
@ -11,6 +11,7 @@ from . import auth_utils, orm_models, pydantic_schemas
|
|||||||
|
|
||||||
# Загружаем стихи
|
# Загружаем стихи
|
||||||
async def add_poems_to_db(async_db: AsyncSession):
|
async def add_poems_to_db(async_db: AsyncSession):
|
||||||
|
poems = []
|
||||||
f1 = open('poems.txt', encoding='utf-8', mode='r')#открыть фаил для чтения на русском
|
f1 = open('poems.txt', encoding='utf-8', mode='r')#открыть фаил для чтения на русском
|
||||||
for a in range(1, 110):
|
for a in range(1, 110):
|
||||||
f1.seek(0)#перейти к началу
|
f1.seek(0)#перейти к началу
|
||||||
@ -35,8 +36,11 @@ async def add_poems_to_db(async_db: AsyncSession):
|
|||||||
author += str1
|
author += str1
|
||||||
poem = orm_models.Poems(title=name, text=stixi, author=author)
|
poem = orm_models.Poems(title=name, text=stixi, author=author)
|
||||||
# В конце каждой итерации добавляем в базу данных
|
# В конце каждой итерации добавляем в базу данных
|
||||||
async_db.add(poem)
|
poems.append(poem)
|
||||||
async_db.commit()
|
|
||||||
|
async_db.add_all(poems)
|
||||||
|
|
||||||
|
await async_db.commit()
|
||||||
|
|
||||||
# close the file
|
# close the file
|
||||||
f1.close()
|
f1.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user