Coverage for databases/tests/types/raw_queries/test_bool.py: 100%
22 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1import pytest
2from pydantic import BaseModel
4from prisma import Prisma
5from prisma.models import Types
7from ....utils import DatabaseConfig
8from ...._types import DatabaseMapping, SupportedDatabase
9from ...._compat import LiteralString
12class Queries(BaseModel):
13 select: LiteralString
16_mysql_queries = Queries(
17 select='SELECT * FROM Types WHERE bool_ = ?',
18)
20_postgresql_queries = Queries(
21 select='SELECT * FROM "Types" WHERE bool_ = $1',
22)
24RAW_QUERIES: DatabaseMapping[Queries] = {
25 'mysql': _mysql_queries,
26 'mariadb': _mysql_queries,
27 'sqlite': Queries(
28 select='SELECT * FROM Types WHERE bool_ = ?',
29 ),
30 'postgresql': _postgresql_queries,
31 'cockroachdb': _postgresql_queries,
32}
35@pytest.mark.asyncio
36async def test_query_first(
37 client: Prisma,
38 database: SupportedDatabase,
39 config: DatabaseConfig,
40) -> None:
41 """Standard usage of Boolean in raw SELECT queries"""
42 queries = RAW_QUERIES[database]
44 record = await client.types.create({'bool_': True})
46 found = await client.query_first(queries.select, True)
47 assert found['id'] == record.id
49 if config.bools_are_ints:
50 assert found['bool_'] == 1
51 else:
52 assert found['bool_'] is True
54 model = await client.query_first(queries.select, True, model=Types)
55 assert model is not None
56 assert model.id == record.id
57 assert model.bool_ is True