@@ -115,7 +115,9 @@ def _adapt_complex(value: complex | np.complexfloating) -> sqlite3.Binary:
115
115
return sqlite3 .Binary (out .read ())
116
116
117
117
118
- def connect (name : str | Path , debug : bool = False , version : int = - 1 ) -> ConnectionPlus :
118
+ def connect (
119
+ name : str | Path , debug : bool = False , version : int = - 1 , read_only : bool = False
120
+ ) -> ConnectionPlus :
119
121
"""
120
122
Connect or create database. If debug the queries will be echoed back.
121
123
This function takes care of registering the numpy/sqlite type
@@ -126,6 +128,7 @@ def connect(name: str | Path, debug: bool = False, version: int = -1) -> Connect
126
128
debug: should tracing be turned on.
127
129
version: which version to create. We count from 0. -1 means 'latest'.
128
130
Should always be left at -1 except when testing.
131
+ read_only: Should the database be opened in read only mode.
129
132
130
133
Returns:
131
134
connection object to the database (note, it is
@@ -137,8 +140,14 @@ def connect(name: str | Path, debug: bool = False, version: int = -1) -> Connect
137
140
# register binary(TEXT) -> numpy converter
138
141
sqlite3 .register_converter ("array" , _convert_array )
139
142
140
- sqlite3_conn = sqlite3 .connect (name , detect_types = sqlite3 .PARSE_DECLTYPES ,
141
- check_same_thread = True )
143
+ path = f"file:{ str (name )} "
144
+
145
+ if read_only :
146
+ path = path + "?ro"
147
+
148
+ sqlite3_conn = sqlite3 .connect (
149
+ path , detect_types = sqlite3 .PARSE_DECLTYPES , check_same_thread = True , uri = True
150
+ )
142
151
conn = ConnectionPlus (sqlite3_conn )
143
152
144
153
latest_supported_version = _latest_available_version ()
0 commit comments