5.1.1 • Published 12 months ago

pgsqwell v5.1.1

Weekly downloads
23
License
MIT
Repository
github
Last release
12 months ago

pgsqwell

SQL template tag for PostgreSQL done well

GitHub license

Done well because:

  • immutable
  • separation of concerns / specialization: use the sql tag for valid SQL statements, sqlPart for subparts that ain't necessarily valid

Sample usage

import sql, {
  escapeSQLIdentifier,
  sqlPart,
  emptySQLPart,
  joinSQLValues,
} from 'pgsqwell';

const limit = 10;
const query = sql`SELECT id FROM users WHERE name=${'toto'} ${
  limit ? sqlPart`LIMIT ${limit}` : emptySQLPart
}`;
const query2 = sql`SELECT id FROM ${escapeSQLIdentifier('table')}`;
const query3 = sql`SELECT id FROM users WHERE id IN ${joinSQLValues([1, 2])}}`;
const mergedQuery = sql`
${query}
UNION
${query2}
UNION
${query3}
`;

Debug

To print any query built with pgsqwell use the DEBUG=pgsqwell environment variable:

DEBUG=pgsqwell npm t

Testing

Use pgsqwell-mock to check you queries in your tests.

Known downsides

Authors

License

MIT

5.1.1

12 months ago

5.1.0

1 year ago

5.0.0

1 year ago

4.2.0

1 year ago

3.0.0

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

2.0.2

2 years ago

2.0.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

2.0.0

3 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.0.0

5 years ago