<?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.gitee.gen.mapper.DatasourceConfigMapper">
    <resultMap id="BaseResultMap" type="com.gitee.gen.entity.DatasourceConfig">
        <result column="id" property="id" />
        <result column="db_type" property="dbType" />
        <result column="db_desc" property="dbDesc" />
        <result column="driver_class" property="driverClass" />
        <result column="db_name" property="dbName" />
        <result column="schema_name" property="schemaName" />
        <result column="host" property="host" />
        <result column="port" property="port" />
        <result column="username" property="username" />
        <result column="password" property="password" />
        <result column="is_deleted" property="isDeleted" />
        <result column="package_name" property="packageName" />
        <result column="del_prefix" property="delPrefix" />
        <result column="group_id" property="groupId" />
        <result column="author" property="author" />
        <result column="db_group_name" property="dbGroupName" />
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id
        , t.db_type
        , t.db_desc
        , t.driver_class
        , t.db_name
        , t.schema_name
        , t.host
        , t.port
        , t.username
        , t.password
        , t.is_deleted
        , t.package_name
        , t.del_prefix
        , t.group_id
        , t.author
        , t.db_group_name
        </sql>

    <!-- 查询全部 -->
    <select id="listAll" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns" />
        FROM datasource_config t
        where is_deleted=0
    </select>

    <!-- 根据主键获取单条记录 -->
    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        SELECT
        <include refid="baseColumns" />
        FROM datasource_config t
        WHERE id = #{id}
    </select>

    <!-- 插入全部字段 -->
    <insert id="insert" parameterType="com.gitee.gen.entity.DatasourceConfig"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO datasource_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            db_type,
            db_desc,
            driver_class,
            db_name,
            schema_name,
            host,
            port,
            username,
            password,
            is_deleted,
            package_name,
            del_prefix,
            group_id,
            author,
            db_group_name,
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            #{dbType},
            #{dbDesc},
            #{driverClass},
            #{dbName},
            #{schemaName},
            #{host},
            #{port},
            #{username},
            #{password},
            #{isDeleted},
            #{packageName},
            #{delPrefix},
            #{groupId},
            #{author},
            #{dbGroupName},
        </trim>
    </insert>

    <!-- 插入不为NULL的字段 -->
    <insert id="insertIgnoreNull" parameterType="com.gitee.gen.entity.DatasourceConfig"
            keyProperty="id" keyColumn="id" useGeneratedKeys="true"
    >
        INSERT INTO datasource_config
        <trim prefix="(" suffix=")" suffixOverrides=",">

            <if test="dbType != null">
                db_type,
            </if>
            <if test="dbDesc != null">
                db_desc,
            </if>
            <if test="driverClass != null">
                driver_class,
            </if>
            <if test="dbName != null">
                db_name,
            </if>
            <if test="schemaName != null">
                schema_name,
            </if>
            <if test="host != null">
                host,
            </if>
            <if test="port != null">
                port,
            </if>
            <if test="username != null">
                username,
            </if>
            <if test="password != null">
                password,
            </if>
            <if test="isDeleted != null">
                is_deleted,
            </if>
            <if test="packageName != null">
                package_name,
            </if>
            <if test="delPrefix != null">
                del_prefix,
            </if>
            <if test="groupId != null">
                group_id,
            </if>
            <if test="author != null">
                author,
            </if>
            <if test="dbGroupName != null">
                db_group_name,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="dbType != null" >
                #{dbType},
            </if>
            <if test="dbDesc != null" >
                #{dbDesc},
            </if>
            <if test="driverClass != null" >
                #{driverClass},
            </if>
            <if test="dbName != null" >
                #{dbName},
            </if>
            <if test="schemaName != null" >
                #{schemaName},
            </if>
            <if test="host != null" >
                #{host},
            </if>
            <if test="port != null" >
                #{port},
            </if>
            <if test="username != null" >
                #{username},
            </if>
            <if test="password != null" >
                #{password},
            </if>
            <if test="isDeleted != null" >
                #{isDeleted},
            </if>
            <if test="packageName != null" >
                #{packageName},
            </if>
            <if test="delPrefix != null" >
                #{delPrefix},
            </if>
            <if test="groupId != null" >
                #{groupId},
            </if>
            <if test="author != null" >
                #{author},
            </if>
            <if test="dbGroupName != null" >
                #{dbGroupName},
            </if>
        </trim>
    </insert>

    <!-- 更新,更新全部字段 -->
    <update id="update" parameterType="com.gitee.gen.entity.DatasourceConfig">
        UPDATE datasource_config
        <set>
            db_type=#{dbType},
            db_desc=#{dbDesc},
            driver_class=#{driverClass},
            db_name=#{dbName},
            schema_name=#{schemaName},
            host=#{host},
            port=#{port},
            username=#{username},
            password=#{password},
            is_deleted=#{isDeleted},
            package_name=#{packageName},
            del_prefix=#{delPrefix},
            group_id=#{groupId},
            author=#{author},
            db_group_name=#{dbGroupName},
        </set>
        WHERE id = #{id}
    </update>


    <!-- 更新不为NULL的字段 -->
    <update id="updateIgnoreNull" parameterType="com.gitee.gen.entity.DatasourceConfig">
        UPDATE datasource_config
        <set>
            <if test="dbType != null" >
                db_type=#{dbType},
            </if>
            <if test="dbDesc != null" >
                db_desc=#{dbDesc},
            </if>
            <if test="driverClass != null" >
                driver_class=#{driverClass},
            </if>
            <if test="dbName != null" >
                db_name=#{dbName},
            </if>
            <if test="schemaName != null" >
                schema_name=#{schemaName},
            </if>
            <if test="host != null" >
                host=#{host},
            </if>
            <if test="port != null" >
                port=#{port},
            </if>
            <if test="username != null" >
                username=#{username},
            </if>
            <if test="password != null" >
                password=#{password},
            </if>
            <if test="isDeleted != null" >
                is_deleted=#{isDeleted},
            </if>
            <if test="packageName != null" >
                package_name=#{packageName},
            </if>
            <if test="delPrefix != null" >
                del_prefix=#{delPrefix},
            </if>
            <if test="groupId != null" >
                group_id=#{groupId},
            </if>
            <if test="author != null" >
                author=#{author},
            </if>
            <if test="dbGroupName != null" >
                db_group_name=#{dbGroupName},
            </if>
        </set>
        WHERE id = #{id}
    </update>


    <!-- 根据主键删除记录 -->
    <delete id="delete" parameterType="com.gitee.gen.entity.DatasourceConfig">
		UPDATE datasource_config
		SET is_deleted=1
		WHERE id = #{id}
	</delete>


</mapper>