Skip to content

Migrate LocalDB to use SQLite database#502

Open
paman7647 wants to merge 1 commit intoTeamUltroid:mainfrom
paman7647:patch-3
Open

Migrate LocalDB to use SQLite database#502
paman7647 wants to merge 1 commit intoTeamUltroid:mainfrom
paman7647:patch-3

Conversation

@paman7647
Copy link
Copy Markdown

Migrate LocalDB to use SQLite instead of localdb. Added methods for database operations and performance optimizations.

Migrate LocalDB to use SQLite instead of localdb. Added methods for database operations and performance optimizations.
Copilot AI review requested due to automatic review settings April 7, 2026 16:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the fallback “LocalDB” implementation from the third-party localdb JSON-based storage to a SQLite-backed store, keeping the same high-level get/set/delete behavior when no Redis/Mongo/Postgres backend is configured.

Changes:

  • Replaced localdb dependency/installer path with a SQLite-based local database implementation.
  • Added SQLite schema initialization and basic CRUD operations for LocalDB.
  • Updated the fallback log message to indicate SQLite is used.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +301 to +306
self.conn = sqlite3.connect(db_name, check_same_thread=False)
self.cursor = self.conn.cursor()

# Performance tweaks
self.cursor.execute("PRAGMA journal_mode=WAL;")
self.cursor.execute("PRAGMA synchronous=NORMAL;")
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

sqlite3.connect(..., check_same_thread=False) allows cross-thread access, but the class shares a single connection + cursor without any locking. Since udB is used inside run_async functions (ThreadPoolExecutor), concurrent calls can lead to sqlite3.ProgrammingError (recursive cursor use) or data corruption. Consider either (a) adding a threading.Lock/RLock and serializing all DB operations, and/or (b) not storing a shared self.cursor and instead using self.conn.execute(...) (creating a fresh cursor per call).

Copilot uses AI. Check for mistakes.
else:
LOGS.critical(
"No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using local file as database."
"No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database."
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

Typo in log message: "fullfilled" should be "fulfilled".

Suggested change
"No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database."
"No DB requirement fulfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database."

Copilot uses AI. Check for mistakes.
@JefersonProjectRandom
Copy link
Copy Markdown

@paman7647 lol

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.

3 participants