Skip to content

Commit

Permalink
Merge pull request #123 from aparnakesarkar/main
Browse files Browse the repository at this point in the history
read local/remote url dynamically in connect_to_sqlite
  • Loading branch information
zainhoda authored Oct 7, 2023
2 parents e49a6ed + 87e57f5 commit 4862898
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/vanna/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import os
import sqlite3
import traceback

from abc import ABC, abstractmethod
from typing import List, Tuple, Union
from urllib.parse import urlparse

import pandas as pd
import plotly
Expand Down Expand Up @@ -235,17 +237,18 @@ def connect_to_sqlite(self, url: str):
# URL of the database to download

# Path to save the downloaded database
path = "tempdb.sqlite"
path = os.path.basename(urlparse(url).path)

# Download the database if it doesn't exist
if not os.path.exists(path):
if not os.path.exists(url):
response = requests.get(url)
response.raise_for_status() # Check that the request was successful
with open(path, "wb") as f:
f.write(response.content)
url = path

# Connect to the database
conn = sqlite3.connect(path)
conn = sqlite3.connect(url)

def run_sql_sqlite(sql: str):
return pd.read_sql_query(sql, conn)
Expand Down

0 comments on commit 4862898

Please sign in to comment.