Skip to content

Releases: trialandsuccess/TypeDAL

Typedal v3.8 – New Custom Fields and Enhanced Typing

11 Oct 19:11
94283ae
Compare
Choose a tag to compare

Release v3.8 - TypeDAL

We are excited to announce the release of TypeDAL v3.8! This update introduces some useful new features and enhancements, focusing on improving type handling and usability for developers. ✨

What's New in v3.8.0

1. Custom TypedFields for timestamp, point, and uuid

We’ve added new custom TypedFields for timestamp, point, and uuid. These new types provide better integration with PostgreSQL and enhanced usability:

  • Timestamp: Offers millisecond precision, unlike the standard datetime type.
  • UUID: Automatically converts values into uuid.UUID instances when received from the database. 🔗
  • Point: Maps directly to the point type in PostgreSQL, providing specific functionality for geometric data. 📐
from typedal.fields import TimestampField, PointField, UUIDField
@db.define()
class MyTable(typedal.TypedTable):
   ts = TimestampField() # ts will be `datetime.datetime` in Python and `timestamp` in the database
   pt = PointField() # pt will be `tuple[float, float]` in Python and `point` in the database
   gid = UUIDField() # gid will be `uuid.UUID` in Python and `uuid` in the database

2. New _sql() Function in TypedTable

This minor but handy addition allows you to quickly generate SQL CREATE TABLE statements directly from a TypedTable class, provided that the migration extra or pydal2sql package is installed. ⚙️

>>> MyTable._sql()
CREATE TABLE "my_table"(
    "id" INTEGER PRIMARY KEY AUTOINCREMENT,
    "ts" timestamp NOT NULL,
    "pt" point NOT NULL,
    "gid" uuid NOT NULL
);

3. Improved FieldSettings Typing

We've introduced a FieldSettings typed dict to provide better hinting when creating fields using TypedField() or any fields derived from it. This change enhances the developer experience by making the code more readable and helping with IDE suggestions. 🤓
image
VSCode

image
PyCharm

4. Python 3.13 Compatibility

We’ve prepared for Python 3.13 by addressing changes in forward reference evaluation and the removal of the cgi module. However, please note that currently (as of October 11, 2024), there is no build for psycopg2-binary compatible with Python 3.13. Users relying on PostgreSQL may encounter issues until a compatible build is available. ⚠️

Highlights from Earlier Versions (3.2.0 to 3.7.0)

Enhanced Migration Support (v3.6.0)

We introduced the typedal migrations.stub feature in version 3.6.0, enabling users to generate stub migrations using the pydal2sql package. While this is a niche feature, it's a powerful tool for those who need migration support. 📝

Improved Callback Hooks (v3.5.0)

Version 3.5.0 included enhancements to callback hooks, adding support for before_ and after_ triggers on insert, update, and delete operations. 🔁

get_db, get_table, and get_field Helpers (v3.7.0)

These helper functions were added to simplify retrieving pydal objects, streamlining the process of interacting with Typedal-managed databases. 🔧

TypeDAL 3.1

16 Apr 19:42
44bce94
Compare
Choose a tag to compare

TypeDAL 3.1 Release - Introducing Mixins 🥣!

We're thrilled to announce the release of TypeDAL 3.1, packed with a powerful new feature: Mixins. 🎉

Mixins Overview

Mixins in TypeDAL enable you to encapsulate reusable fields and behaviors, enhancing the flexibility and modularity of your database models.

🔗 Learn more about Mixins

Key Highlights

This update ships with two example mixins:

  • TimestampsMixin: Automate timestamp management with created_at and updated_at fields.
  • SlugMixin: Generate SEO-friendly slugs for your models, effortlessly.

Example Usage:

from typedal import TypeDAL, TypedTable
from typedal.mixins import TimestampsMixin

class MyTable(TypedTable, TimestampsMixin):
    # Define your table fields here
    pass
from typedal import TypeDAL, TypedTable
from typedal.mixins import SlugMixin

class MyTable(TypedTable, SlugMixin, slug_field="title"):
    title: str
    # Define other fields here

Creating Custom Mixins:

  • Define your own mixins to tailor functionality according to your app's requirements.
  • Enjoy seamless integration with your models, promoting code reuse and maintainability.
from typedal import TypeDAL, TypedTable
from typedal.mixins import Mixin

# Define your custom mixin
class HasImageMixin(Mixin):
    # Define your mixin fields and methods here

# Integrate custom mixin into your table definitions
class Article(TypedTable, HasImageMixin):
    # Define other fields here

Upgrade to TypeDAL 3.1 today and unlock the power of Mixins in your database modeling journey! 🚀

TypeDAL 2.1

02 Nov 15:18
2ecee70
Compare
Choose a tag to compare

TypeDAL Version 2.1.0 Release (2023-11-02)

New Features

Improved Query Builder with .cache() Functionality

The query builder now supports caching, thanks to the new .cache() feature. This empowers you to optimize query performance by storing query results (TypedRows with model instances) for later use, reducing the load on your database.

  • With the ability to set Time-to-Live (TTL) or specify an expiration datetime for cached data, you gain greater control over cache management. This ensures that your application always uses fresh data when necessary.

  • The caching mechanism includes automatic cache invalidation with dependency tracking. When related data changes, the cache updates accordingly, ensuring that your application remains consistent with the underlying database.

  • You can mark specific tables as "not a caching dependency" by using db.define(cache_dependency=False). This allows you to fine-tune which tables should participate in the caching process.

py4web Integration: AuthUser Class

This release also introduces the AuthUser class, which can be used as the typed model on top of db.auth_user.

TypeDAL 2.0.0

01 Nov 12:11
fa7d483
Compare
Choose a tag to compare

TypeDAL 2.0.0 Release Announcement

We are thrilled to announce the release of TypeDAL version 2.0.0! This release brings significant enhancements and new features to TypeDAL, making working with databases even more intuitive and efficient. Here's a glimpse of what's new in this version:

ORM Features

Query Builder

In TypeDAL 2.0.0, we introduce a powerful Query Builder that simplifies the process of constructing database queries. Compared to pydal, the Query Builder uses a more modern and intuitive syntax that follows the builder pattern. You can easily chain .where, .select, and .join clauses to create complex queries. Additionally, we've added features like pagination and chunking to make working with databases even more convenient.

One major improvement is that using the Query Builder will no longer return a generic Row object but an actual instance of your model class. This change provides a more seamless and type-safe experience when working with your data.

# from pydal

db(db.person.id > 5).select(db.person.id, db.person.name, limitby=(0, 5))

# to typedal 2.0

Person.where(Person.id > 5).select(Person.id, Person.name).paginate(limit=5)

TypedField

TypeDAL now supports improved type hinting with the introduction of TypedField. You can enhance your table definition classes with TypedField[...], which doesn't affect the runtime behavior but greatly improves support for mypy, type checking, and IDE integration. Here's an example of the change:

# pydal
Person = db.define_table("person", Field("name"))

# typedal 1.0
@db.define
class Person(TypedTable):
    name: str

# typedal 2.0
@db.define
class Person(TypedTable):
    name: TypedField[str]

This enhancement allows your editor to recognize that Person.name is not just a string but a Field, providing better type-awareness and offering additional properties like .belongs. When you work with an actual Person row, the editor knows that 'name' is now a string.

Relationships

With TypeDAL 2.0.0, you can now define relationships between tables, enabling the use of the .join method to automatically load related model data into the right properties. This feature simplifies working with complex data models and enhances the overall clarity of your code.

@db.define
class Author(TypedTable):
    name: str
    # define relationship:
    articles = relationship(list["Article"], lambda self, other: other.author == self.id)

@db.define
class Article(TypedTable):
    title: str
    author: Author # Relationship via reference

# get one author with all their articles:
author_with_articles = Author.join("articles").first() # -> instance of Author
# author_with_articles.articles is now a list[Article]

# get one article with its author:
article_with_author = Article.join("author").first() # -> instance of Article
# article_with_author.author is now an Author instance

Upgrading to 2.0

Since all new features should be backwards compatible, installing 2.0.0 in your older project or even a pydal project should still just work. You can incrementally upgrade parts of your program to the new syntax.
An example order of steps could be:

  1. replace db = DAL(...) with db = TypeDAL(...)
  2. replace your pydal db.define_table definitions with TypeDAL classes
  3. Replace simple annotations (: str) with improved annotations (: TypedField[str])
  4. replace pydal queries with the TypeDAL Query builder

See the docs for more information and examples.