<?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.ruoyi.druid.mapper.DruidConfigMapper">

    <resultMap type="DruidConfig" id="DruidConfigResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="version"    column="version"    />
        <result property="driverClass"    column="driver_class"    />
        <result property="comment"    column="comment"    />
        <result property="dataBase"    column="data_base"    />
        <result property="host"    column="host"    />
        <result property="port"    column="port"    />
        <result property="user"    column="user"    />
        <result property="password"    column="password"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDruidConfigVo">
        select id, type, version, driver_class, comment, data_base, host, port, user, password, create_by, create_time, update_by, update_time from tb_druid_config
    </sql>

    <select id="selectDruidConfigList" parameterType="DruidConfig" resultMap="DruidConfigResult">
        <include refid="selectDruidConfigVo"/>
        <where>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
            <if test="driverClass != null  and driverClass != ''"> and driver_class like concat('%', #{driverClass}, '%')</if>
            <if test="comment != null  and comment != ''"> and comment like concat('%', #{comment}, '%')</if>
            <if test="dataBase != null  and dataBase != ''"> and data_base = #{dataBase}</if>
            <if test="host != null  and host != ''"> and host = #{host}</if>
            <if test="port != null  and port != ''"> and port = #{port}</if>
            <if test="user != null  and user != ''"> and user = #{user}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
        </where>
    </select>

    <select id="selectDruidConfigById" parameterType="Long" resultMap="DruidConfigResult">
        <include refid="selectDruidConfigVo"/>
        where id = #{id}
    </select>

    <insert id="insertDruidConfig" parameterType="DruidConfig" useGeneratedKeys="true" keyProperty="id">
        insert into tb_druid_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null and type != ''">type,</if>
            <if test="version != null and version != ''">version,</if>
            <if test="driverClass != null and driverClass != ''">driver_class,</if>
            <if test="comment != null">comment,</if>
            <if test="dataBase != null and dataBase != ''">data_base,</if>
            <if test="host != null and host != ''">host,</if>
            <if test="port != null and port != ''">port,</if>
            <if test="user != null and user != ''">user,</if>
            <if test="password != null and password != ''">password,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null and type != ''">#{type},</if>
            <if test="version != null and version != ''">#{version},</if>
            <if test="driverClass != null and driverClass != ''">#{driverClass},</if>
            <if test="comment != null">#{comment},</if>
            <if test="dataBase != null and dataBase != ''">#{dataBase},</if>
            <if test="host != null and host != ''">#{host},</if>
            <if test="port != null and port != ''">#{port},</if>
            <if test="user != null and user != ''">#{user},</if>
            <if test="password != null and password != ''">#{password},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDruidConfig" parameterType="DruidConfig">
        update tb_druid_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="version != null and version != ''">version = #{version},</if>
            <if test="driverClass != null and driverClass != ''">driver_class = #{driverClass},</if>
            <if test="comment != null">comment = #{comment},</if>
            <if test="dataBase != null and dataBase != ''">data_base = #{dataBase},</if>
            <if test="host != null and host != ''">host = #{host},</if>
            <if test="port != null and port != ''">port = #{port},</if>
            <if test="user != null and user != ''">user = #{user},</if>
            <if test="password != null and password != ''">password = #{password},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDruidConfigById" parameterType="Long">
        delete from tb_druid_config where id = #{id}
    </delete>

    <delete id="deleteDruidConfigByIds" parameterType="String">
        delete from tb_druid_config where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
