-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WIP to add more ORM features (dynamic querying. some better typ…
…ing etc)
- Loading branch information
1 parent
5d85995
commit 64c9b67
Showing
4 changed files
with
113 additions
and
27 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import re | ||
import typing | ||
from sqlite3 import IntegrityError | ||
|
||
import pydal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import uuid | ||
|
||
from src.typedal import TypeDAL, TypedTable | ||
from src.typedal.fields import StringField | ||
|
||
db = TypeDAL('sqlite:memory:') | ||
|
||
|
||
@db.define | ||
class User(TypedTable): | ||
name: str | ||
gid = StringField(default=uuid.uuid4) | ||
|
||
|
||
class Post(TypedTable): | ||
title: str | ||
gid = StringField(default=uuid.uuid4) | ||
|
||
|
||
db.define(Post) | ||
|
||
|
||
@db.define() | ||
class Tag(TypedTable): | ||
slug: str | ||
gid = StringField(default=uuid.uuid4) | ||
|
||
|
||
@db.define() | ||
class Tagged(TypedTable): | ||
entity: str # uuid | ||
tag: Tag | ||
|
||
|
||
def test_orm_classes(): | ||
henkie = User.insert( | ||
name="Henkie" | ||
) | ||
|
||
ijsjes = Post.insert( | ||
title="IJsjes" | ||
) | ||
|
||
post_by_henkie = Tag.insert( | ||
slug='post-by-henkie' | ||
) | ||
|
||
melk_producten = Tag.insert( | ||
slug='melk-producten' | ||
) | ||
|
||
Tagged.insert( | ||
entity=henkie.gid, | ||
tag=post_by_henkie | ||
) | ||
|
||
Tagged.insert( | ||
entity=ijsjes.gid, | ||
tag=melk_producten | ||
) | ||
|
||
print(Tagged.select(Tagged.ALL).where(Tagged.id).first()) | ||
print(list(Tagged.where(Tagged.id).select(Tagged.ALL))) |