Skip to content

Changelog

Aqui estΓ‘ a traduΓ§Γ£o fiel e natural para o inglΓͺs do seu changelog:


πŸ“ Changelog – April 2025 Updates


πŸ”₯ QuerySet.py β€” New Enhancements and Methods

🧠 Improvements to Existing Functions

  • join(...) now supports special types like LEFT ANTI and RIGHT ANTI.
  • Supports both positional and named JOIN type arguments.
  • filter(...) now accepts free expressions, lists, and dictionaries.
  • filter_in(...) and not_in(...) improved to support multiple formats.
  • order_by(), group_by(), and select() refined for greater flexibility without forcing prefixes.

πŸ†• New Methods in QuerySet

  • limit(), offset(), distinct(), having(), live(), count(), first()
  • show() β€” Displays results with automatic pagination.
  • pivot() β€” Generates dynamic pivot tables directly.
  • create_temp_table() β€” Creates temporary tables directly from a query.

πŸ“¦ ResultSet.py β€” Visual Improvements

  • Terminal tables with color indicators:
  • πŸ”΅ Blue: cache results.
  • 🟒 Green: live results.
  • Automatic pagination in show(page_size=50).

πŸ› οΈ Model.py β€” New Operations and Enhancements

πŸ“‹ Data Handling

  • to_dict(), to_json(), as_dict(deep=True).

πŸ”§ Validation and Hooks

  • validate(), before_add(), after_update().

πŸ—‘οΈ CRUD Operations

  • add(confirm=True), update(confirm=True), delete(confirm=True), bulk_add(confirm=True).

πŸ“š ModelMeta.py β€” Method Interception

  • QuerySet methods can now be called directly from the Model class.
  • Example: User.filter(active=True).limit(10).show().

πŸ“ˆ Expressions.py β€” Enhancements

  • col(), date(), now(), and raw() improved.
  • Expanded documentation and practical examples.

πŸ“„ Extended Documentation

  • All methods now include clear docstrings and usage examples.
  • New JOIN types explained.

🎯 Summary of New Features

Feature Description
ANTI JOINs supported left_anti, right_anti
Smarter filters Improved filter, filter_in, not_in
Direct pivot from queryset .pivot()
Temporary table creation .create_temp_table()
Required confirmation for operations confirm=True for add/update/delete
Colored and paginated result views Enhanced UX with show()
Full autocomplete support Updated .pyi file for all models

βœ… Guaranteed Backward Compatibility

All enhancements are 100% compatible with previous versions.


πŸ“ Changelog – New Modules and Features


πŸ“š registry.py – Global Model and Cache Registry

πŸ—‚οΈ Global Structure

  • _model_registry: stores all generated Model classes available for autocomplete and reuse.
  • _model_cache: maps models by (table_name, conn_id) to avoid redundant recreation.
  • _query_result_cache: in-memory cache for query results with TTL, used in QuerySet.

This module provides the foundation for features like: - Query result caching (with live() to bypass). - Automatic model reloads. - Stub generation based on dynamically loaded models.


πŸ“¦ model_cache.py – Persistent Model Caching on Disk

πŸ” Encryption and Storage

  • Implements encrypted model caching in .wbmodels/ using a Fernet key saved in .wbormkey.
  • Models are serialized with pickle, encrypted, and saved with .wbm extension.

πŸ“€ Key Functions

  • save_model_to_disk(table_name, model_cls)
  • Saves a model class as a dictionary of serializable attributes (fields and relations).
  • try_load_model_from_disk(table_name, conn)
  • Attempts to load a previously saved model, rebuilds the class using ModelMeta, and registers it.
  • generate_model_stub(output_path)
  • Automatically generates a .pyi stub file for autocomplete support in editors.

πŸ”‘ Security

  • Uses cryptography.fernet.Fernet to ensure secure caching, even if files are exposed.

🧠 expressions.py – Custom SQL Expressions

πŸ“ Declarative Expressions

  • Expression class allows for clean, safe SQL expressions:
  • Supported operators: ==, !=, >, <, >=, <=.
  • Integrates with datetime values using automatic conversion.

πŸ”§ Utility Functions for Queries

  • col(name) – builds a column-based expression.
  • date(field) – wraps a field with Informix's DATE(...).
  • now() – returns the CURRENT SQL keyword.
  • raw(expr) – inserts raw SQL directly.
  • format_informix_datetime(value) – converts datetime or str to DATETIME(...) YEAR TO SECOND, supporting ISO8601 or fallback to raw strings.

These functions are available directly via the main package __init__.py:

from wborm import col, now, raw


πŸ“ utils.py

πŸš€ New Features

  • Local model caching
  • Automatically checks for cached models using try_load_model_from_disk() before regenerating.
  • Generated models are saved using save_model_to_disk() for future reuse.

  • Global scope injection

  • Adds inject_globals=True to assign models to global variables by table name.

  • Autocomplete stub

  • Introduces generate_model_stub() to generate .pyi files post-generation for editor autocomplete.

  • Model listing

  • Adds list_models() to:

    • List all models loaded from the database (if connected).
    • List cached models from .wbmodels/ if not connected, with decryption via cryptography.fernet.
  • Batch model generation

  • Adds generate_all_models(conn) to introspect all tables (and optionally views) with verbosity control and global injection.

  • Secure model access by name

  • Adds get_model_by_name(name) for direct access from _model_registry.

  • Create temp tables from queryset

  • Adds create_temp_table_from_queryset(...) to generate TEMP TABLEs from ORM queries.

πŸ”§ Improvements

  • FK exception handling
  • Uses try/except to gracefully handle foreign key reading errors with warnings.

  • Explicit model module

  • Sets __module__ of models to "wborm.core" for accurate tracking and autocomplete support.

  • Global model registry

  • Adds _model_registry usage in addition to _model_cache for name-based lookups.

  • Improved name mapping

  • Ensures field and variable names are treated as str(col["name"]) to avoid inconsistencies.

  • Import separation

  • Clearer organization of external vs. internal imports.

πŸ—‘οΈ Removals

  • Nothing was removed. The update maintains full backward compatibility while expanding capabilities.

⚠️ Technical Notes

  • Local caching requires:
  • Access to the encryption key (get_or_create_key()).
  • Proper permissions for .wbmodels/.
  • FK introspection may silently fail for robustness, but can hide subtle bugs if not logged.

πŸ“ introspect.py

πŸš€ Robust Improvements to get_foreign_keys()

πŸ” Index-Based FK Analysis

  • Now uses sysindexes to correctly identify FK and PK columns.
  • Supports up to 16 index columns (part1 to part16), allowing composite key detection.

🧠 Semantic Accuracy Fixes

  • Replaces r.tabid = fk.tabid join with c.tabid = fk.tabid for precision.
  • Adds idx_fk.part1 IS NOT NULL AND idx_pk.part1 IS NOT NULL filter to exclude corrupted/incomplete entries.

🧹 COALESCE usage

  • Applies COALESCE(..., '') to avoid null comparison failures.

πŸ› οΈ Other Technical Adjustments

  • Improved SQL indentation.
  • Retains aliases fk, pk, fc, pc with improved index-based joins.
  • Query structure refactored for long-term maintainability and Informix-style consistency.

βœ… No Changes to introspect_table()

  • The introspect_table(...) function remains unchanged.
  • No impact on existing usage.
  • Same introspection logic.

πŸ“ query.py

πŸš€ New Features

🧠 Query Result Caching

  • Adds in-memory query result cache (_query_result_cache) with TTL (default 60s).
  • Introduces live() to disable cache per-query.
  • Reuses cached results in all() if valid.

🧾 Advanced ResultSet Class

  • New ResultSet inherits from list and adds:
  • show(tablefmt="grid"): tabulated result display with green (live) or blue (cache) borders.
  • Dynamic column detection or from select(...).
  • Auto-removal of fully empty columns.

πŸ“Š pivot(...) Function

  • Transforms results into a pivot table with indexes, columns, and values.
  • Uses tabulate, colored output, and optimized layout.

πŸ§ͺ show(...) in QuerySet

  • Shortcut to all().show(...), allowing customizable table format.

🧩 Subquery Join Support

  • join() now accepts QuerySet instances named with .as_temp_table(alias) for subquery joins.

πŸ§ͺ Chained Temp Table Creation

  • create_temp_table(...) creates a temporary table from the current query and returns its model.

πŸ”§ Enhancements

  • More flexible filter(...)
  • Accepts string expressions (filter("age > 30")) and ColumnExpr, plus safe key=value filtering.

  • Flexible join(...) ON clause

  • Supports:

    • Lists/tuples of columns β†’ a.col = b.col
    • Single column (assumes equality)
    • Full custom SQL conditions
  • Explicit instance creation

  • _create_instance_from_row(...) uses fallback to __dict__ if not in _fields.

  • select(...) now influences ResultSet rendering

  • Column order and names reflect select fields.

  • Safe escaping in count()

  • Escapes filter values to prevent SQL injection.

πŸ—‘οΈ Removals / Deprecated Items

  • preload(...) has been removed – needs reimplementation if required.
  • Heuristic FK logic in preload(...) is deprecated.
  • all() now returns ResultSet, not a simple list.

🎨 UX and Visual Enhancements

  • Uses colorama for terminal border coloring (green: live, blue: cached).
  • tabulate formatting for CLI clarity.

βš™οΈ Internals and Techniques

  • Adds sha256-based query hash keying for caching.
  • Subquery joins require .as_temp_table_alias set.
  • Fully compatible with updated generate_model() for temp tables.

πŸ“ core.py

πŸš€ New Features

🧬 Dynamic QuerySet Method Access

  • Via __getattr__ in ModelMeta metaclass:
  • Allows direct model access to QuerySet methods (e.g. User.limit(10).show()).
  • Examples: Model.join(...), Model.pivot(...) without manual binding.

πŸ“¦ Temporary Table Creation

  • New create_temp_table() method (both instance and class level):
  • Builds SQL from model fields.
  • Executes CREATE TEMP TABLE ... with visual logging.
  • Supports intermediate joins or data snapshots.

πŸ“Š Enhanced Visualization: Model.show(...)

  • Uses tabulate to show up to 50 records (default).
  • Colors borders based on model source:
  • πŸ”΅ Blue: cached
  • 🟒 Green: live/dynamic

πŸ” Pivot via Model.pivot(...)

  • Supports pivoting at model level with filters and aggfunc="count" by default.

πŸ” Relationship Overview: Model.describe_relations()

  • Displays mapped relations with destination table names.

πŸ”§ Major Improvements

  • Field introspection in ModelMeta
  • Uses str(k) for key safety and compatibility.

  • Better to_dict() handling

  • Skips private/method attributes.

  • Improved SQL generation for tables

  • Cleaner NOT NULL / PRIMARY KEY clause generation with .strip().

πŸ—‘οΈ Removals / Deprecated

  • πŸ“€ Removed instance-level show()
  • Replaced with more versatile class-level version.

  • πŸ“¦ preload() still referenced but likely obsolete (depends on removed QuerySet method).

  • May be removed in future releases.

🎨 UI/UX Enhancements

  • More readable output using colorama for relation mapping and table generation.
  • Informative messages on creation/deletion/updates.

πŸ› οΈ Structural Notes

  • lazy_property remains unchanged.
  • validate() is still required before persisting with add, bulk_add, etc.

πŸ“ __init__.py

πŸš€ New Public Exports

New helpers have been added to the public API for expressive, direct SQL construction:

πŸ“ SQL Expression Utilities

  • col – Column-based expression builder (e.g., col("age") > 18).
  • date – Converts or wraps a value as a date.
  • now – SQL CURRENT timestamp.
  • raw – Direct SQL insertion.
  • format_informix_datetime – Formats values for Informix's DATETIME ... YEAR TO SECOND.

Provided by the expressions.py module, now part of the main package.


🧭 Explicit __all__ Export

  • Adds __all__ = [...] to define what gets imported via from wborm import *.
  • Improves code clarity.
  • Controls public API surface.
  • Aids IDEs and documentation tools.

βœ… Backward Compatibility Maintained

  • All previously available elements (Model, Field, generate_model, get_model, QuerySet) are still fully supported.