"""
byceps.services.language.language_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2014-2023 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from sqlalchemy import select

from byceps.database import db

from .dbmodels import DbLanguage
from .models import Language


def create_language(code: str) -> Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()

    return _db_entity_to_language(db_language)


def get_languages() -> list[Language]:
    """Return all languages."""
    db_languages = db.session.scalars(select(DbLanguage)).all()

    return [_db_entity_to_language(db_language) for db_language in db_languages]


def _db_entity_to_language(db_language: DbLanguage) -> Language:
    return Language(code=db_language.code)

804d3d0ed6c634a3fd2e13a30a964bc04600e0cb
<mask token>


def create_language(code: str) ->Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()
    return _db_entity_to_language(db_language)


<mask token>

<mask token>


def create_language(code: str) ->Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()
    return _db_entity_to_language(db_language)


def get_languages() ->list[Language]:
    """Return all languages."""
    db_languages = db.session.scalars(select(DbLanguage)).all()
    return [_db_entity_to_language(db_language) for db_language in db_languages
        ]


<mask token>

<mask token>


def create_language(code: str) ->Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()
    return _db_entity_to_language(db_language)


def get_languages() ->list[Language]:
    """Return all languages."""
    db_languages = db.session.scalars(select(DbLanguage)).all()
    return [_db_entity_to_language(db_language) for db_language in db_languages
        ]


def _db_entity_to_language(db_language: DbLanguage) ->Language:
    return Language(code=db_language.code)

<mask token>
from sqlalchemy import select
from byceps.database import db
from .dbmodels import DbLanguage
from .models import Language


def create_language(code: str) ->Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()
    return _db_entity_to_language(db_language)


def get_languages() ->list[Language]:
    """Return all languages."""
    db_languages = db.session.scalars(select(DbLanguage)).all()
    return [_db_entity_to_language(db_language) for db_language in db_languages
        ]


def _db_entity_to_language(db_language: DbLanguage) ->Language:
    return Language(code=db_language.code)

"""
byceps.services.language.language_service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2014-2023 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from sqlalchemy import select

from byceps.database import db

from .dbmodels import DbLanguage
from .models import Language


def create_language(code: str) -> Language:
    """Create a language."""
    db_language = DbLanguage(code)
    db.session.add(db_language)
    db.session.commit()

    return _db_entity_to_language(db_language)


def get_languages() -> list[Language]:
    """Return all languages."""
    db_languages = db.session.scalars(select(DbLanguage)).all()

    return [_db_entity_to_language(db_language) for db_language in db_languages]


def _db_entity_to_language(db_language: DbLanguage) -> Language:
    return Language(code=db_language.code)
