-
Notifications
You must be signed in to change notification settings - Fork 11
Improvement of db_helper for sqlite support #52
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
Conversation
@suyashgautam kindly review the changes whenever you get the time |
src/server/db/db_helper.py
Outdated
@@ -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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/server/db/db_helper.py
Outdated
def __init__(self): | ||
self.temp_db_folder = "temporary_db" | ||
if not os.path.exists(self.temp_db_folder): | ||
os.makedirs(self.temp_db_folder) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/server/db/db_helper.py
Outdated
async def get_connection(self): | ||
try: | ||
con = sqlite3.connect("temp.db") | ||
db_file_path = os.path.join(self.temp_db_folder, "temp.db") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/server/db/db_helper.py
Outdated
@@ -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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/server/db/db_helper.py
Outdated
@@ -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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Merge this code as part of #53 Hence closing this ticket |
Merge this code as part of #53 Hence closing this ticket |
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.