Registry / database / nodebatis

nodebatis

JSON →
library2.4.2jsnpmunverified

NodeBatis is a SQL-style ORM for Node.js, inspired by MyBatis on Java. It allows developers to write SQL statements in YAML files and execute them via namespaced keys. Version 2.4.2 is the latest stable release, compatible with Node >=7.6.0. It currently supports only MySQL. Key differentiators include first-class SQL support, parameter binding with :paramName, DDL support with ::ddl, SQL inheritance via {{namespace.key}}, conditional SQL fragments (if), and for-loop SQL generation for batch operations. It also offers transaction management and connection pooling. Compared to traditional ORMs like Sequelize or TypeORM, NodeBatis gives full control over SQL, avoiding ORM abstraction overhead.

npm install nodebatis
INSTALL
IMPORT
SIG · NODEBATIS
N
nodebatis
databasejavascriptv2.4.2
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.

NodeBatis
import NodeBatis from 'nodebatis'
const NodeBatis = require('nodebatis')
Default import from ESM. CommonJS require also works but is non-standard.
path
import path from 'path'
Required to resolve YAML directory path.
nodebatis instance
const nodebatis = new NodeBatis(path.resolve(__dirname, './yaml'), config)
const nodebatis = new NodeBatis('./yaml', config)
YAML directory must be an absolute path. Use path.resolve.

Initialize NodeBatis with MySQL config, execute a named query from YAML, and handle results asynchronously.

import NodeBatis from 'nodebatis'; import path from 'path'; const nodebatis = new NodeBatis(path.resolve(__dirname, './yaml'), { debug: true, dialect: 'mysql', host: '127.0.0.1', port: 3306, database: 'test', user: 'root', password: process.env.DB_PASSWORD ?? 'root' }); async function findByAge(age) { const result = await nodebatis.execute('test.findByAge', { age }); return result; } findByAge(18).then(rows => console.log(rows));
Debug
Known issues
gotchaYAML directory must be an absolute path; relative paths may fail silently
fix
Use path.resolve(__dirname, 'yaml') or an absolute path string.
affects: >=2.0.0
gotchaOnly MySQL dialect is supported; attempts to use other dialects will throw errors
fix
Set dialect: 'mysql' or wait for future versions.
affects: >=2.0.0
gotchaParameter binding uses :paramName syntax, not ? or $1
fix
Use :paramName in SQL and pass an object with matching keys.
affects: >=2.0.0
deprecatedNode <7.6.0 is not supported; old versions (<=2.2.1) are deprecated
fix
Upgrade Node to >=7.6.0 or use an older NodeBatis version (not recommended).
affects: <=2.2.1
Errors
Common errors & fixes
Error: Cannot find module 'nodebatis'
nodebatis not installed or missing from package.json
fix
Run: npm install nodebatis --save
Error: ENOENT: no such file or directory, open '...'
YAML directory path is invalid or relative
fix
Provide an absolute path using path.resolve(__dirname, './yaml')
Error: Dialect 'postgresql' is not supported
Only 'mysql' is supported as dialect
fix
Change config.dialect to 'mysql'
Upgrade
Version history
2.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
nodebatis — npm install nodebatis · libregistry