<?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.boman.gen.mapper.TableSqlMapper">
    
    <resultMap type="TableSql" id="TableSqlResult">
        <result property="id"       column="id"      />
        <result property="tableId"           column="table_id"           />
        <result property="createSql"           column="create_sql"           />
        <result property="createLog"           column="create_log"           />
        <result property="createBy"       column="create_by"      />
        <result property="createTime"     column="create_time"    />
        <result property="updateBy"       column="update_by"      />
        <result property="updateTime"     column="update_time"    />
        <result property="remark"     column="remark"    />
        <result property="isDel"     column="is_del"    />
	</resultMap>

	
	<sql id="selectTableSqlVo">
        select id, table_id, create_sql, create_log, create_by, create_time, update_by, update_time, remark, is_del from table_sql
    </sql>

    <select id="selectTableSqlByTableId" parameterType="Long" resultMap="TableSqlResult">
        <include refid="selectTableSqlVo"></include>
        where table_id = #{id} limit 1
    </select>
    <insert id="insertTableSql" parameterType="TableSql" useGeneratedKeys="true" keyProperty="id">
        insert into table_sql (
			<if test="tableId != null and tableId != ''">table_id,</if>
			<if test="createSql != null and createSql != ''">create_sql,</if>
			<if test="createLog != null and createLog != ''">create_log,</if>
			<if test="remark != null and remark != ''">remark,</if>
			<if test="createBy != null and createBy != ''">create_by,</if>
			create_time
         )values(
			<if test="tableId != null and tableId != ''">#{tableId},</if>
			<if test="createSql != null and createSql != ''">#{createSql},</if>
			<if test="createLog != null and createLog != ''">#{createLog},</if>
			<if test="remark != null and remark != ''">#{remark},</if>
			<if test="createBy != null and createBy != ''">#{createBy},</if>
			sysdate()
         )
    </insert>


    <update id="updateTableSql" parameterType="TableSql">
        update table_sql
        <set>
            <if test="tableId != null">table_id = #{tableId},</if>
            <if test="createSql != null and createSql != ''">create_sql = #{createSql},</if>
            <if test="createLog != null and createLog != ''">create_log = #{createLog},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>
</mapper>