使用方法
创建连接
- 因为它只支持非连接池所以每次都要创建连接
let dao = new MySqlDaoContext({
    charset: "utf8",
    host: "localhost",
    user: "root",
    password: "root",
    database: "test",
  });
  await dao.initialize();
  dao = initDaoContext({ dao });
创建实体类
注意这里的initDaoContext还有一个可选参数types,用来关联实体类,实体类示例代码如下:
 // 定义实体类
class SystemMst extends AuroraEntity {
  @DBColumn({ idType: 'uniqueIndex' })
  public systemId!: string | null
  public systemName: string | null = null
}
xml
<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  <mapper namespace="esbatis.test">
      <select id="selectOne">
          SELECT
              *
          FROM
              car AS t1
      </select>
  </mapper>
-  前两行是XML文件的声明部分,用于指定XML版本和编码方式。具体解释如下: 
-  <?xml version="1.0" encoding="UTF-8"?>:这是XML文件的声明,表示使用XML的版本为1.0,并使用UTF-8编码。
-  <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">:这是DTD(Document Type Definition)声明,用于指定XML文件的文档类型。在这里,它指定了MyBatis的Mapper文件的DTD,版本为3.0。
-  namespace和id我的理解是方便调用; 
-  主体部分必须要用mapper作为父标签,里面的子标签据作者的博客中记载支持以下标签: 
 insert
 select
 update
 delete
 sql
 where
 set
 trim
 if
 foreach
 bind
 choose/when/otherwise
 include这里的xml如果要放在单独的文件里按如下方法使用 
const sqlTemplate = require("es-batis").default;
const searchSql = sqlTemplate`
  <mapper namespace="esbatis.test">
      <select id="selectOne">
          SELECT
              *
          FROM
              car AS t1
          <where>
            <if test="sim != null">
              and t1.sim = #{sim}
            </if>
          </where>      
      </select>
  </mapper>
`;
module.exports = {
  searchSql,
};
执行sql的方法
const mapping = require("./mappingxml"); // 放xml的文件
let sqlResults = await mapping.searchSql.selectList(
    "esbatis.test.selectOne",
    {
      sim: 159951,
    }
  );
方法列表:
![[图片]](https://img-blog.csdnimg.cn/a18da8a574f849e3af726465fc02e2be.png)
- selectOne:只支持结果唯一的,结果不唯一就报错(没查到不会报错,返回null)
- selectList:支持任意数量的结果
已知问题:
- 不支持连接池
- 不支持一对多(https://github.com/herotangabc/es-batis/issues/1)



















