Coverage for databases/sync_tests/types/raw_queries/test_datetime.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 datetime
3from pydantic import BaseModel
5from prisma import Prisma
6from prisma.models import Types
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 `id` = ?',
18)
20_postgresql_queries = Queries(
21 select='SELECT * FROM "Types" WHERE id = $1',
22)
24RAW_QUERIES: DatabaseMapping[Queries] = {
25 'mysql': _mysql_queries,
26 'mariadb': _mysql_queries,
27 'sqlite': Queries(
28 select='SELECT * FROM Types WHERE id = ?',
29 ),
30 'postgresql': _postgresql_queries,
31 'cockroachdb': _postgresql_queries,
32}
35def test_query_first(
36 client: Prisma,
37 database: SupportedDatabase,
38) -> None:
39 """Standard usage of a DateTime field in raw SELECT queries"""
40 queries = RAW_QUERIES[database]
42 datetime_ = datetime.datetime(
43 year=2022,
44 month=12,
45 day=25,
46 hour=12,
47 minute=1,
48 second=34,
49 tzinfo=datetime.timezone.utc,
50 )
52 record = client.types.create({'datetime_': datetime_})
54 found = client.query_first(queries.select, record.id)
55 assert found['id'] == record.id
56 assert found['datetime_'] == '2022-12-25T12:01:34+00:00'
58 model = client.query_first(queries.select, record.id, model=Types)
59 assert model is not None
60 assert model.id == record.id
61 assert model.datetime_ == datetime_