A battle-tested PostgreSQL client with strict types, detailed logging and assertions.
(The above GIF shows Slonik producing query logs. Slonik produces logs using Roarr. Logs include stack trace of the actual query invocation location and values used to execute the query.)
If you value my work and want to see Slonik and many other of my Open-Source projects to be continuously improved, then please consider becoming a patron:
- Promotes writing raw SQL.
- Discourages ad-hoc dynamic generation of SQL.
Read: Stop using Knex.js
Note: Using this project does not require TypeScript. It is a regular ES6 module. Ignore the type definitions used in the documentation if you do not use a type system.
- Assertions and type safety.
- Connection mocking.
- Safe connection handling.
- Safe transaction handling.
- Safe value interpolation.
- Transaction nesting.
- Transaction retrying
- Detailed logging.
- Asynchronous stack trace resolution.
- Middlewares.
- Mapped errors.
- ESLint plugin.
{"gitdown": "contents"}
{"gitdown": "include", "file": "./ABOUT_SLONIK.md"}
{"gitdown": "include", "file": "./USAGE.md"}
{"gitdown": "include", "file": "./TYPE_PARSERS.md"}
{"gitdown": "include", "file": "./INTERCEPTORS.md"}
{"gitdown": "include", "file": "./RECIPES.md"}
{"gitdown": "include", "file": "./SQL_TAG.md"}
{"gitdown": "include", "file": "./VALUE_PLACEHOLDERS.md"}
{"gitdown": "include", "file": "./QUERY_BUILDING.md"}
{"gitdown": "include", "file": "./QUERY_METHODS.md"}
{"gitdown": "include", "file": "./ERROR_HANDLING.md"}
{"gitdown": "include", "file": "./TYPES.md"}
{"gitdown": "include", "file": "./DEBUGGING.md"}
Using Atom IDE you can leverage the language-babel
package in combination with the language-sql
to enable highlighting of the SQL strings in the codebase.
To enable highlighting, you need to:
- Install
language-babel
andlanguage-sql
packages. - Configure
language-babel
"JavaScript Tagged Template Literal Grammar Extensions" setting to uselanguage-sql
to highlight template literals withsql
tag (configuration value:sql:source.sql
). - Use
sql
helper to construct the queries.
For more information, refer to the JavaScript Tagged Template Literal Grammar Extensions documentation of language-babel
package.
The vscode-sql-template-literal
extension provides syntax highlighting for VS Code: