<?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.salpa.subject.mapper.TableIndexDocumentMapper">

    <resultMap type="com.salpa.subject.domain.MonitorTableIndexDocument" id="MonitorTableIndexDocumentResult">
        <id     property="id"            column="id"             />
        <id     property="tableDocumentId"            column="table_document_id"             />
        <result property="databaseDocumentId"          column="database_document_id"           />
        <result property="name"   column="name"    />
        <result property="unique"              column="is_unique"                />
        <result property="columnNameArray"             column="column_name_array"              />
        <result property="createAt"             column="create_at"              />
    </resultMap>

    <select id="getTableIndex" resultMap="MonitorTableIndexDocumentResult">
        SELECT id,table_document_id,database_document_id,`name`,is_unique,column_name_array,create_at
        FROM monitor_table_index_document WHERE database_document_id = #{id}
    </select>

    <select id="getTableIndexByTableId" resultMap="MonitorTableIndexDocumentResult">
        SELECT id,table_document_id,database_document_id,`name`,is_unique,column_name_array,create_at
        FROM monitor_table_index_document WHERE table_document_id = #{id}
    </select>

    <insert id="insertTableIndex">
        insert into monitor_table_index_document(
        <if test="tableDocumentId != null">table_document_id,</if>
        <if test="name != null and name != ''">`name`,</if>
        <if test="unique != null">is_unique,</if>
        <if test="columnNameArray != null and columnNameArray != ''">column_name_array,</if>
        <if test="databaseDocumentId != null">database_document_id</if>
        )values(
        <if test="tableDocumentId != null">#{tableDocumentId},</if>
        <if test="name != null and name != ''">#{name},</if>
        <if test="unique != null">#{unique},</if>
        <if test="columnNameArray != null and columnNameArray != ''">#{columnNameArray},</if>
        <if test="databaseDocumentId != null">#{databaseDocumentId}</if>
        )
    </insert>
</mapper>