{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Managing Schemas\n", "\n", "This notebook shows how you can manage schemas with the ThanoSQL library. We will cover how to create schemas, get the list of stored schemas, and delete schemas.\n", "First, initialize a ThanoSQL client with your API token and engine URL." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from thanosql import ThanoSQL\n", "\n", "client = ThanoSQL(\n", " api_token=\"THANOSQL_API_TOKEN\",\n", " engine_url=\"THANOSQL_ENGINE_URL\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Listing Schemas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can get the list of schemas in your workspace using the `list()` function. There are no required or optional parameters." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "res = client.schema.list()\n", "for schema in res[\"schemas\"]:\n", " print(schema[\"name\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating Schemas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is possible to create schemas through the ThanoSQL client. Only the schema name is needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "client.schema.create(\"my_schema_1\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Deleting Schemas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Currently, there is no direct API for deleting schemas. However, it is possible to do through raw query using the query API." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query = f\"DROP SCHEMA my_schema_1 CASCADE\"\n", "\n", "client.query.execute(query)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }