{"id":44160,"library":"yesql","title":"yesql","description":"A Node.js library for reading named SQL statements from .sql files and using named parameters in prepared statements. Version 7.0.0 supports PostgreSQL, MySQL/MariaDB, and raw/SQLite drivers. It parses SQL files with named queries and converts named parameters (e.g. :name, $name) into database-specific parameterized formats. Key differentiator: it handles multiple database dialects, supports quoted strings, missing parameter handling, and throws on duplicate query names. Released on npm, maintained, with active development history.","status":"active","version":"7.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/pihvi/yesql","tags":["javascript","sql","named","parameter","prepared","statement","pg","postgres","node-pg"],"install":[{"cmd":"npm install yesql","lang":"bash","label":"npm"},{"cmd":"yarn add yesql","lang":"bash","label":"yarn"},{"cmd":"pnpm add yesql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The default export is a factory function that takes a directory path and options object.","wrong":"const yesql = require('yesql');\nconst sql = yesql('/path/to/sql')()","symbol":"default (require function)","correct":"const sql = require('yesql')('/path/to/sql', {type: 'pg'})"},{"note":"Named exports are available as .mysql and .pg.","wrong":"const { mysql } = require('yesql')","symbol":"mysql","correct":"const named = require('yesql').mysql"},{"note":"Use .pg for PostgreSQL prepared statements.","wrong":"const pg = require('yesql').pg","symbol":"pg","correct":"const named = require('yesql').pg"}],"quickstart":{"code":"const sql = require('yesql')('/path/to/sql', {type: 'pg'});\nconst pg = require('pg');\nconst client = new pg.Client();\n// query with named parameters\nclient.query(sql.updatePokemon({price: 5, name: 'Pikachu'}), (err, res) => {\n  if (err) throw err;\n  console.log(res.rows);\n});\n// also works without directory: use named directly\nconst named = require('yesql').pg;\nconst query = named('UPDATE pokemon SET price = :price WHERE id = :id;');\nclient.query(query({price: 10, id: 1}), (err, res) => {\n  if (err) throw err;\n});","lang":"javascript","description":"Demonstrates reading SQL from files and using named parameters with PostgreSQL."},"warnings":[{"fix":"Ensure each query name in .sql files is unique, remove or rename duplicates.","message":"Duplicate SQL query names now throw an error (since v5.0.0). Before v5.0.0 duplicates silently overwrote.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"If you rely on missing parameters being an error, do not set useNullForMissing: true. If you want NULLs, continue using it.","message":"The 'useNullForMissing' flag changes the behavior of missing parameters, potentially masking errors by inserting NULL instead of throwing.","severity":"deprecated","affected_versions":">=4.1.0"},{"fix":"Pass a directory path: yesql('./sql/'), not yesql('./sql/query.sql').","message":"The directory path passed to yesql() should be the path to the SQL files directory, not the files themselves. The library reads all .sql files in that directory.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the correct parameter syntax for your database type. For PG/MySQL use :name; for SQLite use $name; for raw SQL use ?.","message":"For PostgreSQL, the named parameter syntax uses :name (colon prefix). For MySQL, it also uses :name. For SQLite, use $name. This is database-specific and not interchangeable.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'7.0.0':21 'activ':72 'convert':36 'databas':44,53 'database-specif':43 'develop':73 'dialect':54 'differenti':49 'driver':27 'duplic':64 'e.g':39 'file':12,31 'format':47 'handl':51,60 'histori':74 'javascript':75 'key':48 'librari':4 'maintain':70 'miss':58 'multipl':52 'mysql/mariadb':24 'name':7,15,33,37,40,41,66,77 'node':84 'node-pg':83 'node.js':3 'npm':69 'paramet':16,38,59,78 'parameter':46 'pars':29 'pg':81,85 'postgr':82 'postgresql':23 'prepar':18,79 'queri':34,65 'quot':56 'raw/sqlite':26 'read':6 'releas':67 'specif':45 'sql':8,11,30,76 'statement':9,19,80 'string':57 'support':22,55 'throw':62 'use':14 'version':20 'yesql':1","created_at":"2026-06-05T17:03:16.504896+00:00","updated_at":"2026-06-05T17:03:16.504896+00:00","problems":[{"fix":"npm install yesql","cause":"yesql is not installed.","error":"Error: Cannot find module 'yesql'"},{"fix":"Use sql.getPokemon({param: value}) instead of sql.getPokemon.","cause":"Calling a query without parenthesized arguments. yesql returns functions that must be called with parameters object.","error":"TypeError: sql.getPokemon is not a function"},{"fix":"Rename one of the queries to have a unique name.","cause":"Two queries in .sql files have the same comment-based name.","error":"Error: Duplicate query name found: getPokemon"}],"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/pihvi/yesql#readme","github":"ssh://git@github.com/pihvi/yesql","docs":null,"changelog":null,"pypi":null,"npm":"yesql","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}}