Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read local/remote url dynamically in connect_to_sqlite #123

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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