mybatis-node
v1.0.2
Published
MyBatisNodeJs is a port from the The MyBatis Java data mapper framework for Node.Js.
Downloads
10
Maintainers
Readme
MyBatisNodeJs
MyBatisNodeJs is a port from the The MyBatis data mapper framework for Node.Js.
MyBatisNodeJs understands the same xml files as input like MyBatis Java.
- How to use:
- Write your MyBatis mapping files:
To Know how to write mapping files read: http://mybatis.github.io/mybatis-3/
- Create a connection to your database
const mysql = require('mysql');
const pool = mysql.createPool({
host : 'localhost',
user : '****',
password : '****',
database : 'database',
typeCast : true,
multipleStatements: true
});
- To process the xml mapping files and get an sessionFactory instance:
const mybatis = require('mybatis-node');
const sessionFactory = new mybatis(pool).process(dir_xml);
The string variable dir_xml points to the MyBatis mapping files directory.
The variable sessionFactory has methods for selectOne, selectList, insert, update or delete objects.
- Select one object:
sessionFactory.selectOne('user.select', {id: 1}).then((user)=> {
//console.log(user);
});
The callback function is called with the user or null if not found.