1.0.2 • Published 6 years ago

mybatis-node v1.0.2

Weekly downloads
5
License
BSD-2-Clause
Repository
github
Last release
6 years ago

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:

1) Write your MyBatis mapping files:

To Know how to write mapping files read: http://mybatis.github.io/mybatis-3/

2) Create a connection to your database

const mysql = require('mysql');
const pool = mysql.createPool({
    host     : 'localhost',
    user     : '****',
    password : '****',
    database : 'database',
    typeCast : true,
    multipleStatements: true
});

3) 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.

4) 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.