sql-fn (v0.0.1) generates JavaScript functions from SQL files, eliminating the need for an ORM. It parses .sql files in a directory and produces functions named after the files, with smart defaults: single-row return for CRUD prefixes (findOne, updateOne, createOne, deleteOne) and automatic transaction wrapping for UPDATE, DELETE, INSERT. Options allow overriding these rules globally or per query, including cursor support for streaming. Released with sparse cadence, it targets Node.js >=12 and is loosely inspired by Clojure's HugSQL. Unlike traditional ORMs, it offers zero abstraction overhead and direct SQL control.
npm install sql-fnNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Generates and uses SQL functions from a directory of .sql files with custom options for transaction and single-row behavior.
Use withOptions({ ... }) to wrap options, e.g., generate('./sql', withOptions({ tx: false })).Always do: const { generate } = require('sql-fn')(config); or await import('sql-fn').then(m => m({config})).Ensure cursor queries do not expect transaction isolation or single-row return.
Override with 'withOptions' to explicitly set 'single' and 'tx' per query.
Pin exact version and review changelog before upgrading.
const { generate } = require('sql-fn')(config); OR await import('sql-fn').then(m => m({config})).then(m => m.generate)Check database connection parameters: host, port, user, password, database.
const { withOptions } = require('sql-fn')(config); or destructure after calling the default export.Override using withOptions({ myQuery: {single: true} }).Upgrade Node.js to v12 or higher.