{"id":43229,"library":"msql","title":"msql","description":"msql is a lightweight JavaScript library for programmatically building SQL query strings (SELECT, INSERT, UPDATE, DELETE) without raw string concatenation, reducing SQL injection risk. Version 1.0.3 is the latest stable release. It supports a fluent API with methods like .where(), .field(), .config() for primary key assignment, enabling chainable query construction. Unlike ORMs, msql outputs raw SQL strings and targets Node.js with CommonJS only (no ESM). It is suitable for simple projects needing dynamic SQL generation, but lacks async support, prepared statements, and broader SQL dialect coverage.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","sql","mysql","msql"],"install":[{"cmd":"npm install msql","lang":"bash","label":"npm"},{"cmd":"yarn add msql","lang":"bash","label":"yarn"},{"cmd":"pnpm add msql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"msql is CommonJS-only; ESM imports will fail. Use require() in Node.js.","wrong":"import msql from 'msql'","symbol":"default","correct":"const msql = require('msql')"},{"note":"msql() is a factory function, not a constructor. Do not use 'new'.","wrong":"const qb = new msql('tableName')","symbol":"default (with table name)","correct":"const qb = msql('tableName')"},{"note":"The config option is named 'pk', not 'primaryKey' or 'key'.","wrong":"msql('tableName').config({ primaryKey: 'id' })","symbol":"config (optional primary key)","correct":"msql('tableName').config({ pk: 'id' })"}],"quickstart":{"code":"const msql = require('msql');\n\n// Create a query builder for the 'users' table\nconst qb = msql('users').config({ pk: 'id' });\n\n// SELECT with where\nvar sqlSelect = qb.where({ id: 1 }).select();\nconsole.log(sqlSelect); // SELECT * FROM users where id = 1\n\n// INSERT\nvar sqlInsert = msql('users').create({ name: 'Alice', age: 30 });\nconsole.log(sqlInsert); // INSERT INTO users(name, age) VALUES (\"Alice\", 30)\n\n// UPDATE\nvar sqlUpdate = msql('users').config({ pk: 'id' }).update({ id: 1, name: 'Bob' });\nconsole.log(sqlUpdate); // UPDATE users SET name = \"Bob\" where id = 1\n\n// DELETE\nvar sqlDelete = msql('users').delete({ id: 1 });\nconsole.log(sqlDelete); // DELETE FROM users where id = 1","lang":"javascript","description":"Demonstrates building SQL queries (SELECT, INSERT, UPDATE, DELETE) using msql's fluent API with configurable primary key."},"warnings":[{"fix":"Manually sanitize or escape user-provided values before passing to msql methods, or switch to a library that supports prepared statements.","message":"Values are not sanitized; library does not use parameterized queries or escaping. Direct string interpolation can lead to SQL injection if values come from user input.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a new variable: `const imgTable = msql('img').config(...)` and continue with imgTable instead of reusing Msql.","message":"The README shows deprecated usage: `var Msql = Msql('img').config(...)` reassigns the Msql variable, which overwrites the original require reference. This is error-prone.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Always call .config({ pk: 'id' }) before using .find(value) where value is not an object.","message":"The `find` method with a primary key value requires that `config({ pk: ... })` has been called on the same query builder instance; otherwise find({ id: 1 }) works but find(1) will produce incorrect SQL.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a more full-featured SQL builder library like knex.js if you need advanced query generation.","message":"msql does not support JOINs, subqueries, aggregate functions, or LIMIT/OFFSET clauses natively. Complex SQL must be manually written.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'1.0.3':27 'api':37 'assign':47 'async':79 'broader':84 'build':10 'chainabl':49 'commonj':63 'concaten':21 'config':43 'construct':51 'coverag':87 'delet':17 'dialect':86 'dynam':74 'enabl':48 'esm':66 'field':42 'fluent':36 'generat':76 'inject':24 'insert':15 'javascript':6,88 'key':46 'lack':78 'latest':30 'librari':7 'lightweight':5 'like':40 'method':39 'msql':1,2,54,91 'mysql':90 'need':73 'node.js':61 'orm':53 'output':55 'prepar':81 'primari':45 'programmat':9 'project':72 'queri':12,50 'raw':19,56 'reduc':22 'releas':32 'risk':25 'select':14 'simpl':71 'sql':11,23,57,75,85,89 'stabl':31 'statement':82 'string':13,20,58 'suitabl':69 'support':34,80 'target':60 'unlik':52 'updat':16 'version':26 'without':18","created_at":"2026-06-05T16:58:48.353100+00:00","updated_at":"2026-06-05T16:58:48.353100+00:00","problems":[{"fix":"Replace with const msql = require('msql');","cause":"Using ES6 import syntax 'import msql from 'msql'' on a CommonJS-only module.","error":"TypeError: msql is not a function"},{"fix":"Ensure you pass a valid value to .find() or call .where() before .select().","cause":"Calling .find() with no arguments or with an undefined primary key value.","error":"SELECT * FROM users where id = undefined"},{"fix":"Use a different variable name: const img = msql('img').config(...);","cause":"Overwriting the 'Msql' variable in the example: var Msql = Msql('img').config(...) redefines Msql as a query builder, losing the require reference.","error":"Uncaught ReferenceError: Msql is not defined"},{"fix":"Ignore the discrepancy; the library will use the actual value provided in the data object.","cause":"The README example has a mismatch: the data object has con: 'This is content' but the output shows 'This is a new record'. This is a documentation bug.","error":"INSERT INTO users(path, con) VALUES (\"path1\", \"This is a new record\") -> but content says 'This is content'"}],"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":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"msql","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}}