![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@mojojs/sql
Advanced tools
Safely generate and compose SQL statements with tagged template literals. Written in TypeScript.
import {sql} from '@mojojs/sql';
// {text: 'SELECT * FROM users WHERE name = $1', values: ['sebastian']}
const {text, values} = sql`SELECT * FROM users WHERE name = ${'sebastian'}`.toQuery();
To prevent SQL injection attacks, all interpolated values become placeholders in the generated query. Partial statements can even be used recursively to build more complex queries.
const role = 'admin';
const partialQuery = sql`AND role = ${role}`;
const name = 'root';
// {text: 'SELECT * FROM users WHERE name = $1 AND role = $2', values: ['root', 'admin']}
const {text, values} = sql`SELECT * FROM users WHERE name = ${name} ${partialQuery}`.toQuery();
Make partial statements optional to dynamically generate WHERE
clauses.
const optionalPart = foo === true ? sql`AND foo IS NOT NULL` : sql``;
const {text, values} = sql`SELECT * FROM users WHERE name = ${'sebastian'} ${optionalPart}`.toQuery();
And if you need a little more control over the generated SQL query, you can of course also bypass safety features with
the tagged template literal sqlUnsafe
. But make sure to handle unsafe values yourself with appropriate escaping
functions for your database. For PostgreSQL there are escapeLiteral
and escapeIdentifier
functions included with
this package.
import {sql, sqlUnsafe, escapeLiteral} from '@mojojs/sql';
const role = 'role = ' + escapeLiteral('power user');
const partialQuery = sqlUnsafe`AND ${role}`;
const name = 'root';
// {text: "SELECT * FROM users WHERE name = $1 AND role = 'power user'", values: ['root']}
const {text, values} = sql`SELECT * FROM users WHERE name = ${name} ${partialQuery}`.toQuery();
For databases that do not support numbered placeholders like $1
and $2
, you can set a custom character with the
placeholder
option.
// {text: 'SELECT * FROM users WHERE name = ?', values: ['root']}
const {text, values} = sql`SELECT * FROM users WHERE name = ${'root'}`.toQuery({placeholder: '?'});
All you need is Node.js 16.0.0 (or newer).
$ npm install @mojojs/sql
If you have any questions the documentation might not yet answer, don't hesitate to ask in the Forum, on Matrix, or IRC.
FAQs
SQL generator
The npm package @mojojs/sql receives a total of 235 weekly downloads. As such, @mojojs/sql popularity was classified as not popular.
We found that @mojojs/sql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.