sqlite-html

repository·main·Indexed 18 days ago

https://github.com/asg017/sqlite-html

A SQLite extension written in Go that provides tools for querying, manipulating, and creating HTML elements directly within SQL queries using CSS selectors. It includes functions such as html_extract, html_each, and html_attribute_get. The extension is available for Node.js (npm), Python (pip), Deno, Ruby, and as a Datasette plugin (datasette-sqlite-html), with pre-compiled binaries for macOS, Linux, and Windows.

Tokens
8.7K
Snippets
48
Records
54
Agent score
60%

What's inside sqlite-html

  1. Choose the right `sqlite-html` Python package

    main

    The sqlite-html project provides two distinct Python packages depending on your integration needs:

    1. sqlite-html: The core package for general Python usage. Use this if you want to use the SQLite HTML extension directly in your own Python applications.
    2. datasette-sqlite-html: A Datasette plugin. This is a lightweight wrapper around the core sqlite-html package designed specifically for use with the Datasette data publishing tool.
  2. Install sqlite-html for linux-x64

    main
    The sqlite-html-linux-x64 package provides the pre-compiled SQLite extension (lib/html0.so) specifically for Linux systems with x64 architecture. When you install the main sqlite-html package, it will automatically resolve to this platform-specific package on compatible Linux environments. This extension is designed to be used with better-sqlite3 or node-sqlite3 drivers in Node.js.
  3. Run Deno scripts with x/sqlite_html

    main

    Because x/sqlite_html relies on x/sqlite3 (which uses FFI) and needs to download/cache pre-compiled extensions, you must grant the necessary permissions. It is recommended to use the -A (or --allow-all) and --unstable flags when running your script.

    deno run -A --unstable <file>
  4. Install sqlite-html

    main

    You can install sqlite-html via various package managers depending on your runtime environment:

    • Python: pip install sqlite-html
    • Datasette: datasette install datasette-sqlite-html
    • Node.js: npm install sqlite-html
    • Deno: Use deno.land/x/sqlite_html
    • Ruby: gem install sqlite-html
    pip install sqlite-html
  5. Load the `sqlite-html` extension into a SQLite connection

    main

    To use the sqlite-html SQL functions in your Python application, use the sqlite_html.load(conn) function. This function wraps the standard sqlite3.Connection.load_extension() method.

    Important: You must ensure that extension loading is enabled on your connection before calling load(). It is a best practice to disable extension loading again after the extension has been loaded to maintain security.

    import sqlite_html
    import sqlite3
    
    conn = sqlite3.connect(':memory:')
    
    # Enable extension loading
    conn.enable_load_extension(True)
    
    # Load the sqlite-html extension
    sqlite_html.load(conn)
    
    # Disable extension loading for security
    conn.enable_load_extension(False)
    
    # Verify installation
    version = conn.execute('select html_version()').fetchone()
    print(version)
    # ('v0.1.0')
  6. Use sqlite-html as a loadable extension

    main

    To use sqlite-html as a runtime-loadable extension, download the appropriate binary for your platform from the GitHub Releases page:

    • MacOS: html0.dylib
    • Linux: html0.so
    • Windows: html0.dll

    Note: The 0 in the filename represents the major version. Since the project is currently pre-v1, expect breaking changes in future versions.

    Loading in SQLite CLI

    .load ./html0

    Loading in Python (sqlite3)

    import sqlite3
    con = sqlite3.connect(":memory:")
    con.enable_load_extension(True)
    con.load_extension("./html0")

    Loading in Node.js (better-sqlite3)

    const Database = require("better-sqlite3");
    const db = new Database(":memory:");
    db.loadExtension("./html0");

    Loading in Datasette

    datasette data.db --load-extension ./html0
    con.load_extension("./html0")
  7. Install sqlite-html for macOS (darwin-arm64)

    main

    The sqlite-html-darwin-arm64 package is a platform-specific distribution of sqlite-html designed for macOS systems running on ARM64 architecture (e.g., Apple Silicon).

    When you install the main sqlite-html package, it automatically resolves to this package if your environment matches these specifications. It provides a pre-compiled SQLite extension located at lib/html0.dylib. This extension is compatible with the following Node.js SQLite drivers:

    • better-sqlite3
    • node-sqlite3
  8. Install sqlite-html via npm

    main

    For Node.js developers, sqlite-html is available as an NPM package. While you can install the main sqlite-html package, there are also autogenerated platform-specific packages available (e.g., sqlite-html-darwin-x64, sqlite-html-windows-x64, sqlite-html-linux-x64) to ensure compatibility with your specific architecture and operating system.

    npm install sqlite-html
  9. Install sqlite-html for macOS (x64)

    main
    The sqlite-html-darwin-x64 package provides a pre-compiled SQLite extension specifically for macOS systems running on x64 architecture. When you install the main sqlite-html package, it will automatically resolve to this platform-specific package if your host computer matches these requirements. The extension is bundled as lib/html0.dylib and is designed for use with better-sqlite3 or node-sqlite3 drivers.