diff --git a/doc/tutorials/setup_db.ipynb b/doc/tutorials/setup_db.ipynb index bcf301d5..14096bba 100644 --- a/doc/tutorials/setup_db.ipynb +++ b/doc/tutorials/setup_db.ipynb @@ -14,9 +14,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "id": "d6b50070-ae30-4c1c-a56a-bd8881bba1a0", - "metadata": {}, + "metadata": { + "ExecuteTime": { + "end_time": "2023-10-30T16:19:59.735069Z", + "start_time": "2023-10-30T16:19:59.728879Z" + } + }, "outputs": [], "source": [ "# TODO: Move this to a separate configuration notebook. Here we just need to load this configuration from a store.\n", @@ -24,21 +29,21 @@ "\n", "@dataclass\n", "class SandboxConfig:\n", - " EXTERNAL_HOST_NAME = \"192.168.124.93\"\n", - " HOST_PORT = \"8888\"\n", + " EXTERNAL_HOST_NAME: str = \"192.168.124.93\"\n", + " HOST_PORT: int = 8888\n", "\n", " @property\n", " def EXTERNAL_HOST(self):\n", " return f\"\"\"{self.EXTERNAL_HOST_NAME}:{self.HOST_PORT}\"\"\"\n", "\n", - " USER = \"sys\"\n", - " PASSWORD = \"exasol\"\n", - " BUCKETFS_PORT = \"6666\"\n", - " BUCKETFS_USER = \"w\"\n", - " BUCKETFS_PASSWORD = \"write\"\n", - " BUCKETFS_USE_HTTPS = False\n", - " BUCKETFS_SERVICE = \"bfsdefault\"\n", - " BUCKETFS_BUCKET = \"default\"\n", + " USER: str = \"sys\"\n", + " PASSWORD: str = \"exasol\"\n", + " BUCKETFS_PORT: int = 6666\n", + " BUCKETFS_USER: str = \"w\"\n", + " BUCKETFS_PASSWORD: str = \"write\"\n", + " BUCKETFS_USE_HTTPS: bool = False\n", + " BUCKETFS_SERVICE: str = \"bfsdefault\"\n", + " BUCKETFS_BUCKET: str = \"default\"\n", "\n", " @property\n", " def EXTERNAL_BUCKETFS_HOST(self):\n", @@ -53,11 +58,11 @@ " # Filesystem-Path to the read-only mounted BucketFS inside the running UDF Container\n", " return f\"/buckets/{self.BUCKETFS_SERVICE}/{self.BUCKETFS_BUCKET}\"\n", "\n", - " SCRIPT_LANGUAGE_NAME = \"PYTHON3_60\"\n", - " UDF_FLAVOR = \"python3-ds-EXASOL-6.0.0\"\n", - " UDF_RELEASE= \"20190116\"\n", - " UDF_CLIENT = \"exaudfclient\" # or for newer versions of the flavor exaudfclient_py3\n", - " SCHEMA = \"IDA\"\n", + " SCRIPT_LANGUAGE_NAME: str = \"PYTHON3_60\"\n", + " UDF_FLAVOR: str = \"python3-ds-EXASOL-6.0.0\"\n", + " UDF_RELEASE: str = \"20190116\"\n", + " UDF_CLIENT: str = \"exaudfclient\" # or for newer versions of the flavor exaudfclient_py3\n", + " SCHEMA: str = \"IDA\"\n", "\n", " @property\n", " def SCRIPT_LANGUAGES(self):\n", @@ -83,41 +88,59 @@ " \"BUCKETFS_PATH\": self.BUCKETFS_PATH\n", " }\n", "\n", - "conf = SandboxConfig()" + "#conf = SandboxConfig()" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "id": "7f31ccfd-bd6d-435a-9f4c-ae2e5af04ea3", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "creates Schema in 42.64ms\n" - ] + "metadata": { + "ExecuteTime": { + "end_time": "2023-10-30T16:20:00.552424Z", + "start_time": "2023-10-30T16:20:00.540210Z" } - ], + }, + "outputs": [], "source": [ "import pyexasol\n", "from stopwatch import Stopwatch\n", - "stopwatch = Stopwatch()\n", "\n", - "with pyexasol.connect(dsn=conf.EXTERNAL_HOST, user=conf.USER, password=conf.PASSWORD, compression=True) as conn:\n", - " conn.execute(query=\"CREATE SCHEMA IF NOT EXISTS {schema!i}\", query_params=conf.params)\n", + "def setup_schema(conf: SandboxConfig):\n", + " stopwatch = Stopwatch()\n", "\n", - "print(f\"creates Schema in {stopwatch}\")" + " with pyexasol.connect(dsn=conf.EXTERNAL_HOST, user=conf.USER, password=conf.PASSWORD, compression=True) as conn:\n", + " conn.execute(query=\"CREATE SCHEMA IF NOT EXISTS {schema!i}\", query_params=conf.params)\n", + "\n", + " print(f\"Schema created in {stopwatch}\")" ] }, + { + "cell_type": "markdown", + "source": [ + "# Usage \n", + "This notebook could be used in other notebooks like this:\n", + "\n", + "```\n", + "%run ../setup_db.ipynb\n", + "conf = SandboxConfig(EXTERNAL_HOST_NAME=\"127.0.0.1\", HOST_PORT=8563)\n", + "setup_schema(conf)\n", + "```" + ], + "metadata": { + "collapsed": false + }, + "id": "26d6af42cc6d777f" + }, { "cell_type": "code", "execution_count": null, - "id": "fd30de4d-78c1-49cb-a86a-825ee3d42f6d", - "metadata": {}, "outputs": [], - "source": [] + "source": [], + "metadata": { + "collapsed": false + }, + "id": "207efa4935251bf5" } ], "metadata": {