Skip to content

Commit

Permalink
extend example
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Sep 19, 2024
1 parent 85d5446 commit 5e96dc0
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions database-example/UseDatabase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,115 @@
"# You can also view individual tables\n",
"db.connection.table(\"Publication\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "f8cad996-655f-46c3-b95e-2dc343e27717",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">✅ Inserted <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span> rows into the database.\n",
"</pre>\n"
],
"text/plain": [
"✅ Inserted \u001b[1;36m1\u001b[0m rows into the database.\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
],
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"┏━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
"\u001b[1m \u001b[0m\u001b[1mname\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1maffiliation\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1memail\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1morcid\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mid\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\n",
"┡━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
"\u001b[2m!string\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2m!string\u001b[0m │\n",
"├────────────┼─────────────┼────────┼────────┼──────────────────────────────────────┤\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m00594dae-d6e0-4b6e-812f-0b994359f4af\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m1c60c513-a4e8-49c3-beb5-a07fa5022574\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m261012b1-446d-48da-8d70-8225256a497b\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m33cce500-64de-4e8a-b64d-3f78c30a8367\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m3e28623f-c5e7-4887-8025-bcd8f21afd29\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m4362f522-28ad-4a73-95a8-171f24f2c4b3\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m461f8c9d-8a75-4cd0-9f9c-2d8ab3414872\u001b[0m │\n",
"\u001b[32mJohn Doe \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m58c672ad-962e-45df-b820-e384003455b7\u001b[0m │\n",
"\u001b[32mStrendaMan\u001b[0m │ \u001b[32mStrenda \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m5b0931b8-cb72-4c7d-bc49-4d1fee79d551\u001b[0m │\n",
"\u001b[32mJohn Doe \u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m5e407774-8196-4800-bb5f-ea9e1633c85e\u001b[0m │\n",
"\u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │ \u001b[2m…\u001b[0m │\n",
"└────────────┴─────────────┴────────┴────────┴──────────────────────────────────────┘\n"
]
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Looking for John Doe\n",
"</pre>\n"
],
"text/plain": [
"Looking for John Doe\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
"┃<span style=\"font-weight: bold\"> name </span>┃<span style=\"font-weight: bold\"> affiliation </span>┃<span style=\"font-weight: bold\"> email </span>┃<span style=\"font-weight: bold\"> orcid </span>┃<span style=\"font-weight: bold\"> id </span>┃\n",
"┡━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
"│ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">!string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">string</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">!string</span> │\n",
"├──────────┼─────────────┼────────┼────────┼──────────────────────────────────────┤\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">John Doe</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">58c672ad-962e-45df-b820-e384003455b7</span> │\n",
"│ <span style=\"color: #008000; text-decoration-color: #008000\">John Doe</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">NULL</span> │ <span style=\"color: #008000; text-decoration-color: #008000\">5e407774-8196-4800-bb5f-ea9e1633c85e</span> │\n",
"└──────────┴─────────────┴────────┴────────┴──────────────────────────────────────┘\n",
"</pre>\n"
],
"text/plain": [
"┏━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
"\u001b[1m \u001b[0m\u001b[1mname\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1maffiliation\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1memail\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1morcid\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mid\u001b[0m\u001b[1m \u001b[0m\u001b[1m \u001b[0m┃\n",
"┡━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
"\u001b[2m!string\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2mstring\u001b[0m │ \u001b[2m!string\u001b[0m │\n",
"├──────────┼─────────────┼────────┼────────┼──────────────────────────────────────┤\n",
"\u001b[32mJohn Doe\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m58c672ad-962e-45df-b820-e384003455b7\u001b[0m │\n",
"\u001b[32mJohn Doe\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[2mNULL\u001b[0m │ \u001b[32m5e407774-8196-4800-bb5f-ea9e1633c85e\u001b[0m │\n",
"└──────────┴─────────────┴────────┴────────┴──────────────────────────────────────┘"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Suppose, we only want to add an author. You can proceed in the same way as above.\n",
"Author = db.get_table_api(\"Author\")\n",
"author1 = Author(name=\"John Doe\")\n",
"\n",
"# Add and lets check the table\n",
"db.insert(author1)\n",
"table = db.connection.table(\"Author\")\n",
"print(table)\n",
"\n",
"# We can also filter the table\n",
"rich.print(\"Looking for John Doe\")\n",
"table[table.name == \"John Doe\"]"
]
}
],
"metadata": {
Expand Down

0 comments on commit 5e96dc0

Please sign in to comment.