Coverage for databases/constants.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 __future__ import annotations
3from typing import List, cast
4from pathlib import Path
5from typing_extensions import get_args
7from lib import pyright
9from .utils import DatabaseConfig, DatabaseFeature
10from ._types import DatabaseMapping, SupportedDatabase
13def _fromdir(path: str) -> list[str]:
14 """Get the contents of a subdirectory within the `` directory"""
15 # TODO: recurse subdirs
16 return [str(f.relative_to(TESTS_DIR)) for f in (TESTS_DIR / path).iterdir()]
19# databases
20CONFIG_MAPPING: DatabaseMapping[DatabaseConfig] = {
21 'postgresql': DatabaseConfig(
22 id='postgresql',
23 name='PostgreSQL',
24 env_var='POSTGRESQL_URL',
25 bools_are_ints=False,
26 unsupported_features=set(),
27 default_date_func='CURRENT_DATE',
28 autoincrement_id='Int @id @default(autoincrement())',
29 ),
30 'cockroachdb': DatabaseConfig(
31 id='cockroachdb',
32 name='CockroachDB',
33 env_var='COCKROACHDB_URL',
34 bools_are_ints=False,
35 default_date_func='CURRENT_DATE',
36 autoincrement_id='BigInt @id @default(sequence())',
37 unsupported_features={
38 'json_arrays',
39 'array_push',
40 'transactions',
41 'full_text_search',
42 },
43 ),
44 'sqlite': DatabaseConfig(
45 id='sqlite',
46 name='SQLite',
47 env_var='SQLITE_URL',
48 bools_are_ints=False,
49 default_date_func='',
50 autoincrement_id='Int @id @default(autoincrement())',
51 unsupported_features={
52 'enum',
53 'json',
54 'date',
55 'arrays',
56 'create_many_skip_duplicates',
57 'case_sensitivity',
58 'full_text_search',
59 },
60 ),
61 'mysql': DatabaseConfig(
62 id='mysql',
63 name='MySQL',
64 env_var='MYSQL_URL',
65 bools_are_ints=True,
66 default_date_func='(CURRENT_DATE)',
67 autoincrement_id='Int @id @default(autoincrement())',
68 unsupported_features={
69 'arrays',
70 'case_sensitivity',
71 },
72 ),
73 'mariadb': DatabaseConfig(
74 id='mysql',
75 name='MariaDB',
76 env_var='MARIADB_URL',
77 bools_are_ints=True,
78 default_date_func='CURRENT_DATE',
79 autoincrement_id='Int @id @default(autoincrement())',
80 unsupported_features={
81 'arrays',
82 'case_sensitivity',
83 'full_text_search',
84 },
85 ),
86}
87SUPPORTED_DATABASES = cast(List[SupportedDatabase], list(get_args(SupportedDatabase)))
89# paths
90ROOT_DIR = Path(__file__).parent.parent
91DATABASES_DIR = Path(__file__).parent
93# database features
94TESTS_DIR = DATABASES_DIR / 'tests'
95SYNC_TESTS_DIR = DATABASES_DIR / 'sync_tests'
96FEATURES_MAPPING: dict[DatabaseFeature, list[str]] = {
97 'enum': ['test_enum.py', 'test_arrays/test_enum.py'],
98 'json': [
99 'types/test_json.py',
100 'test_arrays/test_json.py',
101 'types/raw_queries/test_json.py',
102 ],
103 'arrays': [*_fromdir('arrays'), *_fromdir('types/raw_queries/arrays')],
104 'array_push': _fromdir('arrays/push'),
105 'json_arrays': ['arrays/test_json.py', 'arrays/push/test_json.py'],
106 'transactions': ['test_transactions.py'],
107 # not yet implemented
108 'date': [],
109 'create_many_skip_duplicates': ['test_create_many_skip_duplicates.py'],
110 'raw_queries': ['test_raw_queries.py', *_fromdir('types/raw_queries')],
111 'case_sensitivity': ['test_case_sensitivity.py'],
112 'full_text_search': ['test_full_text_search.py'],
113}
115# config files
116PYRIGHT_CONFIG: pyright.Config = {
117 'include': [],
118 'exclude': ['../src/prisma/_vendor/**.py', '**/prisma/_vendor/**.py'],
119 # required so that Pyright can resolve the `lib` module
120 'extraPaths': ['../'],
121 'typeCheckingMode': 'strict',
122 'reportPrivateUsage': False,
123 # copied from `pyproject.toml`
124 'reportUnusedImport': True,
125 'reportPrivateUsage': False,
126 'reportImportCycles': False,
127 'reportUnknownMemberType': False,
128 'reportUnknownVariableType': False,
129 'reportUnknownArgumentType': False,
130 # very strict errors
131 'reportImplicitOverride': True,
132 'reportUnusedCallResult': False,
133 'reportImplicitStringConcatenation': False,
134 'reportCallInDefaultInitializer': True,
135}
136PYTEST_CONFIG = {
137 '[tool.pytest.ini_options]': {
138 'asyncio_mode': 'strict',
139 'ignore': [],
140 },
141}