
Company News
AWS Security Hub Adds Socket for Supply Chain Security
Socket is now in the AWS Security Hub Extended plan. Adopt it through AWS, apply committed spend, and block malicious open source packages.
The tiny SQL templater, with the aim to be as simple as possible so to not get in the way of you writing SQL.
It supports the following conditionals:
{key, optionalDefault} - Turns args into ? with an optional default{!key, optionalDefault} - Passed raw into the SQL{>path, optionalDataKey} - Require file from the templates{?key, replaceTruthy, replaceFalsey} - Ternary switch, the defaults are replaceTruthy/replaceFalsey === true/falsenpm i sql-stamp --save
The API is as follows
var sqlStamp = require("sql-stamp");
var tmpl = sqlStamp({
/* Pass a list of templates... (key=path, value=sql-string) */
"./friends.sql": "SQL_STRING",
"./example.sql": "SQL_STRING"
});
So for example given the following SQL file which selects all friend requests you've accepted
/* ./friends.sql */
select * from friends where status = "accepted"
The following file can require this as a CTE (http://www.postgresql.org/docs/9.1/static/queries-with.html) via a require directive {> ./file/path.sql}
/* ./example.sql */
WITH friend AS (
{> ./friends.sql}
)
select
*
from
account
where
account.id = friend.toId
AND friend.fromId = {accountId}
AND (
{?filterDisabled} OR {!filterKey} = {filterVal}
)
When we run the following
var out = tmpl("./example.sql", {
accountId: 1,
filterDisabled: false,
filterKey: "role",
filterVal: "dev"
});
The following will be returned
{
args: [1, "dev"],
sql: /* SQL in comment below */
/**
* WITH friend AS (
* select * from friends where status = "active"
* )
* select
* *
* from
* account
* where
* account.id = friend.toId
* AND friend.fromId = ?
* AND (
* /*feature:filterDisabled*/ false AND role = ?
* )
*/
}
There is also experimental support for more descriptive errors and can be enabled with {prettyErrors: true}
var tmpl = sqlStamp(templates, {prettyErrors: true});
Then you'll get more descriptive errors about where the error happened in your source SQL
SQLError: Too many args
select
*
from
account
where
foo = {too, many, args}
--------^
You can see some more examples in the tests here here
npm test
FAQs
The tiny SQL templater
The npm package sql-stamp receives a total of 4 weekly downloads. As such, sql-stamp popularity was classified as not popular.
We found that sql-stamp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket is now in the AWS Security Hub Extended plan. Adopt it through AWS, apply committed spend, and block malicious open source packages.

Research
/Security News
Popular npm packages keyv and cacheable compromised.

Security News
A misconfiguration gave three Anthropic models internet access, and one, believing it was in a simulation, shipped a credential-stealing package to PyPI.