Skip to content

Commit 5d674d3

Browse files
committed
Fix data saving issues with SQLAlchemy models
1 parent 48368c7 commit 5d674d3

File tree

1 file changed

+19
-36
lines changed

1 file changed

+19
-36
lines changed

languages/python/jupyter_notebook/CipherStash-Getting-Started.ipynb

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
"In order to encrypt and store plaintext values, CipherStash Proxy requires encrypted columns in its specific format.\n",
412412
"In Python, this conversion is done by creating an object of `CsText` as:\n",
413413
"```\n",
414-
"txt = CsText(\"hell, world\", \"examples\", \"encrypted_utf8_str\")\n",
414+
"txt = CsText(\"hello, world\", \"examples\", \"encrypted_utf8_str\")\n",
415415
"txt.to_db_format()\n",
416416
"```\n",
417417
"\n",
@@ -863,55 +863,38 @@
863863
"\n",
864864
"BaseModel.metadata.create_all(engine) # Create table for models if it's not created yetbelow and\n",
865865
"\n",
866-
"session.query(Example).delete() # Clear data if there is any from previous runs\n",
867-
"ex = Example(e_utf8_str = \"example record 1\", e_jsonb = json.dumps({'a': {'b': 1}}), e_int = 42, e_float = 3.14, e_date = date.today(), e_bool=False)\n",
866+
"# Clear data if there is any from previous runs\n",
867+
"session.query(Example).delete()\n",
868868
"\n",
869+
"ex = Example(e_utf8_str = \"example record 1\", e_jsonb = json.dumps({'a': {'b': 1}}), e_int = 42, e_float = 3.14, e_date = date.today(), e_bool=False)\n",
869870
"session.add(ex)\n",
870871
"session.commit()\n",
871872
"\n",
872873
"ex = Example(e_utf8_str = \"example record 2\", e_jsonb = json.dumps({'a': {'c': 2}}), e_int = 43, e_float = 1.41, e_date = date.today(), e_bool=True)\n",
873874
"session.add(ex)\n",
874875
"session.commit()\n",
875876
"\n",
876-
"ex3 = Example(e_utf8_str = \"example record 1\", e_jsonb = json.dumps({'a': {'b': 1}}), e_int = 44, e_float = 2.718, e_date = date.today(), e_bool=True)\n",
877+
"ex = Example(e_utf8_str = \"example record 3\", e_jsonb = json.dumps({'a': {'b': 1}}), e_int = 44, e_float = 2.718, e_date = date.today(), e_bool=True)\n",
877878
"session.add(ex)\n",
878879
"session.commit()\n",
879880
"\n",
880-
"'''\n",
881-
"ex1 = Example(\n",
882-
" e_utf8_str = \"example record 1\",\n",
883-
" e_jsonb = json.dumps({'a': {'b': 1}}),\n",
884-
" e_int = 42,\n",
885-
" e_float = 3.14,\n",
886-
" e_date = date.today(),\n",
887-
" e_bool=False)\n",
888-
"\n",
889-
"ex2 = Example(\n",
890-
" e_utf8_str = \"example record 2\",\n",
891-
" e_jsonb = json.dumps({'a': {'c': 2}}),\n",
892-
" e_int = 44,\n",
893-
" e_float = 1.41,\n",
894-
" e_date = date.today(),\n",
895-
" e_bool=True)\n",
896-
"\n",
897-
"ex3 = Example(\n",
898-
" e_utf8_str = \"example record 1\",\n",
899-
" e_jsonb = json.dumps({'a': {'b': 1}}),\n",
900-
" e_int = 44,\n",
901-
" e_float = 2.718,\n",
902-
" e_date = date.today(),\n",
903-
" e_bool=True)\n",
904-
"\n",
905-
"session.add(ex1)\n",
906-
"session.add(ex2)\n",
907-
"session.add(ex3)\n",
908-
"session.commit()\n",
909-
"'''\n",
910-
"# After the commit above, the records are visible outside of this session\n",
911-
"\n",
912881
"print(\"Example data creation done\")"
913882
]
914883
},
884+
{
885+
"cell_type": "markdown",
886+
"id": "a002b3d7-7889-4286-a80a-278a13196503",
887+
"metadata": {},
888+
"source": [
889+
"With the above code, records are created as in the following table:\n",
890+
"\n",
891+
"| encrypted_utf8_str | encrypted_jsonb | encrypted_int | encrypted_float | encrypted_date | encrypted_boolean |\n",
892+
"|--------------------|-----------------|---------------|-----------------|----------------|-------------------|\n",
893+
"| example record 1 | {\"a\": {\"b\": 1}} | 42 | 3.14 | 2024-10-25 | False |\n",
894+
"| example record 2 | {\"a\": {\"c\": 2}} | 43 | 1.41 | 2024-10-26 | True |\n",
895+
"| example record 3 | {\"a\": {\"b\": 1}} | 44 | 2.718 | 2024-10-27 | True |"
896+
]
897+
},
915898
{
916899
"cell_type": "markdown",
917900
"id": "97e4fea0-74e5-4f16-9040-1eecbefe5c14",

0 commit comments

Comments
 (0)