v2.4.0
===
Dataloom 2.4.0
Release Notes - dataloom
We have release the new dataloom
Version 2.4.0
(2024-02-27
)
Features
-
sync
andconnect_and_sync
function can now take in a collection ofModel
or a singleModel
instance. -
Updated documentation.
-
Fixing
ForeignKeyColumn
bugs. -
Adding the
alias
as an argument toInclude
class so that developers can flexibly use their own alias for eager model inclusion rather than lettingdataloom
decide for them. -
Adding the
junction_table
as an argument to theInclude
so that we can use this table as a reference forN-N
associations. -
Introducing self relations
- now you can define self relations in
dataloom
class Employee(Model): __tablename__: TableColumn = TableColumn(name="employees") id = PrimaryKeyColumn(type="int", auto_increment=True) name = Column(type="text", nullable=False, default="Bob") supervisorId = ForeignKeyColumn( "Employee", maps_to="1-1", type="int", required=False )
- You can also do eager self relations queries
emp_and_sup = mysql_loom.find_by_pk( instance=Employee, pk=2, select=["id", "name", "supervisorId"], include=Include( model=Employee, has="one", select=["id", "name"], alias="supervisor", ), ) print(emp_and_sup) # ? = {'id': 2, 'name': 'Michael Johnson', 'supervisorId': 1, 'supervisor': {'id': 1, 'name': 'John Doe'}}
- now you can define self relations in
-
Introducing
N-N
relationship- with this version of
dataloom
n-n
relationships are now available. However you will need to define a reference table manual. We recommend you to follow our documentation to get the best out of it.
class Course(Model): __tablename__: TableColumn = TableColumn(name="courses") id = PrimaryKeyColumn(type="int", auto_increment=True) name = Column(type="text", nullable=False, default="Bob") class Student(Model): __tablename__: TableColumn = TableColumn(name="students") id = PrimaryKeyColumn(type="int", auto_increment=True) name = Column(type="text", nullable=False, default="Bob") class StudentCourses(Model): __tablename__: TableColumn = TableColumn(name="students_courses") studentId = ForeignKeyColumn(table=Student, type="int") courseId = ForeignKeyColumn(table=Course, type="int")
- you can do
eager
data fetching in this type of relationship, however you need to specify thejunction_table
. Here is an example:
english = mysql_loom.find_by_pk( Course, pk=engId, select=["id", "name"], include=Include(model=Student, junction_table=StudentCourses, has="many"), )
- with this version of
What's Changed
- Relations by @CrispenGari in #10
Full Changelog: v2.3.0...v2.4.0