<?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="org.hongxi.whatsmars.shardingsphere.repository.OrderItemRepository">
    <resultMap id="baseResultMap" type="org.hongxi.whatsmars.shardingsphere.entity.OrderItem">
        <result column="order_item_id" property="orderItemId" jdbcType="INTEGER"/>
        <result column="order_id" property="orderId" jdbcType="INTEGER"/>
        <result column="user_id" property="userId" jdbcType="INTEGER"/>
        <result column="status" property="status" jdbcType="VARCHAR"/>
    </resultMap>

    <update id="createIfNotExistsTable">
        CREATE TABLE IF NOT EXISTS t_order_item (order_item_id BIGINT AUTO_INCREMENT, order_id BIGINT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id));
    </update>

    <update id="truncateTable">
        TRUNCATE TABLE t_order_item;
    </update>
    
    <update id="dropTable">
        DROP TABLE IF EXISTS t_order_item;
    </update>
    
    <insert id="insert" useGeneratedKeys="true" keyProperty="orderItemId">
        INSERT INTO t_order_item (
          order_id, user_id, status
        )
        VALUES (
        #{orderId,jdbcType=INTEGER},
        #{userId,jdbcType=INTEGER},
        #{status,jdbcType=VARCHAR}
        )
    </insert>
    
    <delete id="delete">
        DELETE FROM t_order_item WHERE order_id = #{orderId,jdbcType=INTEGER}
    </delete>
    
    <select id="selectAll" resultMap="baseResultMap">
        SELECT
        i.*
        FROM
        t_order o, t_order_item i
        WHERE
        o.order_id = i.order_id
    </select>
</mapper>
