Registry / database / sql-loader

sql-loader

JSON →
library1.0.3jsnpmunverified

SQL file loader for Node.js that loads .sql files from a directory into a JavaScript object. Version 1.0.3 is the current stable release. It supports relative and absolute paths, and recursively loads files from subdirectories to create nested objects. Simple alternative to other SQL loaders, no external dependencies, works with both CommonJS and ESM.

npm install sql-loader
INSTALL
IMPORT
SIG · SQL-LOADER
S
sql-loader
databasejavascriptv1.0.3
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.

default
import sqlLoader from 'sql-loader'
const sqlLoader = require('sql-loader')
ESM default import; the package has no named exports.
sqlLoader
const sqlLoader = require('sql-loader');
CommonJS require. The returned value is a function.
sqlLoader namespace
import * as sqlLoader from 'sql-loader'
ESM namespace import if you prefer style over default import.

Loads SQL files from directory and accesses them as object properties.

import sqlLoader from 'sql-loader'; const sql = sqlLoader('./path/to/sql/files'); // If you have a file 'users.sql' containing 'SELECT * FROM users' console.log(sql.users); // 'SELECT * FROM users' // If you have a directory structure: get/user.sql, insert/date.sql console.log(sql.get.user); // content of get/user.sql console.log(sql.insert.date); // content of insert/date.sql
Debug
Known issues
gotchaPaths passed to sqlLoader should be relative to the calling file, not to process.cwd().
fix
Use path.join(__dirname, './sql') to avoid ambiguity.
affects: >=1.0.0
gotchaFile names with dots other than .sql extension will be treated as part of the key; e.g., 'my.query.sql' becomes 'my.query' property.
fix
Use only alphanumeric and underscore in file names for predictable keys.
affects: >=1.0.0
breakingPackage does not support ES import by default; must use require or configure bundler.
fix
Use CommonJS require or transpile with bundler that handles CJS.
affects: <=1.0.3
Errors
Common errors & fixes
Error: Cannot find module 'sql-loader'
Package not installed or import path incorrect.
fix
Run 'npm install sql-loader' and ensure your import/require is correct.
TypeError: sqlLoader is not a function
Using default import in ESM incorrectly (e.g., import { sqlLoader } from 'sql-loader').
fix
Use 'import sqlLoader from 'sql-loader'' or 'const sqlLoader = require('sql-loader')'.
Error: ENOTDIR: not a directory, scandir
Provided path is not a directory.
fix
Ensure the path points to a directory containing .sql files.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

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