|
411 | 411 | "In order to encrypt and store plaintext values, CipherStash Proxy requires encrypted columns in its specific format.\n",
|
412 | 412 | "In Python, this conversion is done by creating an object of `CsText` as:\n",
|
413 | 413 | "```\n",
|
414 |
| - "txt = CsText(\"hell, world\", \"examples\", \"encrypted_utf8_str\")\n", |
| 414 | + "txt = CsText(\"hello, world\", \"examples\", \"encrypted_utf8_str\")\n", |
415 | 415 | "txt.to_db_format()\n",
|
416 | 416 | "```\n",
|
417 | 417 | "\n",
|
|
863 | 863 | "\n",
|
864 | 864 | "BaseModel.metadata.create_all(engine) # Create table for models if it's not created yetbelow and\n",
|
865 | 865 | "\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", |
868 | 868 | "\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", |
869 | 870 | "session.add(ex)\n",
|
870 | 871 | "session.commit()\n",
|
871 | 872 | "\n",
|
872 | 873 | "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",
|
873 | 874 | "session.add(ex)\n",
|
874 | 875 | "session.commit()\n",
|
875 | 876 | "\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", |
877 | 878 | "session.add(ex)\n",
|
878 | 879 | "session.commit()\n",
|
879 | 880 | "\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", |
912 | 881 | "print(\"Example data creation done\")"
|
913 | 882 | ]
|
914 | 883 | },
|
| 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 | + }, |
915 | 898 | {
|
916 | 899 | "cell_type": "markdown",
|
917 | 900 | "id": "97e4fea0-74e5-4f16-9040-1eecbefe5c14",
|
|
0 commit comments