Coverage for databases/sync_tests/types/raw_queries/test_bool.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-08-27 18:25 +0000

1from pydantic import BaseModel 

2 

3from prisma import Prisma 

4from prisma.models import Types 

5 

6from ....utils import DatabaseConfig 

7from ...._types import DatabaseMapping, SupportedDatabase 

8from ...._compat import LiteralString 

9 

10 

11class Queries(BaseModel): 

12 select: LiteralString 

13 

14 

15_mysql_queries = Queries( 

16 select='SELECT * FROM Types WHERE bool_ = ?', 

17) 

18 

19_postgresql_queries = Queries( 

20 select='SELECT * FROM "Types" WHERE bool_ = $1', 

21) 

22 

23RAW_QUERIES: DatabaseMapping[Queries] = { 

24 'mysql': _mysql_queries, 

25 'mariadb': _mysql_queries, 

26 'sqlite': Queries( 

27 select='SELECT * FROM Types WHERE bool_ = ?', 

28 ), 

29 'postgresql': _postgresql_queries, 

30 'cockroachdb': _postgresql_queries, 

31} 

32 

33 

34def test_query_first( 

35 client: Prisma, 

36 database: SupportedDatabase, 

37 config: DatabaseConfig, 

38) -> None: 

39 """Standard usage of Boolean in raw SELECT queries""" 

40 queries = RAW_QUERIES[database] 

41 

42 record = client.types.create({'bool_': True}) 

43 

44 found = client.query_first(queries.select, True) 

45 assert found['id'] == record.id 

46 

47 if config.bools_are_ints: 

48 assert found['bool_'] == 1 

49 else: 

50 assert found['bool_'] is True 

51 

52 model = client.query_first(queries.select, True, model=Types) 

53 assert model is not None 

54 assert model.id == record.id 

55 assert model.bool_ is True