Coverage for databases/sync_tests/types/raw_queries/test_bytes.py: 100%
19 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 Base64, 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 id = ?',
16)
18_postgresql_queries = Queries(
19 select='SELECT * FROM "Types" WHERE id = $1',
20)
22RAW_QUERIES: DatabaseMapping[Queries] = {
23 'mysql': _mysql_queries,
24 'mariadb': _mysql_queries,
25 'sqlite': Queries(
26 select='SELECT * FROM Types WHERE id = ?',
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 Bytes in raw SELECT queries"""
38 queries = RAW_QUERIES[database]
40 record = client.types.create({'bytes': Base64.encode(b'foo')})
42 found = client.query_first(queries.select, record.id)
43 assert found is not None
44 assert found['id'] == record.id
45 assert found['bytes'] == 'Zm9v'
47 model = client.query_first(queries.select, record.id, model=Types)
48 assert model is not None
49 assert model.id == record.id
50 assert model.bytes.decode_str() == 'foo'