v2.0.0
===
Dataloom 2.0.0
Release Notes - dataloom
We have release the new dataloom
Version 2.0.0
(2024-02-21
)
Features
-
Renaming the class
Dataloom
toLoom
.from dataloom import Loom
-
Eager data fetching in relationships
- Now you can fetch your child relationship together in your query
user = mysql_loom.find_one( instance=User, filters=[Filter(column="id", value=userId)], include=[Include(model=Profile, select=["id", "avatar"], has="one")], ) print(user)
- You can apply limits, offsets, filters and orders to your child associations during queries
post = mysql_loom.find_one( instance=Post, filters=[Filter(column="userId", value=userId)], select=["title", "id"], include=[ Include( model=User, select=["id", "username"], has="one", include=[Include(model=Profile, select=["avatar", "id"], has="one")], ), Include( model=Category, select=["id", "type"], has="many", order=[Order(column="id", order="DESC")], limit=2, ), ], )
-
Now
return_dict
has bee removed as an option indataloom
in the query functions likefind_by_pk
,find_one
,find_many
andfind_all
now works starting from this version. If you enjoy working with python objects you have to maneuver them manually using experimental features.from dataloom.decorators import initialize @initialize(repr=True, to_dict=True, init=True, repr_identifier="id") class Profile(Model): __tablename__: Optional[TableColumn] = TableColumn(name="profiles") id = PrimaryKeyColumn(type="int", auto_increment=True) avatar = Column(type="text", nullable=False) userId = ForeignKeyColumn( User, maps_to="1-1", type="int", required=True, onDelete="CASCADE", onUpdate="CASCADE", ) # now you can do this profile = mysql_loom.find_many( instance=Profile, ) print([Profile(**p) for p in profile]) # ? = [<Profile:id=1>] print([Profile(**p) for p in profile][0].id) # ? = 1
- These are
experimental
decorators they are little bit slow and they work perfect in a single instance, you can not nest relationships on them. - You can use them if you know how your data is structured and also if you know how to manipulate dictionaries
- These are
-
Deprecated
to the use ofjoin_next_filter_with
join_next_with
-
Values that was required as
list
e.g,select
,include
etc can now be passed as a single value.- Before
res = mysql_loom.find_by_pk(Profile, pk=profileId, select={"id", "avatar"}) # invalid res = mysql_loom.find_by_pk(Profile, pk=profileId, select=("id", "avatar")) # invalid res = mysql_loom.find_by_pk(Profile, pk=profileId, select="id") # invalid res = mysql_loom.find_by_pk(Profile, pk=profileId, select=["id"]) # valid
- Now
res = mysql_loom.find_by_pk(Profile, pk=profileId, select={"id", "avatar"}) # valid res = mysql_loom.find_by_pk(Profile, pk=profileId, select=("id", "avatar")) # valid res = mysql_loom.find_by_pk(Profile, pk=profileId, select="id") # valid res = mysql_loom.find_by_pk(Profile, pk=profileId, select=["id"]) # valid
-
Updated the documentation.
-
Grouping data in queries will also be part of this release, using the class
Group
andHaving
.
posts = pg_loom.find_many(
Post,
select="id",
filters=Filter(column="id", operator="gt", value=1),
group=Group(
column="id",
function="MAX",
having=Having(column="id", operator="in", value=(2, 3, 4)),
return_aggregation_column=True,
),
)