Skip to content

Conversation

goyalpramod
Copy link
Contributor

@goyalpramod goyalpramod commented Jul 30, 2023

Earlier db_helper for sqlite support was storing the temporary db in the root directory. After this PR it will store the temporary db files in a temporary directory that can be deleted later.

Regex has also been improved in create_schema_for_db to take care of the case when semi-colon (;) may be present inside the query.

@goyalpramod
Copy link
Contributor Author

@suyashgautam kindly review the changes whenever you get the time

@@ -438,9 +438,15 @@ async def validate_sql(self, db_name, query):
# return False

class sqlite_database(Database):
def __init__(self):
self.temp_db_folder = "temporary_db"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont call the folder as temporary_db.
Make the directory like this.
There is a folder called files at the root where we store all the sql files. I would suggest create a fodler sqlite_db inside the files folder and then save the db files in that fodler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def __init__(self):
self.temp_db_folder = "temporary_db"
if not os.path.exists(self.temp_db_folder):
os.makedirs(self.temp_db_folder)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont use temp_db_folder as variable name. Give it a more descriptive name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

async def get_connection(self):
try:
con = sqlite3.connect("temp.db")
db_file_path = os.path.join(self.temp_db_folder, "temp.db")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you are not using this function anywhere so dont use temp.db to create a connection. Dont define this function if you are not using it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed it and added a pass statement, because the function itself may be called at times, but it does not do anything, completely removing it may cause issues in app.py itself.

@@ -488,7 +496,8 @@ async def create_schema_in_db(self, db_name, schema):

async def get_tables_from_schema_id(self, schema_id):
try:
con = sqlite3.connect(f'{db_name}.db')
db_file_path = os.path.join(self.temp_db_folder, f'{db_name}.db')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are getting the db name as schema_id but you are using db_name as the file name. Change it schema_id

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -500,7 +509,8 @@ async def get_tables_from_schema_id(self, schema_id):

async def get_table_info(self, db_name, table_name):
try:
con = sqlite3.connect(f'{db_name}.db')
db_file_path = os.path.join(self.temp_db_folder, f'{db_name}.db')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a more descriptive name for temp_db_folder variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to sqlite_db_folder

@suyashgautam
Copy link
Collaborator

Merge this code as part of #53 Hence closing this ticket

@suyashgautam
Copy link
Collaborator

Merge this code as part of #53 Hence closing this ticket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants