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

    <resultMap type="com.salpa.subject.domain.MonitorTableColumnDocument" id="MonitorTableColumnDocumentResult">
        <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="type"              column="type"                />
        <result property="dataType"             column="data_type"              />
        <result property="comment"             column="comment"              />
        <result property="defaultValue"             column="default_value"              />
        <result property="size"             column="size"              />
        <result property="decimalDigits"             column="decimal_digits"              />
        <result property="primaryKey"             column="is_primary_key"              />
        <result property="nullable"             column="nullable"              />
        <result property="autoIncrement"             column="auto_increment"              />
        <result property="createAt"             column="create_at"              />
    </resultMap>

    <select id="getTableColumn" resultMap="MonitorTableColumnDocumentResult">
        SELECT id,table_document_id,database_document_id,name,type,comment,decimal_digits,default_value,data_type,size,is_primary_key,nullable,auto_increment,create_at
        FROM monitor_table_column_document WHERE database_document_id = #{id}
    </select>

    <select id="getTableColumnByTableId" resultMap="MonitorTableColumnDocumentResult">
        SELECT id,table_document_id,database_document_id,name,type,comment,decimal_digits,default_value,data_type,size,is_primary_key,nullable,auto_increment,create_at
        FROM monitor_table_column_document WHERE table_document_id = #{id}
    </select>

    <insert id="insertTableColumn">
        insert into monitor_table_column_document(
        <if test="tableDocumentId != null">table_document_id,</if>
        <if test="name != null and name != ''">`name`,</if>
        <if test="type != null and type != ''">`type`,</if>
        <if test="comment != null and comment != ''">comment,</if>
        <if test="decimalDigits != null">decimal_digits,</if>
        <if test="defaultValue != null and defaultValue != ''">default_value,</if>
        <if test="dataType != null">data_type,</if>
        <if test="size != null">`size`,</if>
        <if test="primaryKey != null">is_primary_key,</if>
        <if test="nullable != null and nullable != ''">`nullable`,</if>
        <if test="autoIncrement != null and autoIncrement != ''">auto_increment,</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="type != null and type != ''">#{type},</if>
        <if test="comment != null and comment != ''">#{comment},</if>
        <if test="decimalDigits != null">#{decimalDigits},</if>
        <if test="defaultValue != null and defaultValue != ''">#{defaultValue},</if>
        <if test="dataType != null">#{dataType},</if>
        <if test="size != null">#{size},</if>
        <if test="primaryKey != null">#{primaryKey},</if>
        <if test="nullable != null and nullable != ''">#{nullable},</if>
        <if test="autoIncrement != null and autoIncrement != ''">#{autoIncrement},</if>
        <if test="databaseDocumentId != null">#{databaseDocumentId}</if>
        )
    </insert>
</mapper>