This repository was archived by the owner on Jun 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequirements.py
More file actions
72 lines (63 loc) · 2.22 KB
/
Copy pathrequirements.py
File metadata and controls
72 lines (63 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from sqlalchemy import exc
from sqlalchemy.testing.exclusions import closed
from sqlalchemy.testing.exclusions import only_on
from sqlalchemy.testing.requirements import SuiteRequirements
# this is based on sqlalchemy/test/requirements.py
class Requirements(SuiteRequirements):
def _sqlite_json(self, config):
with config.db.connect() as conn:
try:
return (
conn.exec_driver_sql(
"""select json_extract('{"foo": "bar"}', """
"""'$."foo"')"""
).scalar()
== "bar"
)
except exc.DBAPIError:
return False
@property
def json_type(self):
return only_on([self._sqlite_json])
@property
def reflects_json_type(self):
return only_on(["sqlite >= 3.9"])
def _sqlite_partial_idx(self, config):
with config.db.connect() as conn:
connection = conn.connection
cursor = connection.cursor()
try:
cursor.execute("SELECT * FROM pragma_index_info('idx52')")
except:
return False
else:
return (
cursor.description is not None
and len(cursor.description) >= 3
)
finally:
cursor.close()
@property
def sqlite_partial_indexes(self):
return only_on(self._sqlite_partial_idx)
def _sqlite_attach(self, config):
with config.db.connect() as conn:
connection = conn.connection
cursor = connection.cursor()
try:
cursor.execute("ATTACH ':memory:' AS test_schema")
cursor.execute("DETACH test_schema")
return True
except:
return False
finally:
cursor.close()
@property
def sqlite_attach(self):
return only_on(self._sqlite_attach)
@property
def sqlite_savepoint(self):
# TODO: sqld should send "autocommit" state so we know
# we're inside a transaction or not. Meanwhile libsql_client
# tries to figure out and is lost with savepoints
return closed()