{"id":43470,"library":"node-sql-template","title":"node-sql-template","description":"A simple SQL template engine and query runner for Node.js, version 0.2.3, low release cadence. It reads SQL files from a directory, renders them with escaped values, and executes queries using a connection pool via the mysql package. Key differentiators: simple API with forge/run, streaming results, and debug output. Alternatives like Squel or Knex are more feature-rich but heavier.","status":"active","version":"0.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/adriano-di-giovanni/node-sql-template","tags":["javascript","sql","mysql","template","engine","query"],"install":[{"cmd":"npm install node-sql-template","lang":"bash","label":"npm"},{"cmd":"yarn add node-sql-template","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-sql-template","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for query execution; must be installed separately.","package":"mysql","optional":true}],"imports":[{"note":"Package is CommonJS only; no ESM exports. Use require.","wrong":"import SQLTemplate from 'node-sql-template';","symbol":"default","correct":"const SQLTemplate = require('node-sql-template');"},{"note":"forge is the factory method; returns a template instance.","wrong":null,"symbol":"forge","correct":"const template = SQLTemplate.forge(options);"},{"note":"render() returns the rendered SQL string; run() executes the query.","wrong":"template.run('example-1', [1], callback);","symbol":"render","correct":"template.render('example-1', [1]);"}],"quickstart":{"code":"const path = require('path');\nconst SQLTemplate = require('node-sql-template');\n\n// Create a SQL file 'example.sql' with content: SELECT ?\nconst options = {\n  template: {\n    dir: path.resolve(__dirname, './sql'),\n    ext: 'sql'\n  },\n  connection: {\n    host: 'localhost',\n    user: 'root',\n    password: 'root'\n  },\n  isDebug: true\n};\n\nconst template = SQLTemplate.forge(options);\n\n// Render only\ntemplate.render('example', [1], (err, sql) => {\n  console.log('SQL:', sql);\n});\n\n// Execute query with callback\ntemplate.run('example', [1], (err, rows) => {\n  console.log('Rows:', rows);\n  template.end();\n});","lang":"javascript","description":"Shows template rendering and query execution with a callback."},"warnings":[{"fix":"Install and use mysql2 instead of mysql; API is similar but more modern.","message":"The mysql package is deprecated. Consider using mysql2.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Run 'npm install mysql' alongside node-sql-template.","message":"In version 0.2.0, mysql became a peer dependency. You must install it separately.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Use environment variables and enforce TLS with ssl option.","message":"The password in options.connection is passed in plain text; ensure secure transport.","severity":"gotcha","affected_versions":"all"},{"fix":"Specify an existing directory with SQL files.","message":"The template dir must exist and contain .sql files; no default.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.2.3':16 'altern':54 'api':46 'cadenc':19 'connect':37 'debug':52 'differenti':44 'directori':26 'engin':9,70 'escap':30 'execut':33 'featur':62 'feature-rich':61 'file':23 'forge/run':48 'heavier':65 'javascript':66 'key':43 'knex':58 'like':55 'low':17 'mysql':41,68 'node':2 'node-sql-templ':1 'node.js':14 'output':53 'packag':42 'pool':38 'queri':11,34,71 'read':21 'releas':18 'render':27 'result':50 'rich':63 'runner':12 'simpl':6,45 'sql':3,7,22,67 'squel':56 'stream':49 'templat':4,8,69 'use':35 'valu':31 'version':15 'via':39","created_at":"2026-06-05T16:59:57.086958+00:00","updated_at":"2026-06-05T16:59:57.086958+00:00","problems":[{"fix":"Install mysql: npm install mysql","cause":"Missing peer dependency mysql.","error":"Cannot find module 'mysql'"},{"fix":"Use require instead of import.","cause":"Using import statement on CommonJS module.","error":"TypeError: template.render is not a function"},{"fix":"Add 'database' to options.connection, e.g., { database: 'mydb' }.","cause":"Missing database in connection options.","error":"Error: ER_NO_DB_ERROR: No database selected"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/adriano-di-giovanni/node-sql-template","github":"https://github.com/adriano-di-giovanni/node-sql-template","docs":null,"changelog":null,"pypi":null,"npm":"node-sql-template","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}