<commit_before>from typing import Union

from sqlalchemy.ext.asyncio import AsyncSession

import virtool.utils
from virtool.uploads.models import Upload


async def create(db, name: str, upload_type: str, reserved: bool = False, user: Union[None, str] = None):
    """
    Creates and commits a new upload document

    :param db: PostgreSQL database object
    :param name: the name of the upload
    :param upload_type: the type of upload (e.g. reads)
    :param reserved: should the file immediately be reserved (used for legacy samples)
    :param user: the id of the uploading user
    :return: a JSON response document
    """
    async with AsyncSession(db) as session:
        upload = Upload(
            created_at=virtool.utils.timestamp(),
            name=name,
            ready=False,
            removed=False,
            reserved=reserved,
            type=upload_type,
            user=user
        )

        session.add(upload)

        await session.flush()
        document = upload.to_dict()

        await session.commit()

        return document<commit_msg>Rename `document` to `upload` in `uploads.db`<commit_after>from typing import Union

from sqlalchemy.ext.asyncio import AsyncSession

import virtool.utils
from virtool.uploads.models import Upload


async def create(db, name: str, upload_type: str, reserved: bool = False, user: Union[None, str] = None):
    """
    Creates and commits a new upload document

    :param db: PostgreSQL database object
    :param name: the name of the upload
    :param upload_type: the type of upload (e.g. reads)
    :param reserved: should the file immediately be reserved (used for legacy samples)
    :param user: the id of the uploading user
    :return: a JSON response document
    """
    async with AsyncSession(db) as session:
        upload = Upload(
            created_at=virtool.utils.timestamp(),
            name=name,
            ready=False,
            removed=False,
            reserved=reserved,
            type=upload_type,
            user=user
        )

        session.add(upload)

        await session.flush()
        upload = upload.to_dict()

        await session.commit()

        return upload
{'fraction_non_alphanumeric': 0.07969034608378871, 'fraction_numerical': 0.0, 'mean_word_length': 2.492845786963434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4473885', 'n_tokens_mistral': 602, 'n_tokens_neox': 586, 'n_words': 210}