Coverage for databases/tests/types/raw_queries/test_string.py: 100%
20 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
15_mysql_queries = Queries(
16 select='SELECT * FROM Types WHERE string = ?',
17)
19_postgresql_queries = Queries(
20 select='SELECT * FROM "Types" WHERE string = $1',
21)
23RAW_QUERIES: DatabaseMapping[Queries] = {
24 'mysql': _mysql_queries,
25 'mariadb': _mysql_queries,
26 'sqlite': Queries(
27 select='SELECT * FROM Types WHERE string = ?',
28 ),
29 'postgresql': _postgresql_queries,
30 'cockroachdb': _postgresql_queries,
31}
34@pytest.mark.asyncio
35async def test_query_first(
36 client: Prisma,
37 database: SupportedDatabase,
38) -> None:
39 """Standard usage of string in raw SELECT queries"""
40 queries = RAW_QUERIES[database]
42 record = await client.types.create({'string': 'abcd'})
44 found = await client.query_first(queries.select, 'abcd')
45 assert found['id'] == record.id
46 assert found['string'] == 'abcd'
48 model = await client.query_first(queries.select, 'abcd', model=Types)
49 assert model is not None
50 assert model.id == record.id
51 assert model.string == 'abcd'