Created
September 5, 2024 06:31
-
-
Save pydanny/6a6e31552211aac6bac9fac14179ee23 to your computer and use it in GitHub Desktop.
fasthtml-pk-search.ipynb
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "from dataclasses import dataclass\n\ndb = Database(':memory:')\n\n\nclass User: username:str; pwd:str; role:str\nclass Img: id:int; username:str; mime:str; b64:str; created_at:str; score:int\nclass Comment: id:int; imgid:int; username:str; comment:str; created_at:str\n\nusers = db.create(User, pk='username', transform=True)\nimgs = db.create(Img, pk=('id', 'username'), transform=True)\ncomments = db.create(Comment, pk=('id', 'imgid', 'username'), transform=True)", | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "comments.insert(dict(id=1, imgid=1, username='user1', comment='comment1'))\ncomments.insert(dict(id=2, imgid=1, username='user1', comment='comment2'))\ncomments.insert(dict(id=3, imgid=1, username='user1', comment='comment2'))", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "Comment(id=3, imgid=1, username='user1', comment='comment2', created_at=None)" | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "comments()", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[Comment(id=1, imgid=1, username='user1', comment='comment1', created_at=None),\n Comment(id=2, imgid=1, username='user1', comment='comment2', created_at=None),\n Comment(id=3, imgid=1, username='user1', comment='comment2', created_at=None)]" | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "comments(where=\"id=1 AND imgid=1 AND username='user1'\")", | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "[Comment(id=1, imgid=1, username='user1', comment='comment1', created_at=None)]" | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.10.6", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "fasthtml-pk-search.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment