Skip to main content

A comprehensive data access layer for Vortex apps

Project description

LDC Vortex Data Layer

A comprehensive data access layer for Vortex Django applications, providing database operations, Redis caching, entity mappers, and business flow operations.

Features

Module Description
Base Layer Database connection management, query execution, transaction handling
Entity Mappers Data mappers for loans, investments, wallets, accounts, lenders, etc.
Flow Operations Business logic flows (redemption, repayment, portfolio, dashboard)
Redis Integration Unified caching layer with type-safe get/set operations
Cache Manager High-level caching patterns with fallback to database
Constants Centralized constants for transaction types, statuses, filters
Helpers Date utilities, generic utilities, master account caching

Installation

pip install LDC_Vortex-Datalayer

Requirements

  • Python 3.10+
  • Django 5.2+
  • PostgreSQL (with psycopg 3.x)
  • Redis 5.0+

Quick Start

Django Settings Configuration

# Database Configuration
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'vortex_db',
        'USER': 'your_user',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

# Redis Configuration
IOS_REDIS_CACHE = "redis://localhost:6379/0"

Using Base Data Layer

from vortex_datalayer.base_layer import BaseDataLayer

class UserRepository(BaseDataLayer):
    def __init__(self):
        super().__init__(db_alias="default")
    
    def get_user_by_id(self, user_id: int) -> dict:
        sql = "SELECT * FROM users WHERE id = %s"
        return self.execute_fetch_one(sql, params=[user_id])
    
    def get_active_users(self) -> list:
        sql = "SELECT * FROM users WHERE status = 'ACTIVE'"
        return self.execute_fetch_all(sql)

Using Redis Utilities

from vortex_datalayer import redis_utils

# Get with automatic type conversion
user = redis_utils.get("user:123", dict)      # Returns dict or None
count = redis_utils.get("counter", int)        # Returns int or None
name = redis_utils.get("name", str)            # Returns str or None
data = redis_utils.get("key")                  # Returns raw bytes (backward compatible)

# Set with automatic serialization
redis_utils.set("user:123", {"name": "John", "age": 30}, ttl=3600)
redis_utils.set("counter", 42, ttl=1800)

# Other operations
redis_utils.delete("user:123")
redis_utils.exists("user:123")
redis_utils.keys("user:*")

Using Cache Manager

from vortex_datalayer.cache_manager import CacheManager

# Get or set pattern with database fallback
result = CacheManager.get_or_set(
    cache_identifier="user_123",
    db_callback=lambda: fetch_user_from_db(123),
    cache_key_prefix="USER_DATA",
    ttl=1800,
    return_type=dict
)

# Invalidate cache
CacheManager.invalidate("user_123", cache_key_prefix="USER_DATA")

Using Constants

from vortex_datalayer.constants import TransactionStatus, LoanStatus, WalletTransactionType

if transaction.status == TransactionStatus.SUCCESS:
    print("Transaction completed")

if loan.status == LoanStatus.FUNDED:
    process_funded_loan(loan)

Using Entity Mappers

from vortex_datalayer.entity.loan import Loan
from vortex_datalayer.entity.wallet_transaction import WalletTransaction

# Loan operations
loan_repo = Loan()
loan_details = loan_repo.get_loan_by_id(loan_id)

# Wallet transactions
wallet_repo = WalletTransaction()
transactions = wallet_repo.get_transaction_list(lender_id, filters)

Package Structure

vortex_datalayer/
├── base_layer.py          # Base database operations
├── redis_utils.py         # Redis connection and operations
├── cache_manager.py       # High-level caching patterns
├── constants.py           # Centralized constants
├── entity/                # Data mappers
│   ├── loan.py
│   ├── wallet_transaction.py
│   ├── lender.py
│   └── ...
├── flow/                  # Business logic flows
│   ├── redemption_processing.py
│   ├── repayment_consumption.py
│   ├── cp_dashboard_summary.py
│   └── ...
├── helper/                # Utility helpers
│   ├── date_utils.py
│   ├── generic_utils.py
│   └── master_account_helper.py
├── ddl/                   # Database DDL scripts
├── job_mappers/           # Job-specific mappers
└── stored_procedures/     # PostgreSQL stored procedures

Deploying to PyPI

Build and Upload

# Install build tools
pip install build twine

# Clean and build
rm -rf build/ dist/ *.egg-info/
python -m build

# Upload to PyPI
twine upload dist/*

Version Management

Update version in setup.py:

version = "0.0.2"

License

Proprietary - LenDenClub Internal Use Only

Author

Sonu Sharma - sonu.sharma@lendenclub.com

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ldc_vortex_datalayer-0.0.3.tar.gz (114.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ldc_vortex_datalayer-0.0.3-py3-none-any.whl (159.2 kB view details)

Uploaded Python 3

File details

Details for the file ldc_vortex_datalayer-0.0.3.tar.gz.

File metadata

  • Download URL: ldc_vortex_datalayer-0.0.3.tar.gz
  • Upload date:
  • Size: 114.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for ldc_vortex_datalayer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 55ee49645c68508790662f5d3986553a09749021e7035d55967e1f861ae89b04
MD5 b5af7e03fafd233281891dcc79fd410a
BLAKE2b-256 6e3516eac99fd226839f3d7fd6b3127e1d8f3627bc13d74908b88c27aa1af2cf

See more details on using hashes here.

File details

Details for the file ldc_vortex_datalayer-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ldc_vortex_datalayer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 751a70ba33c53ccf06f841761e3b6cde3869761af4c6498f8b734561fd1810b1
MD5 41bb3bdb4ad40dbcacaab930e6f02e80
BLAKE2b-256 32652f475cc18112b5fa4042e8a00c5e4bfe822710e0b0c6bd31b9fc7b7496df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page