Obsidian SQLSeal

repository·main·Indexed 41 days ago

https://github.com/h-sphere/sql-seal

A plugin for Obsidian (version 0.40.1) that enables SQL queries on notes, tags, and tasks. It allows users to treat CSV files as database tables and render results as HTML, Markdown, or AG Grid views. The ecosystem includes SQLSeal Charts for data visualization using Apache ECharts, supporting advanced features like data clustering and regression analysis via ecStat transforms.

Tokens
20.9K
Snippets
89
Records
115
Agent score
99%

What's inside SQLSeal

  1. Query Obsidian vault data with SQL

    main

    SQLSeal allows you to treat your Obsidian vault as a queryable database. You can use standard SQL syntax to select, join, and filter data from your notes, files, and tags. The engine uses SQLite under the hood, providing full SQL capabilities.

    SELECT * FROM files
    ORDER BY modified_at DESC
    LIMIT 10
  2. Query Vault content using built-in tables

    main

    SQLSeal provides built-in tables to query your Obsidian vault content. You can use these tables to retrieve information about files, tags, tasks, and links based on their properties (frontmatter) and associations.

    Available tables:

    • files: Information about files in the vault.
    • tags: Information about tags associated with files.
    • tasks: Information about tasks.
    • links: Information about links within the vault.
  3. Understand the difference between Frontmatter tags and the tags table

    main

    In SQLSeal, tags exist in two distinct contexts with different structures:

    1. Frontmatter Tags: These are defined in the YAML metadata at the top of your Obsidian files (e.g., tags: [project, todo]). In SQLSeal, these are treated as a plain list of values associated with a file and are accessed via the files table.
    2. The tags Table: This is a specialized table that provides a row-based view of every tag in your vault. Each row represents a single tag instance, linking a specific tag value to a specific file path. This is useful for a granular, relational view of tag usage across the entire vault.
  4. Control data refreshing with REFRESH and NO REFRESH

    main

    You can control how SQLSeal handles updates to underlying data sources using the REFRESH or NO REFRESH statements.

    • REFRESH: The query automatically re-executes whenever the underlying data changes. SQLSeal only listens to changes in the specific tables used within the query.
    • NO REFRESH: The query executes exactly once and stops listening for changes. Use this for expensive queries where you want manual control over when data is re-processed.
    TABLE data = file(data.csv)
    
    NO REFRESH
    
    SELECT * FROM data
  5. Use properties to create dynamic SQLSeal queries

    main

    SQLSeal allows you to use properties to make queries dynamic and reusable across different files or templates. To reference a property within a query, prepend the property name with the @ symbol (e.g., @year refers to the year property).

    SELECT * FROM files WHERE path = @path
  6. Perform data clustering in charts

    main

    You can use the ecStat:clustering transform within a dataset to cluster data into separate buckets. This is useful for identifying underlying complexity or patterns in your data.

    To implement clustering, you add a second dataset object to your configuration that uses the transform property. This transform takes the source data and calculates cluster assignments, which can then be used to drive visual properties like color via a visualMap or series encoding.

    // Example of a clustering transform configuration
    {
      transform: {
        type: 'ecStat:clustering',
        print: true,
        config: {
          clusterCount: 6,
          outputType: 'single',
          outputClusterIndexDimension: 2
        }
      }
    }
  7. Handle sparse schemas in JSONL files

    main

    When using JSONL files where different lines contain different keys (sparse schemas), SQLSeal automatically constructs a table schema using the union of all keys found across all lines.

    If a specific row is missing a key that exists elsewhere in the file, that field will be returned as NULL for that row.

    -- If events.jsonl contains lines with varying keys like 'amount'
    TABLE events = file(events.jsonl)
    
    SELECT event, user, amount FROM events WHERE amount IS NOT NULL
  8. Manage tables in SQLSeal codeblocks

    main

    When using SQLSeal in your notes:

    • You can define multiple tables within a single sqlseal codeblock.
    • You can reference tables defined in different snippets, provided they are within the same note.
    • Note: Currently, tables are local to the file they are defined in.
  9. Advanced chart configuration via Apache ECharts

    main
    SQLSeal Charts uses Apache ECharts under the hood. While this documentation covers basic use cases, most advanced and interactive chart configurations available in the Apache ECharts documentation can also be achieved within SQLSeal by passing the appropriate configuration options into the CHART block.
  10. Visualise data with SQLSeal Charts

    main

    SQLSeal Charts is an expansion for the plugin that provides full visualization tools for your query results.

    Note: As of the current documentation, SQLSeal Charts is undergoing review by Obsidian. Full documentation will be released once approved.

  11. Compare SQLSeal with Dataview

    main

    SQLSeal is not intended as a direct replacement for Dataview, but rather as a complementary tool. While Dataview uses its own Dataview Query Language (DQL) and supports JavaScript, SQLSeal uses standard SQL (with full SQLite compatibility).

    Key advantages of SQLSeal over Dataview include:

    • SQL Compatibility: Uses standard SQL instead of DQL.
    • CSV Support: Ability to both query and edit data from CSV files.
    • Relational Power: Supports joining tables, which Dataview does not.
    • Inline Queries: Supports inline queries using the S> prefix (whereas Dataview uses =).

    Both plugins support querying vault data (files, tags, tasks), filtering, and mobile support.

  12. Reference Markdown tables in SQL Seal

    main

    SQL Seal allows you to reference markdown tables using the table() function. You can identify tables using four primary methods:

    1. By numeric index: table(index) (e.g., table(0) for the first table).
    2. By header name: table(headerName) (finds the first table following the specified header; case-insensitive).
    3. By header name and index: table(headerName, index) (useful when multiple tables exist under the same header).
    4. From other files: table(file:path/to/file.md, ...) (accesses tables in external markdown files).

    Compatibility Note:

    • Numeric indexing was introduced in version 0.16.0.
    • Header-based and cross-file references were introduced in version 0.30.0.
    -- By index
    TABLE expenses = table(0)
    
    -- By header
    TABLE expenses = table(Monthly Expenses)
    
    -- By header and index
    TABLE revenue = table(Financial Data, 0)
    
    -- From another file by index
    TABLE expenses = table(file:Finance/expenses.md, 0)
    
    -- From another file by header
    TABLE summary = table(file:Finance/annual-report.md, Revenue Summary)