
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
seduce-windows
Advanced tools
Seduce is a Node module for keeping your SQL out of your code. With seduce,
you write parametrized SQL in .sql files. Seduce parses it and builds your
queries as functions.
Seduce is a way of writing SQL queries. It does not provide database logic.
npm install seduce
Start by writing your SQL queries like this, in a file like queries.sql:
-- name: findByNameAndModel
-- Queries the cars table by a car name and model
SELECT *
FROM cars
WHERE cars.brand = :name AND cars.model = :model
-- name: findByNames
SELECT *
FROM cars
WHERE cars.brand IN :names
Notice the name: notation. This is required, and the name that you define
will be the name of the function that seduce will generate for you. You can
add any number of comment lines describing what the query does after that line.
Next, write your query normally. For any portion that needs to take a
parameter, indicate your parameter like :name.
Write any number of queries that you want -- each should be separated by an empty line.
To use this query that you've just defined, do this:
var seduce = require('seduce'),
q = seduce('queries.sql');
seduce(...) has the following signature: paths {String|Array} and opt {Object}.
Paths are file paths to your sql files; opt is optional but highly recommended.
It supports a key escape to attach a function to escape your parameters to
prevent injection attacks. Here's an example if you're using node-mysql:
seduce(['one.sql', 'two.sql], { escape: connection.escape })
You can call your functions by referring to them by name. Any of these are equivalent:
var carQuery = q.findByNameAndModel('Ford', 'Explorer');
or
var carQuery = q.findByNameAndModel({ name: 'Ford', model: 'Explorer' });
or
var myParams = ['Ford, 'Explorer];
var carQuery = q.findByNameAndModel.apply(null, myParams);
This will return a String like this:
SELECT * FROM cars WHERE cars.brand = "Ford" AND cars.model = "Explorer"
If you pass an array as an argument (like if you're doing an IN query), it'll produce something like this:
SELECT * FROM cars WHERE cars.brand IN ("Ford", "Honda")
If you have multiple parameters with the same name, Seduce will take care of that for you and duplicate the value you provide in your query.
Starting with queries.sql like above...
var mysql = require('mysql'),
connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret'
}),
seduce = require('seduce'),
q = seduce('queries.sql');
connection.connect();
connection
.query(q.findByNameAndModel('Ford', 'Explorer'), function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
Example taken from the documentation for node-mysql.
By default double quotes (") are used for parameters; this is fine for MySQL but for PostgreSQL we need to use single quotes. You can change the quote parameter as an option: seduce('one.sql'], { quote: "'" })
Brand new.
Seduce is heavily inspired by a Clojure library by Kris Jenkins Yesql.
FAQs
Fork of seduce, adds windows and postgres support
We found that seduce-windows 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.