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

@saltcorn/sql

v0.3.9

Published

Actions and views based on SQL

Downloads

207

Readme

sql

Actions and views based on SQL

SQLView view

Use this view to create HTML code views of the results of arbitrary SQL queries

  1. Create a view of this type.
  2. Set output type = Table or JSON to begin with
  3. Start by creating your SQL query with no qualifiers (which will come from the URL query state). The preview table should update as you type
  4. When you are happy with the SQL query, switch to output type = HTML
  5. Create your HTML code, use {{ rows }} to access rows. For instance if your query is an aggregation with a single row result (e.g. SELECT COUNT(*) FROM...), access this with {{ rows[0].count }}, for example <h2>{{ rows[0].count }}</h2>. You can also loop, e.g. {{# for(const row of rows) { }}
  6. When you are happy with both you are SQL and HTML code, Think about whether you need any parameters from the state. List these comma-separated, in order and use in the SQL code as $1, $2 etc. Example SQL code: select * from _sc_config where key = $1;

run_sql_code action

This action allows you to run arbitrary SQL. You specify values from the row that needs to be included in the query using positional parameters $1, $2 etc.

SQL query table provider

This will give you a Saltcorn "virtual table" based on an SQL query and specifying result fields (these will be guessed from the query result, but you need to check and assign a primary key).

Normally you don't need to worry about the where clause when this is filtered by one of the columns in a view. Your query will be parsed, and the appropriate where clause will be inserted before the final query is run.

There are some very specific cases in which you need to include information about the user in the query in a way that cannot be done in the normal way by state filtering. In this case, you can use string interpolation to include information about the user. For instance:

... where baz in (select id from zubs where user_zub = {{ user.myzub }} ) ...

User row values used in this way are automatically escaped by the sqlstring to prevent SQL injection.