Created
December 28, 2024 00:03
-
-
Save pydanny/2775077afeab5d43657b2c1950065f18 to your computer and use it in GitHub Desktop.
fasthtml/check-bools.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": true | |
}, | |
"id": "bc97a990", | |
"cell_type": "code", | |
"source": "from fasthtml.common import *", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "47cdd7a0", | |
"cell_type": "code", | |
"source": "# Debug wrapper\ndef debug_fast_app(*args, **kwargs):\n print(\"\\nDebugging table schemas:\")\n for k, v in kwargs.items():\n if isinstance(v, dict) and 'pk' in v: # This identifies our table schemas\n print(f\"\\n{k} schema:\")\n for field, type_ in v.items():\n print(f\" {field}: {type_} ({type(type_)})\")\n \n result = fast_app(*args, **kwargs)\n return result", | |
"execution_count": 2, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "a253f3e1", | |
"cell_type": "code", | |
"source": "app, rt, tasks, Task = debug_fast_app(\n \"data/data.db\",\n live=True,\n task={\n \"id\": int,\n \"title\": str,\n \"done\": bool,\n \"priority\": int,\n \"profile_id\": int,\n \"pk\": \"id\"\n }\n)\n\n", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "\nDebugging table schemas:\n\ntask schema:\n id: <class 'int'> (<class 'type'>)\n title: <class 'str'> (<class 'type'>)\n done: <class 'bool'> (<class 'type'>)\n priority: <class 'int'> (<class 'type'>)\n profile_id: <class 'int'> (<class 'type'>)\n pk: id (<class 'str'>)\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "1c685c97", | |
"cell_type": "code", | |
"source": "Task", | |
"execution_count": 5, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 5, | |
"data": { | |
"text/plain": "fastlite.core.Task" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "7c6b4dc5", | |
"cell_type": "code", | |
"source": "tasks", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 6, | |
"data": { | |
"text/plain": "<Table task (id, title, done, priority, profile_id)>" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "ac9b1c47", | |
"cell_type": "code", | |
"source": "task = tasks.insert(\n Task(\n id=1,\n title='Test bools',\n done=False,\n priority=3,\n profile_id=1\n )\n)", | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "5e562b27", | |
"cell_type": "code", | |
"source": "task", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 9, | |
"data": { | |
"text/plain": "Task(id=1, title='Test bools', done=0, priority=3, profile_id=1)" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "4620d8d3", | |
"cell_type": "code", | |
"source": "task.done", | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 10, | |
"data": { | |
"text/plain": "0" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "d11d084e", | |
"cell_type": "code", | |
"source": "bool(task.done)", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"execution_count": 11, | |
"data": { | |
"text/plain": "False" | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"id": "cf0bbcd5", | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.12.6", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "2c7f6349f0e2f9988d7c4be69b1da2a6", | |
"data": { | |
"description": "fasthtml/check-bools.ipynb", | |
"public": false | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/pydanny/2c7f6349f0e2f9988d7c4be69b1da2a6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment