Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
added caching to build sqlite3 connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Toan Quach authored and Toan Quach committed Nov 15, 2023
1 parent c583914 commit c9387fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/taipy/core/_repository/db/_sql_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,9 @@ def _build_connection() -> Connection:
except KeyError:
raise MissingRequiredProperty("Missing property db_location")

connection = sqlite3.connect(db_location, check_same_thread=False)
return connection
return __build_connection(db_location)


@lru_cache
def __build_connection(db_location: str):
return sqlite3.connect(db_location, check_same_thread=False)
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ def init_sql_repo(tmp_sqlite):
Config.configure_core(repository_type="sql", repository_properties={"db_location": tmp_sqlite})

# Clean SQLite database
_SQLConnection._connection = None
if _SQLConnection._connection:
_SQLConnection._connection.close()
_SQLConnection._connection = None
connection = _SQLConnection.init_db()
connection.execute(str(DropTable(_CycleModel.__table__, if_exists=True).compile(dialect=sqlite.dialect())))
connection.execute(str(DropTable(_DataNodeModel.__table__, if_exists=True).compile(dialect=sqlite.dialect())))
Expand Down

0 comments on commit c9387fb

Please sign in to comment.