Coverage for databases/sync_tests/types/raw_queries/test_float.py: 100%
18 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
1from pydantic import BaseModel
3from prisma import Prisma
4from prisma.models import Types
6from ...._types import DatabaseMapping, SupportedDatabase
7from ...._compat import LiteralString
10class Queries(BaseModel):
11 select: LiteralString
14_mysql_queries = Queries(
15 select='SELECT * FROM Types WHERE float_ = ?',
16)
18_postgresql_queries = Queries(
19 select='SELECT * FROM "Types" WHERE float_ = $1',
20)
22RAW_QUERIES: DatabaseMapping[Queries] = {
23 'mysql': _mysql_queries,
24 'mariadb': _mysql_queries,
25 'sqlite': Queries(
26 select='SELECT * FROM Types WHERE float_ = ?',
27 ),
28 'postgresql': _postgresql_queries,
29 'cockroachdb': _postgresql_queries,
30}
33def test_query_first(
34 client: Prisma,
35 database: SupportedDatabase,
36) -> None:
37 """Standard usage of float_ in raw SELECT queries"""
38 queries = RAW_QUERIES[database]
40 record = client.types.create({'float_': 10.5})
42 found = client.query_first(queries.select, 10.5)
43 assert found['id'] == record.id
44 assert found['float_'] == 10.5
46 model = client.query_first(queries.select, 10.5, model=Types)
47 assert model is not None
48 assert model.id == record.id
49 assert model.float_ == 10.5