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 likeLEFT ANTIandRIGHT ANTI.- Supports both positional and named JOIN type arguments.
filter(...)now accepts free expressions, lists, and dictionaries.filter_in(...)andnot_in(...)improved to support multiple formats.order_by(),group_by(), andselect()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¶
QuerySetmethods can now be called directly from theModelclass.- Example:
User.filter(active=True).limit(10).show().
π Expressions.py β Enhancements¶
col(),date(),now(), andraw()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 generatedModelclasses 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 inQuerySet.
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.wbmextension.
π€ 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
.pyistub file for autocomplete support in editors.
π Security¶
- Uses
cryptography.fernet.Fernetto ensure secure caching, even if files are exposed.
π§ expressions.py β Custom SQL Expressions¶
π Declarative Expressions¶
Expressionclass allows for clean, safe SQL expressions:- Supported operators:
==,!=,>,<,>=,<=. - Integrates with
datetimevalues using automatic conversion.
π§ Utility Functions for Queries¶
col(name)β builds a column-based expression.date(field)β wraps a field with Informix'sDATE(...).now()β returns theCURRENTSQL keyword.raw(expr)β inserts raw SQL directly.format_informix_datetime(value)β convertsdatetimeorstrtoDATETIME(...) 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=Trueto assign models to global variables by table name. -
Autocomplete stub
-
Introduces
generate_model_stub()to generate.pyifiles 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 viacryptography.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 generateTEMP TABLEs from ORM queries.
π§ Improvements¶
- FK exception handling
-
Uses
try/exceptto 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_registryusage in addition to_model_cachefor 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
sysindexesto correctly identify FK and PK columns. - Supports up to 16 index columns (
part1topart16), allowing composite key detection.
π§ Semantic Accuracy Fixes¶
- Replaces
r.tabid = fk.tabidjoin withc.tabid = fk.tabidfor precision. - Adds
idx_fk.part1 IS NOT NULL AND idx_pk.part1 IS NOT NULLfilter 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,pcwith 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 (default60s). - Introduces
live()to disable cache per-query. - Reuses cached results in
all()if valid.
π§Ύ Advanced ResultSet Class¶
- New
ResultSetinherits fromlistand 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 acceptsQuerySetinstances 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")) andColumnExpr, plus safekey=valuefiltering. -
Flexible
join(...)ON clause -
Supports:
- Lists/tuples of columns β
a.col = b.col - Single column (assumes equality)
- Full custom SQL conditions
- Lists/tuples of columns β
-
Explicit instance creation
-
_create_instance_from_row(...)uses fallback to__dict__if not in_fields. -
select(...)now influencesResultSetrendering -
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 returnsResultSet, not a simple list.
π¨ UX and Visual Enhancements¶
- Uses
coloramafor terminal border coloring (green: live, blue: cached). tabulateformatting for CLI clarity.
βοΈ Internals and Techniques¶
- Adds
sha256-based query hash keying for caching. - Subquery joins require
.as_temp_table_aliasset. - Fully compatible with updated
generate_model()for temp tables.
π core.py¶
π New Features¶
𧬠Dynamic QuerySet Method Access¶
- Via
__getattr__inModelMetametaclass: - Allows direct model access to
QuerySetmethods (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
tabulateto 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 KEYclause 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
coloramafor relation mapping and table generation. - Informative messages on creation/deletion/updates.
π οΈ Structural Notes¶
lazy_propertyremains unchanged.validate()is still required before persisting withadd,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β SQLCURRENTtimestamp.rawβ Direct SQL insertion.format_informix_datetimeβ Formats values for Informix'sDATETIME ... YEAR TO SECOND.
Provided by the
expressions.pymodule, now part of the main package.
π§ Explicit __all__ Export¶
- Adds
__all__ = [...]to define what gets imported viafrom 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.