### Run a Basic SQL Query in LotusWeb Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/getting-started.md This snippet demonstrates how to write and execute a simple SQL query to count records in a 'users' table using LotusWeb's Query Editor. It assumes a database is already configured. ```sql SELECT COUNT(*) as total_users FROM users; ``` -------------------------------- ### Start Development Server Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Starts the development server for the Phoenix application. This includes creating necessary asset files, installing Node.js dependencies, and running the application in development mode. ```Bash mkdir -p priv/static touch priv/static/app.css && touch priv/static/app.js npm install --prefix assets mix dev ``` -------------------------------- ### Use Variables in LotusWeb SQL Queries Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/getting-started.md This snippet shows how to incorporate dynamic variables into SQL queries within LotusWeb. It uses the `{{variable_name}}` syntax for placeholders like 'status' and 'start_date', which can be configured with different types and widgets. ```sql SELECT * FROM orders WHERE status = {{status}} AND created_at >= {{start_date}} ``` -------------------------------- ### Run Development Server (Subsequent) Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Starts the development server for the Phoenix application for subsequent runs after initial setup. Assumes dependencies and asset files are already in place. ```Bash mix dev ``` -------------------------------- ### Run Ecto Migration Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This Bash command executes the pending Ecto migrations, including the one created for Lotus tables, to update the database schema. ```Bash mix ecto.migrate ``` -------------------------------- ### Add Lotus to Application Supervision Tree Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This Elixir code demonstrates how to add the `Lotus` process to your application's supervision tree in `lib/my_app/application.ex`. This is crucial for enabling caching functionality within LotusWeb. ```Elixir # lib/my_app/application.ex def start(_type, _args) do children = [ MyApp.Repo, # Add Lotus for caching support (required for optimal dashboard performance) Lotus, MyAppWeb.Endpoint ] opts = [strategy: :one_for_one, name: MyApp.Supervisor] Supervisor.start_link(children, opts) end ``` -------------------------------- ### Add LotusWeb Dependency to mix.exs Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This snippet shows how to add the lotus_web dependency to your `mix.exs` file to include LotusWeb in your Phoenix project. After adding the dependency, you should run `mix deps.get`. ```Elixir def deps do [ {:lotus_web, "~> 0.2.0"} ] end ``` -------------------------------- ### Configure Lotus Settings in config.exs Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This Elixir code configures the Lotus settings in your `config/config.exs` file. It specifies the Ecto repository, default and data repositories, and caching configurations, including the adapter and namespaces. ```Elixir config :lotus, ecto_repo: MyApp.Repo, default_repo: "main", # Default repository for query execution data_repos: %{ "main" => MyApp.Repo, "analytics" => MyApp.AnalyticsRepo # Optional: multiple databases }, # Recommended: Enable caching for better dashboard performance cache: %{ adapter: Lotus.Cache.ETS, namespace: "myapp_lotus" # Lotus includes built-in profiles that work great with LotusWeb: # - :results (60s TTL) - User query results # - :schema (1h TTL) - Table introspection (used by dashboard) # - :options (5m TTL) - Dropdown options and reference data } ``` -------------------------------- ### SQL for Dropdown Options (Single Column) Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md Provides an example of an SQL query designed to populate a dropdown widget with a single column, where the column's values serve as both the option value and label. ```SQL SELECT status FROM orders GROUP BY status ORDER BY status ``` -------------------------------- ### Generate and Define Lotus Tables Migration Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This section provides the Bash command to generate a new Ecto migration for Lotus tables and the Elixir code for the migration itself. The migration uses `Lotus.Migrations.up()` and `Lotus.Migrations.down()` to manage the database schema. ```Bash mix ecto.gen.migration create_lotus_tables ``` ```Elixir defmodule MyApp.Repo.Migrations.CreateLotusTables do use Ecto.Migration def up do Lotus.Migrations.up() end def down do Lotus.Migrations.down() end end ``` -------------------------------- ### Install LotusWeb Dependency Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md This code snippet shows how to add the lotus_web package as a dependency in your Elixir project's `mix.exs` file. It specifies the version of lotus_web to be used. ```Elixir def deps do [ {:lotus_web, "~> 0.5.0"} ] end ``` -------------------------------- ### Mount LotusWeb Dashboard in Phoenix Router Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/installation.md This Elixir code shows how to mount the LotusWeb dashboard in your Phoenix router. It uses `Lotus.Web.Router.lotus_dashboard` and scopes it under a specific path, with a recommendation to add authentication. ```Elixir defmodule MyAppWeb.Router do use MyAppWeb, :router import Lotus.Web.Router # ... other routes scope "/", MyAppWeb do pipe_through [:browser, :require_authenticated_user] # ⚠️ Add auth! lotus_dashboard "/lotus" end end ``` -------------------------------- ### SQL for Dropdown Options (Two Columns) Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md Illustrates an SQL query for dropdown widgets that returns two columns. The first column is used as the option value, and the second column is used as the option label. ```SQL SELECT user_id, email FROM users WHERE active = true ORDER BY email ``` -------------------------------- ### Advanced SQL Query for Multi-Filter Dashboard Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md An advanced SQL query example for a dashboard, utilizing multiple variables for filtering data. It includes date range filtering, status filtering, and minimum amount filtering, along with aggregation. ```SQL SELECT DATE(created_at) as date, status, COUNT(*) as order_count, SUM(total_amount) as total_revenue FROM orders WHERE status = {{order_status}} AND created_at BETWEEN {{start_date}} AND {{end_date}} AND total_amount >= {{min_amount}} GROUP BY DATE(created_at), status ORDER BY date DESC ``` -------------------------------- ### Basic SQL Query with Variables Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md Demonstrates the basic syntax for embedding variables within SQL queries using double curly braces. These variables are automatically detected and presented as input controls in the query toolbar. ```SQL SELECT * FROM orders WHERE status = {{order_status}} AND created_at >= {{start_date}} AND total_amount >= {{minimum_amount}} ``` -------------------------------- ### Add Lotus to Supervision Tree for Caching Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Includes the Lotus process in the application's supervision tree to enable caching functionality. This ensures Lotus is started and managed alongside other application processes. ```Elixir # lib/my_app/application.ex def start(_type, _args) do children = [ MyApp.Repo, Lotus, MyAppWeb.Endpoint ] opts = [strategy: :one_for_one, name: MyApp.Supervisor] Supervisor.start_link(children, opts) end ``` -------------------------------- ### User Analysis Query with Variables Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md This SQL query analyzes user data, allowing filtering by registration date, email, and minimum order count. It uses parameterized variables for dynamic filtering and sorts results by order count. ```SQL SELECT u.email, u.created_at, COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.created_at >= {{registration_date}} AND ({{user_email}} IS NULL OR u.email LIKE '%' || {{user_email}} || '%') HAVING COUNT(o.id) >= {{min_orders}} ORDER BY order_count DESC ``` -------------------------------- ### Dynamic Category Analysis Query with Variables Source: https://github.com/typhoonworks/lotus_web/blob/main/guides/variables-and-widgets.md This SQL query performs dynamic category analysis, calculating product count and average price for a specified category and product status. It utilizes parameterized variables for category selection and product activation status. ```SQL SELECT c.name as category_name, COUNT(p.id) as product_count, AVG(p.price) as avg_price FROM categories c LEFT JOIN products p ON c.id = p.category_id WHERE c.id = {{category_id}} AND p.active = {{product_status}} GROUP BY c.id, c.name ORDER BY product_count DESC ``` -------------------------------- ### Configure Lotus in config.exs Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Sets up the core Lotus configuration, specifying the Ecto repository for queries and defining data repositories for query execution. ```Elixir config :lotus, ecto_repo: MyApp.Repo, default_repo: "main", data_repos: %{ "main" => MyApp.Repo, "analytics" => MyApp.AnalyticsRepo } ``` -------------------------------- ### Run Ecto Migrations Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Executes all pending Ecto migrations, including the one for creating Lotus tables, ensuring the database schema is up-to-date. ```Bash mix ecto.migrate ``` -------------------------------- ### Secure LotusWeb Mount with Authentication Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Demonstrates the correct way to mount LotusWeb by ensuring it's protected by an authentication pipeline, preventing unauthorized access. ```Elixir scope "/", MyAppWeb do pipe_through [:browser, :require_authenticated_user] lotus_dashboard "/lotus" end ``` -------------------------------- ### Run Elixir Tests Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Executes the test suite for the Elixir project using the Mix build tool. This command is essential for verifying the correctness of the codebase. ```Bash mix test ``` -------------------------------- ### Mount LotusWeb with Additional Callbacks Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Mounts the LotusWeb dashboard and includes custom callbacks for actions like authentication or logging access. ```Elixir lotus_dashboard "/lotus", on_mount: [MyAppWeb.RequireAdmin, MyAppWeb.LogDashboardAccess] ``` -------------------------------- ### Configure Lotus Caching Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Sets up caching for Lotus, specifying the adapter (ETS), a namespace, and different cache profile configurations with varying Time-To-Live (TTL) values for query results, schemas, and options. ```Elixir config :lotus, cache: [ adapter: Lotus.Cache.ETS, namespace: "my_app_cache", profiles: %{ results: [ttl_ms: 60_000], schema: [ttl_ms: 3_600_000], options: [ttl_ms: 300_000] } ] ``` -------------------------------- ### Generate Lotus Migration Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Generates a new Ecto migration file for creating Lotus tables and includes the necessary up and down functions to apply or revert Lotus migrations. ```Bash mix ecto.gen.migration create_lotus_tables ``` -------------------------------- ### Mount LotusWeb with WebSocket Configuration Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Configures the WebSocket settings for LotusWeb, specifying the socket path and transport mechanism. ```Elixir lotus_dashboard "/lotus", socket_path: "/live", transport: "websocket" ``` -------------------------------- ### Add Lotus Migration to Ecto Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Integrates the Lotus migration logic into a generated Ecto migration file, allowing Lotus tables to be created or removed via Ecto migrations. ```Elixir defmodule MyApp.Repo.Migrations.CreateLotusTables do use Ecto.Migration def up do Lotus.Migrations.up() end def down do Lotus.Migrations.down() end end ``` -------------------------------- ### Mount LotusWeb Dashboard in Router Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Integrates the LotusWeb dashboard into the application's router, defining the URL path and applying middleware for authentication. ```Elixir defmodule MyAppWeb.Router do use MyAppWeb, :router import Lotus.Web.Router scope "/", MyAppWeb do pipe_through [:browser, :require_authenticated_user] lotus_dashboard "/lotus" end end ``` -------------------------------- ### Mount LotusWeb with Custom Route Name Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Mounts the LotusWeb dashboard at a custom URL path and assigns a specific route name for easier referencing. ```Elixir lotus_dashboard "/admin/queries", as: :admin_queries ``` -------------------------------- ### Configure Lotus Table Visibility Source: https://github.com/typhoonworks/lotus_web/blob/main/README.md Defines rules for controlling which database tables are visible and accessible through Lotus, enhancing security by restricting access to sensitive data. ```Elixir config :lotus, table_visibility: %{ default: [ allow: [ "reports_users", "analytics_events", {"reporting", ~r/^daily_/} ], deny: [ "users", "admin_logs", {"public", ~r/^schema_/} ] ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.