The starrocks database module for LitePolis
Project description
LitePolis Database Template
This repository provides a template for creating custom database modules for the LitePolis system.
The example code within this template uses SQLModel and SQLite for demonstration purposes, replace this specific implementation with your chosen database technology (e.g., PostgreSQL, MySQL, MongoDB, Redis, etc.) and corresponding drivers or ORMs/ODMs (e.g., SQLAlchemy, Psycopg2, PyMongo, Django ORM, etc.).
Key Files/Variables to Modify
- Folder:
litepolis_database_template/(Rename this) - File:
setup.py(Updatename,version,install_requires, etc.) - File:
requirements.txt(Update dependencies) - File:
litepolis_database_template/utils.py(UpdateDEFAULT_CONFIG, connection/session logic) - File:
litepolis_database_template/Actor.py(UpdateDatabaseActorinheritance/implementation) - File:
litepolis_database_template/__init__.py(Update imports) - Files:
litepolis_database_template/Users.py,Conversations.py(Delete or replace these example files) - Folder:
tests/(Rewrite tests) - File:
README.md(Update prerequisites, add specific notes for your implementation)
Steps
Follow these steps to adapt the template:
- Clone Repository: Get a local copy of this template.
- Rename Package Folder: Rename the
litepolis_database_templatedirectory to your desired package name (e.g.,litepolis_database_mymongodb). This name should match thenameyou'll use insetup.py. - Update
setup.py: Modify thename,version,author,description,url, and especiallyinstall_requiresto reflect your project and its dependencies. - Update
requirements.txt: List your project's dependencies, including the database driver/ORM. Removesqlmodelif unused. - Install Dependencies: Create a virtual environment and install the dependencies:
python -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows pip install -r requirements.txt pip install -e . # Installs your package in editable mode
- Configure Database (
litepolis_database_template/utils.py):- Update
DEFAULT_CONFIGwith settings for your database. - Implement the database connection logic (e.g., creating a client/engine).
- Implement session/connection handling functions suitable for your database.
- Adapt the configuration loading logic if necessary.
- Update
- Define Data Models:
- Delete the example model files (
Users.py,Conversations.py). - Create new Python files for your data models/schemas using your chosen tools.
- Delete the example model files (
- Implement Database Logic:
- Create "Manager" classes for your data models, containing methods for database operations (CRUD, queries, etc.).
- Update
litepolis_database_template/Actor.py(DatabaseActor) to inherit from your new Manager classes. Remove the example inheritance.
- Update
__init__.py: Modify the imports inlitepolis_database_template/__init__.pyto expose the necessary components from your module (yourDatabaseActorandDEFAULT_CONFIGallow LitePolis to integrate your module). - Write/Update Tests (
tests/):- Delete or modify the existing test files (
test_Users.py, etc.). - Write new tests using
pytest(or your preferred framework) to cover your database logic and models. Ensure proper test database setup/teardown. - Run tests using
pytest.
- Delete or modify the existing test files (
- Document Prerequisites: Add any necessary setup instructions for your specific database to this README (e.g., "Requires a running PostgreSQL server accessible via connection string defined in config", "Ensure MongoDB is running on localhost:27017").
- Release: Once developed and tested, you can package and release your module to PyPI using tools like
buildandtwine.- Once your package is published on PyPI, LitePolis CLI will be able to download and install the package during setup of other administrators.
Global Concepts to Retain
While changing the implementation, retain these structural concepts:
- A central
DatabaseActorclass inActor.pyas the main entry point for LitePolis. - Using a configuration dictionary (
DEFAULT_CONFIGinutils.py) for database settings. - Having dedicated logic for database connection and session/client management (
utils.py). - Organizing database logic for different models into separate "Manager" classes (recommended).
- Comprehensive testing using
pytest(or equivalent) in thetests/directory. - Standard Python packaging via
setup.py.
Core Concepts
graph LR
subgraph LitePolis
A[LitePolis Core]
Aa[LitePolis Modules]
end
subgraph Your Database Module
A --> B(DatabaseActor)
Aa --> B(DatabaseActor)
B --> C[UserManager]
B --> D[ConversationManager]
end
C --> G[Your Database]
D --> G
To adapt this template, you need to understand and modify the following key components:
-
DatabaseActor(litepolis_database_template/Actor.py):- Important: This class name
DatabaseActoris the fixed entry point that LitePolis uses to interact with your database module. Do not rename this class. - This is the central class where you will implement your database logic.
- The template demonstrates a recommended pattern of using separate "Manager" classes for different data models/collections (e.g.,
UserManager,ProductManager) and havingDatabaseActorinherit from them. This inheritance pattern is just a suggestion for code organization. - Alternative Implementations: You are also free to implement
DatabaseActorin other ways, such as by having it contain instances of manager classes as attributes, or by directly implementing all database logic withinDatabaseActoritself. - Developer Manual is Key: Regardless of the implementation approach you choose, it is crucial to provide clear documentation (e.g., in a developer manual or within the code itself) for downstream API developers. This documentation should explain how to interact with your
DatabaseActorclass and its methods to perform database operations. - Replace the example
UserManagerandConversationManagerinheritance (or any other example structure) with your chosen implementation, ensuring you maintain theDatabaseActorclass name.
- Important: This class name
-
Configuration (
litepolis_database_template/utils.py):- The
DEFAULT_CONFIGdictionary provides default connection settings. You must update this with configuration keys relevant to your chosen database (e.g., connection string, host, port, username, password, database name). - The logic for retrieving the database configuration (checking
PYTEST_CURRENT_TESTenvironment variable vs. defaults) should be adapted if your testing setup or configuration management differs. - The
get_configfunction (imported fromlitepolis) is used to potentially override defaults in production.
- The
-
Database Connection & Session Management (
litepolis_database_template/utils.py):- The example functions (
connect_db,create_db_and_tables,with_session,get_session) and theenginecreation are specific to SQLModel/SQLAlchemy. - Replace this logic with the appropriate database technology and driver/ORM.
- The example functions (
-
Data Models (e.g.,
litepolis_database_template/Users.py,litepolis_database_template/Conversations.py):- These files are examples demonstrating data models and manager classes using SQLModel.
-
Package Metadata (
setup.py):- This file defines how your module is packaged. You must update:
name: A unique name for your package (e.g.,litepolis-database-mymongodb) must in patternlitepolis-database-*.version,description,author,url: Update with your details.install_requires: Crucially, list all dependencies required by your module, including the database driver (e.g.,pymongo,psycopg2-binary,redis), any ORM/ODM, and other libraries. Removesqlmodelif you are not using it.
- This file defines how your module is packaged. You must update:
-
Dependencies (
requirements.txt):- This file lists dependencies for development and testing.
-
Testing (
tests/folder):- The provided tests are specific to the SQLModel/SQLite example.
- Ensure your tests cover the methods implemented in your
DatabaseActorand Manager classes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litepolis_database_starrocks-0.0.1.tar.gz.
File metadata
- Download URL: litepolis_database_starrocks-0.0.1.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
899d24468ab8c6101419f20eb9f2b6d88aa75186152f998d97a3928804f707a8
|
|
| MD5 |
b791bbb1cda892df79a605f41d514205
|
|
| BLAKE2b-256 |
00a3f502ed8fd4474938f77dc7dc35ecb3dc3b3474cf6a4622f1f4b6c5ecf1f9
|
Provenance
The following attestation bundles were made for litepolis_database_starrocks-0.0.1.tar.gz:
Publisher:
python-publish.yml on cplkake/LitePolis-database-StarRocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litepolis_database_starrocks-0.0.1.tar.gz -
Subject digest:
899d24468ab8c6101419f20eb9f2b6d88aa75186152f998d97a3928804f707a8 - Sigstore transparency entry: 195175722
- Sigstore integration time:
-
Permalink:
cplkake/LitePolis-database-StarRocks@e32fc3f3ca08bba864c4b5dde8f56426cd053582 -
Branch / Tag:
refs/tags/v0.01 - Owner: https://github.com/cplkake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e32fc3f3ca08bba864c4b5dde8f56426cd053582 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litepolis_database_starrocks-0.0.1-py3-none-any.whl.
File metadata
- Download URL: litepolis_database_starrocks-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
538c158fb613ad586c40b074be855c9d19564a74be10083958d337dd9b4497fb
|
|
| MD5 |
5acc6aeb429ca28cda2d11ad404b1976
|
|
| BLAKE2b-256 |
08a06d72f36dcd8fd1053d16c0f51b99ca34fe398b0087461763e976fc568cd2
|
Provenance
The following attestation bundles were made for litepolis_database_starrocks-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on cplkake/LitePolis-database-StarRocks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litepolis_database_starrocks-0.0.1-py3-none-any.whl -
Subject digest:
538c158fb613ad586c40b074be855c9d19564a74be10083958d337dd9b4497fb - Sigstore transparency entry: 195175725
- Sigstore integration time:
-
Permalink:
cplkake/LitePolis-database-StarRocks@e32fc3f3ca08bba864c4b5dde8f56426cd053582 -
Branch / Tag:
refs/tags/v0.01 - Owner: https://github.com/cplkake
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e32fc3f3ca08bba864c4b5dde8f56426cd053582 -
Trigger Event:
release
-
Statement type: