npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@factorialco/tentaclesql

v1.2.5

Published

SQL engine from multiple sources

Downloads

5

Readme

TentacleSQL

Query your HTTP endpoints data using SQL

Install

Using docker

docker run -p 8080 -ti factorialco/tentaclesql

As system command

npm i -g @factorialco/tentaclesql

Setup

To be able to start TentacleSQL you need to provide even SCHEMA_URL or SCHEMA_FILE environment variable specifying the route to retrieve the schema from.

Alternativelly you can provide your own schema into same POST request you run the query.

Examples:

SCHEMA_URL='https://example.com/api/schema'
SCHEMA_FILE='example.yaml' # Note that should be placed into `schemas` folder

This schema stucture is an array of all the table definitions available in your schema. Something like:

[
  {
    "name": "applications",
    "url": "https://example.com/api/schema/tables/applications",
    "fields": [
      {
        "key": "id",
        "type": "number"
      },
      {
        "key": "first_name",
        "type": "text"
      },
      {
        "key": "last_name",
        "type": "text"
      }
    ]
  },
  {
    "name": "goals",
    "url": "https://example.com/api/schema/tables/goals",
    "fields": [
      {
        "key": "id",
        "type": "number"
      },
      {
        "key": "progress",
        "type": "text"
      },
      {
        "key": "application_id",
        "type": "number",
        "table": "applications",
        "foreign_key": "id"
      }
    ]
  }
]

To see yaml example check schemas/example.yaml.

Schema definition API

The schema definition needs to respond with an array of table definitions:

Table:

  • name: Name of the table
  • url: URL to retrieve the data from
  • autodiscover: If you want to autodiscover fields from url response
  • result_key: Which key should be readed for array of results
  • fields: List of fields / foreign keys of this table

Each table will have an array of fields that can be raw fields or foreign key to denote relations between tables.

Field:

  • key: Name of the column / field
  • type: Type of the field. Available types: text, number, data and boolean

Foreign key:

  • key: Name of the foreign key
  • type: Type of the field. Available types: text, number, data and boolean
  • table: Target table of the foreign key
  • foreign_key: Referenced column by the foreign key

Usage HTTP API

Once you have your tentaclesql server up and running you can use it by sending POST requests against /.

Example:

curl -H "Content-type: application/json" -X POST -d '{"query": "SELECT 1;"}' http://localhost:3000/

The expected payload contains the following parameters:

  • query: The SQL query to be executed against the in-memory database.
  • parameters: The parameters to be replaced in the query.
  • config: Configuration parameters.
    • extensions: Array of extensions to enable. Check https://github.com/nalgeon/sqlean to see all the supported extensions and how to use them.
    • schema: Manual schema definition

Usage CLI

Note that you must configure your schema first. You can pass an environment variable:

Example

SCHEMA_FILE=example.yaml tentaclesql interactive

Run interactive prompt

yarn cli interactive
# or installed global
tentaclesql interactive

Execute queries

yarn cli query "SELECT 1;"
# or installed global
tentaclesql query "SELECT 1;"

Bulk fetch

By default Tentacle sends one HTTP request for each table data, however you can change this and fetch all table data in one HTTP request. To enable this you need to pass following paramaters:

  • BULK_FETCH=true
  • BULK_FETCH_URL=url