Skip to main content

ttql 1.0.1 copy "ttql: ^1.0.1" to clipboard
ttql: ^1.0.1 copied to clipboard

TableTalk Query Language (TTQL) - Federated cross-database query engine and AST parser in Dart.

TTQL (TableTalk Query Language) #

Dart CI pub package License: MIT

TTQL (TableTalk Query Language) is a federated, cross-database query engine and AST parser written in pure Dart. It enables executing read-only analytical queries that join data across heterogeneous database systems (PostgreSQL, MySQL, SQLite, MongoDB, Redis) in a single script.

const pg = environment.connections.ecommerce_pg;
const mysql = environment.connections.inventory_mysql;
const mongo = environment.connections.analytics_mongo;

from(pg.customers as c)
  .innerJoin(mysql.shipments as s, on: c.customer_id == s.customer_id)
  .leftJoin(mongo.events as e, on: c.customer_id == e.customer_id)
  .where(c.country == 'US' && s.status == 'in_transit')
  .select([c.customer_id, c.email, s.carrier, e.event_type])
  .limit(25);

Official Visual Client & Local-AI Workspace — TableTalk Studio

ttql is 100% open source (CLI, LSP server, VS Code extension, and Dart compiler library). When you want a turnkey desktop/mobile GUI built around TTQL — featuring OS Keychain credential vaulting, 1-click Server Pool discovery, visual cross-DB ERD graphs, and local Ollama AI query generation & EXPLAIN ANALYZE profiling — check out TableTalk Studio.


Key Features #

  • Federated Cross-Engine Joins: Execute declarative joins across relational databases (PostgreSQL, MySQL, SQLite), document stores (MongoDB), and key-value stores (Redis) in one query.
  • Read-Only Safety: Lexical and AST validation reject mutation operations (INSERT, UPDATE, DELETE, DROP, ALTER, etc.) before any network connection or query execution occurs.
  • In-Memory SQLite Staging: Uses an ephemeral in-memory SQLite database (sqlite3.openInMemory()) to stage intermediate datasets and compute relational joins.
  • DAG Execution Planner: Constructs dependency graphs to schedule independent queries in parallel while throttling concurrent connections per stage (default batch limit: 3).
  • Command-Line Interface: Run queries, inspect execution plans, lint scripts, or launch a Language Server Protocol (LSP) daemon (ttql lint, ttql plan, ttql run, ttql lsp).

📚 Documentation #

  • 🌐 Online Documentation Portal: Official TableTalk & TTQL guides, tutorials, and interactive examples.
  • ⚡ Developer Syntax Guide: Rich, developer-friendly cheat sheet, pipeline diagrams, operators, and copy-paste recipes.
  • 📖 Official Language Manual & Specification: Comprehensive reference manual, pushdown mechanics, and formal EBNF grammar.
  • 🏛️ Compiler Architecture Wiki: Deep dive into the frontend compiler, DAG optimizer, and ephemeral staging engine.

Installation #

Via Pub #

dart pub global activate ttql

From Source #

git clone https://github.com/Dud3core-webdev/TTQL.git
cd TTQL
dart pub get

Command Line Usage #

The ttql executable provides commands for validation, inspection, and execution:

1. Static Linting (ttql lint) #

Validates script syntax and checks for forbidden mutation keywords without connecting to any database:

ttql lint path/to/script.ttql

2. Execution Plan Inspection (ttql plan) #

Displays the Directed Acyclic Graph (DAG) stages, target database engines, and staging tables:

ttql plan path/to/script.ttql

3. Query Execution (ttql run) #

Executes the query script and formats the results:

# Tabular output
ttql run path/to/script.ttql --config connections.json --format table

# JSON output
ttql run path/to/script.ttql --config connections.json --format json

# CSV export
ttql run path/to/script.ttql --config connections.json --format csv > results.csv

4. Language Server Protocol (ttql lsp) #

Starts the JSON-RPC 2.0 Language Server over standard input/output (stdio) for IDE diagnostics and completion:

ttql lsp

Connection Configuration (--config) #

Query execution requires a JSON configuration file specifying connection strings or offline mock data:

{
  "connections": [
    {
      "id": "ecommerce_pg",
      "name": "PostgreSQL E-Commerce",
      "engine": "postgres",
      "connectionString": "postgres://${PG_USER}:${PG_PASS}@localhost:5432/ecommerce_pg",
      "schemaOverview": {
        "customers": ["customer_id", "full_name", "email"]
      },
      "mockData": [
        { "customer_id": "cust_101", "full_name": "Alice Vance", "email": "alice@tabletalk.io" },
        { "customer_id": "cust_102", "full_name": "Bob Smith", "email": "bob.smith@techcorp.dev" }
      ]
    }
  ]
}
  • Environment Variable Expansion: ${VAR_NAME} placeholders in connection strings are resolved from the environment at runtime.
  • Offline Mock Execution: Defining mockData allows evaluating scripts and testing joins without live database connections.

Editor Support #

Syntax highlighting, diagnostic linting, and completion support for VS Code and compatible editors is available in the TTQL VS Code Extension.


Programmatic Usage in Dart #

package:ttql can be integrated directly into Dart applications:

import 'package:ttql/ttql.dart';

void main() async {
  final script = '''
    const pg = environment.connections.ecommerce_pg;
    const mysql = environment.connections.inventory_mysql;
    const targetCustomer = 'cust_101';
    const customerFields = ['customer_id', 'full_name', 'email'];

    from(pg.customers)
      .select([...customerFields])
      .where(customer_id == targetCustomer)
      .innerJoin(mysql.shipments, on: 'customer_id')
      .select('shipment_id', 'order_id')
      .orderBy(customer_id, 'ASC')
      .limit(10);
  ''';

  final engine = TtqlEngine(connectionProvider: myConnectionProvider);
  final result = await engine.executeScript(script);

  for (final row in result.rows) {
    print(row);
  }
}

Fluent Query Pipeline #

TTQL features an ergonomic fluent chaining pipeline:

const pg = environment.connections.ecommerce_pg;
const mysql = environment.connections.inventory_mysql;

from(pg.customers as c)
  .innerJoin(mysql.shipments as s, on: c.customer_id == s.customer_id)
  .where(s.status == 'in_transit' && c.country == 'US')
  .groupBy(c.country)
  .select([
    c.country,
    count() as shipment_count
  ])
  .having(shipment_count > 5)
  .orderBy(shipment_count, 'DESC')
  .limit(20)
  .offset(0);

For the exhaustive specification, formal EBNF grammar, and real-world recipes, read the Official TTQL Language Manual.


Architecture Documentation #

For details on the compiler pipeline, AST representation, DAG planner, and staging database:

  • Official TTQL Language Manual - The complete language specification and cookbook.
  • Architecture Wiki Index
    • 1. High-Level Concept
    • 2. Pipeline Architecture
    • 3. File Breakdown
    • 4. Cross-Database Join Walkthrough

License #

MIT License. See LICENSE for details.

0
likes
0
points
287
downloads

Publisher

unverified uploader

Weekly Downloads

TableTalk Query Language (TTQL) - Federated cross-database query engine and AST parser in Dart.

Homepage
Repository (GitHub)
View/report issues

Topics

#database #sql #query-engine #federated-query #parser

License

unknown (license)

Dependencies

args, path, sqlite3

More

Packages that depend on ttql