Coverage for databases/tests/types/raw_queries/test_bigint.py: 100%
32 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 ...._types import DatabaseMapping, SupportedDatabase
8from ...._compat import LiteralString
11class Queries(BaseModel):
12 select: LiteralString
13 select_null: LiteralString
16_mysql_queries = Queries(
17 select='SELECT * FROM Types WHERE `bigint` = ?',
18 select_null='SELECT * FROM Types WHERE `optional_bigint` IS NULL',
19)
21_postgresql_queries = Queries(
22 select='SELECT * FROM "Types" WHERE bigint = $1',
23 select_null='SELECT * FROM "Types" WHERE optional_bigint IS NULL',
24)
26RAW_QUERIES: DatabaseMapping[Queries] = {
27 'mysql': _mysql_queries,
28 'mariadb': _mysql_queries,
29 'sqlite': Queries(
30 select='SELECT * FROM Types WHERE bigint = ?',
31 select_null='SELECT * FROM Types WHERE optional_bigint IS NULL',
32 ),
33 'postgresql': _postgresql_queries,
34 'cockroachdb': _postgresql_queries,
35}
38@pytest.mark.asyncio
39async def test_query_first(
40 client: Prisma,
41 database: SupportedDatabase,
42) -> None:
43 """Standard usage of BigInt in raw SELECT queries"""
44 queries = RAW_QUERIES[database]
46 record = await client.types.create({'bigint': 12522})
48 found = await client.query_first(queries.select, 12522)
49 assert found['id'] == record.id
50 assert found['bigint'] == 12522
52 model = await client.query_first(queries.select, 12522, model=Types)
53 assert model is not None
54 assert model.id == record.id
55 assert model.bigint == 12522
58@pytest.mark.asyncio
59async def test_query_first_optional(
60 client: Prisma,
61 database: SupportedDatabase,
62) -> None:
63 """Use of BigInt in raw SELECT queries with optional/nullable results"""
64 queries = RAW_QUERIES[database]
66 record = await client.types.create({'optional_bigint': None})
68 found = await client.query_first(queries.select_null)
69 assert found['id'] == record.id
70 assert found['optional_bigint'] is None
72 model = await client.query_first(queries.select_null, model=Types)
73 assert model is not None
74 assert model.id == record.id
75 assert model.optional_bigint is None