<?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.TableTriggerDocumentMapper">

    <resultMap type="com.salpa.subject.domain.MonitorTableTriggerDocument" id="MonitorTableTriggerDocumentResult">
        <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="timing"              column="timing"                />
        <result property="manipulation"             column="manipulation"              />
        <result property="statement"             column="statement"              />
        <result property="triggerCreateAt"             column="trigger_create_at"              />
        <result property="createAt"             column="create_at"              />
    </resultMap>

    <select id="getTableTrigger" resultMap="MonitorTableTriggerDocumentResult">
        SELECT id,table_document_id,database_document_id,`name`,timing,manipulation,trigger_create_at,create_at
        FROM monitor_table_trigger_document WHERE database_document_id = #{id}
    </select>

    <select id="getTableTriggerByTableId" resultMap="MonitorTableTriggerDocumentResult">
        SELECT id,table_document_id,database_document_id,`name`,timing,manipulation,trigger_create_at,create_at
        FROM monitor_table_trigger_document WHERE table_document_id = #{id}
    </select>

    <insert id="insertTableTrigger">
        insert into monitor_table_trigger_document(
        <if test="tableDocumentId != null">table_document_id,</if>
        <if test="name != null and name != ''">`name`,</if>
        <if test="timing != null and timing != ''">timing,</if>
        <if test="manipulation != null and manipulation != ''">manipulation,</if>
        <if test="statement != null and statement != ''">statement,</if>
        <if test="triggerCreateAt != null and triggerCreateAt != ''">trigger_create_at,</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="timing != null and timing != ''">#{timing},</if>
        <if test="manipulation != null and manipulation != ''">#{manipulation},</if>
        <if test="statement != null and statement != ''">#{statement},</if>
        <if test="triggerCreateAt != null and triggerCreateAt != ''">#{triggerCreateAt},</if>
        <if test="databaseDocumentId != null">#{databaseDocumentId}</if>
        )
    </insert>
</mapper>