Registry / database / sqomplexity

sqomplexity

JSON →
library2.0.0jsnpmunverified

A metric library for calculating complexity scores of SQL queries, version 2.0.0, tailored for MySQL but compatible with other SQL dialects. It evaluates queries without requiring database schema knowledge, using a weighting system based on data complexity (computational complexity, row estimates, index usage) and control flow complexity (subqueries, joins, aggregations). Released under ISC license, maintained on GitHub with CI, and updated with minor versions. Differentiators: zero schema dependency, browser/Node/CLI support, customizable weight sets.

npm install sqomplexity
INSTALL
IMPORT
SIG · SQOMPLEXITY
S
sqomplexity
databasejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Sqomplexity
import { Sqomplexity } from 'sqomplexity'
import Sqomplexity from 'sqomplexity'
ESM-only; named export 'Sqomplexity' (class). Default import does not work.
Sqomplexity (CommonJS)
const { Sqomplexity } = require('sqomplexity')
const Sqomplexity = require('sqomplexity')
CommonJS via named destructuring. Node >=16 required.
new Sqomplexity(queries, weights?)
new Sqomplexity(['SELECT 1'])
new Sqomplexity('SELECT 1')
Constructor expects an array of query strings, not a single string.

Creates an instance with two queries and logs their complexity scores.

import { Sqomplexity } from 'sqomplexity'; (async () => { const sqomplexity = new Sqomplexity([ 'SELECT * FROM users', 'SELECT id, name FROM users WHERE active = 1 ORDER BY created_at DESC' ]); try { const scores = await sqomplexity.score(); console.log('Scores:', scores); } catch (err) { console.error('Error:', err.message); } })();
Debug
Known issues
breakingConstructor now expects an array of query strings (single string throws).
fix
Wrap single query in an array: new Sqomplexity(['SELECT 1'])
affects: >=2.0.0
breakingDrop of CommonJS support for require; only ESM imports allowed.
fix
Use import { Sqomplexity } from 'sqomplexity' instead of require
affects: >=2.0.0
gotchascore() is async; calling .score without await returns a Promise.
fix
Always await the score() call: await sqomplexity.score()
affects: >=1.0.0
gotchaQueries must be provided as an array; single array element is allowed.
fix
Ensure each query is a string inside an array, even for one query.
affects: >=2.0.0
gotchaWeights file path is required for custom weights as an absolute or relative path from CWD.
fix
Provide a valid JSON file path to --weights option in CLI.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: sqomplexity.score(...) is not a function
Calling score() incorrectly (e.g., as a property instead of method) or using old version with different API.
fix
Ensure you are using the correct export and call await sqomplexity.score()
SyntaxError: Cannot use import statement outside a module
Running code in a non-ESM environment (e.g., 'type: commonjs' in package.json).
fix
Set 'type': 'module' in package.json, or use .mjs extension.
Error: Queries must be an array of strings
Passing a single string instead of an array to constructor.
fix
new Sqomplexity(['SELECT 1']) instead of new Sqomplexity('SELECT 1')
Error: Invalid query provided
One of the query strings contains a syntax error that fails parsing.
fix
Validate SQL syntax; ensure proper quoting and no typos.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Meta
1
OpenAI (training)
1
Resources
sqomplexity — npm install sqomplexity · libregistry