Skip to content

Commit

Permalink
fix(sqlite): interpolate pathlib.Path correctly in attach
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jan 16, 2023
1 parent 245f482 commit 0415bd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 10 additions & 7 deletions ibis/backends/sqlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,25 @@ def column_reflect(inspector, table, column_info):
if type(column_info["type"]) is TIMESTAMP:
column_info["type"] = ISODATETIME()

def attach(
self,
name: str,
path: str | Path,
) -> None:
def attach(self, name: str, path: str | Path) -> None:
"""Connect another SQLite database file to the current connection.
Parameters
----------
name
Database name within SQLite
path
Path to sqlite3 database file
Path to sqlite3 database files
Examples
--------
>>> con1 = ibis.sqlite.connect("original.db")
>>> con2 = ibis.sqlite.connect("new.db")
>>> con1.attach("new", "new.db")
>>> con1.list_tables(database="new")
"""
quoted_name = self.con.dialect.identifier_preparer.quote(name)
self.raw_sql(f"ATTACH DATABASE {path!r} AS {quoted_name}")
self.raw_sql(f"ATTACH DATABASE {str(path)!r} AS {quoted_name}")

def _get_sqla_table(self, name, schema=None, autoload=True):
return sa.Table(
Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/sqlite/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from pathlib import Path

import numpy as np
import pandas.testing as tm
Expand Down Expand Up @@ -44,7 +45,7 @@ def test_list_tables(con):
def test_attach_file(dbpath):
client = ibis.sqlite.connect(None)

client.attach('foo', dbpath)
client.attach('foo', Path(dbpath))
client.attach('bar', dbpath)

foo_tables = client.list_tables(database='foo')
Expand Down

0 comments on commit 0415bd3

Please sign in to comment.