<?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="com.lframework.xingyun.template.gen.mappers.SimpleDBMapper">

    <resultMap id="SimpleDBDto" type="com.lframework.xingyun.template.gen.dto.simpledb.SimpleDBDto">
        <result column="TABLE_SCHEMA" property="tableSchema"/>
        <result column="TABLE_NAME" property="tableName"/>
    </resultMap>

    <resultMap id="OriSimpleTableDto" type="com.lframework.xingyun.template.gen.dto.simpledb.OriSimpleTableDto">
        <id column="id" property="id"/>
        <result column="table_schema" property="tableSchema"/>
        <result column="table_name" property="tableName"/>
        <result column="engine" property="engine"/>
        <result column="table_collation" property="tableCollation"/>
        <result column="table_comment" property="tableComment"/>
        <result column="convert_type" property="convertType"/>
    </resultMap>

    <select id="selector" resultMap="SimpleDBDto">
        select TABLE_SCHEMA, TABLE_NAME from information_schema.tables
        <where>
            AND TABLE_SCHEMA = database()
            <if test="name != null and name != ''">
                AND TABLE_NAME LIKE CONCAT('%', #{name}, '%')
            </if>
        </where>
        ORDER BY TABLE_SCHEMA, TABLE_NAME
    </select>

    <select id="getByTableName" resultMap="OriSimpleTableDto">
        select
            TABLE_SCHEMA AS table_schema,
            TABLE_NAME AS table_name,
            ENGINE AS engine,
            TABLE_COLLATION AS table_collation,
            TABLE_COMMENT AS table_comment
        FROM information_schema.tables
        WHERE TABLE_SCHEMA = database()
        AND TABLE_NAME = #{tableName}
    </select>
    <select id="listByIds" resultMap="SimpleDBDto">
        select TABLE_SCHEMA, TABLE_NAME from information_schema.tables
        <where>
            AND TABLE_SCHEMA = database()
            AND TABLE_NAME IN <foreach collection="tableNames" open="(" separator="," close=")" item="item">#{item}</foreach>
        </where>
        ORDER BY TABLE_SCHEMA, TABLE_NAME
    </select>
</mapper>
