db.attach(alias, filepath) method, closes #113

Will also be useful for #236
This commit is contained in:
Simon Willison 2021-02-18 20:56:32 -08:00
commit 999f099cbe
3 changed files with 45 additions and 0 deletions

View file

@ -219,6 +219,14 @@ class Database:
def register_fts4_bm25(self):
self.register_function(rank_bm25, deterministic=True)
def attach(self, alias, filepath):
attach_sql = """
ATTACH DATABASE '{}' AS [{}];
""".format(
str(pathlib.Path(filepath).resolve()), alias
).strip()
self.execute(attach_sql)
def execute(self, sql, parameters=None):
if self._tracer:
self._tracer(sql, parameters)