Socket
Socket
Sign inDemoInstall

sqlite-worker

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlite-worker

Thread-safe SQLite3 worker for Python


Maintainers
1

sqlite-worker

Sqlite-Worker is a Python package providing a thread-safe interface for SQLite database operations. It ensures safe concurrent access to SQLite databases and simplifies executing database queries from different threads.

Features

  • Thread-safe SQLite database operations
  • Queue-based query execution
  • Simple and easy-to-use API
  • Initialization actions executed once upon database connection
  • Regular commits for continuous query streams

Installation

To install, run:

pip3 install sqlite-worker

Creating a Worker Instance

To create a basic instance of Sqlite3Worker by specifying the path to your SQLite database file:

from sqlite_worker import SqliteWorker
worker = SqliteWorker("/path/to/your/database.db")

Worker instance with Initialization Actions

Create a SqliteWorker instance with initialization actions (such as setting pragmas):

from sqlite_worker import SqliteWorker

init_actions = [
    "PRAGMA journal_mode=WAL;",
    "PRAGMA synchronous=NORMAL;",
    "PRAGMA temp_store=MEMORY;"
]

worker = SqliteWorker("/path/to/your/database.db", execute_init=init_actions)

Worker Instance with Regular Commits

Create a SqliteWorker instance with initialization actions and set a maximum query count for regular commits:

from sqlite_worker import SqliteWorker

init_actions = [
    "PRAGMA journal_mode=WAL;",
    "PRAGMA synchronous=NORMAL;",
    "PRAGMA temp_store=MEMORY;"
]

worker = SqliteWorker("/path/to/your/database.db", execute_init=init_actions, max_count=50)

Execute Queries

Creating a table

worker.execute("CREATE TABLE example (id INTEGER PRIMARY KEY, name TEXT)")

Inserting data

worker.execute("INSERT INTO example (name) VALUES (?)", ("Alice",))

Fetching data

token = worker.execute("SELECT * FROM example")
results = worker.fetch_results(token)
print(results)

Closing the Worker

After completing all database operations, close the worker to ensure proper cleanup:

worker.close()

Contributing

Contributions to the Sqlite-Worker are welcome! Please refer to the project's issues and pull request sections for contributions.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc