backend/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdEngineDDLMapper.xml

101 lines
3.4 KiB
XML

<?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="cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper">
<!-- 创建数据库 -->
<update id="createDatabase" parameterType="String">
CREATE DATABASE IF NOT EXISTS ${dataBaseName}
</update>
<!-- 创建超级表 -->
<update id="createSuperTable">
CREATE STABLE IF NOT EXISTS ${dataBaseName}.${superTableName}
<foreach item="item" collection="columns" separator=","
open="(" close=")">
${item.fieldName} ${item.dataType}
<if test="item.dataLength > 0">
(${item.dataLength})
</if>
</foreach>
TAGS
<foreach item="item" collection="tags" separator=","
open="(" close=")">
${item.fieldName} ${item.dataType}
<if test="item.dataLength > 0">
(${item.dataLength})
</if>
</foreach>
</update>
<!-- 查看超级表 -->
<select id="showSuperTables" resultType="java.util.Map">
SHOW ${dataBaseName}.STABLES LIKE '${superTableName}'
</select>
<!-- 描述超级表结构 -->
<select id="describeSuperTable" resultType="java.util.Map">
DESCRIBE ${dataBaseName}.${superTableName}
</select>
<!-- 为超级表添加列 -->
<update id="addColumnForSuperTable">
ALTER STABLE ${dataBaseName}.${superTableName} ADD COLUMN ${column.fieldName} ${column.dataType}
<if test="column.dataLength > 0">
(${column.dataLength})
</if>
</update>
<!-- 为超级表删除列 -->
<update id="dropColumnForSuperTable">
ALTER STABLE ${dataBaseName}.${superTableName} DROP COLUMN ${column.fieldName}
</update>
<!-- 修改列宽 -->
<update id="modifyColumnWidthForSuperTable">
ALTER STABLE ${dataBaseName}.${superTableName} MODIFY COLUMN ${column.fieldName} ${column.dataType}
<if test="column.dataLength > 0">
(${column.dataLength})
</if>
</update>
<!-- 为超级表添加标签 -->
<update id="addTagForSuperTable">
ALTER STABLE ${dataBaseName}.${superTableName} ADD TAG ${tag.fieldName} ${tag.dataType}
<if test="tag.dataLength > 0">
(${tag.dataLength})
</if>
</update>
<!-- 为超级表删除标签 -->
<update id="dropTagForSuperTable">
ALTER STABLE ${dataBaseName}.${superTableName} DROP TAG ${tag.fieldName}
</update>
<!-- 创建子表 -->
<update id="createTable">
CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
USING ${dataBaseName}.${superTableName}
TAGS
<foreach item="item" collection="tags" separator=","
open="(" close=")">
#{item.fieldValue}
</foreach>
</update>
<!-- 创建子表,带有 TAGS -->
<update id="createTableWithTags">
CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
USING ${dataBaseName}.${superTableName}
<foreach item="item" collection="tags" separator="," open="(" close=")">
#{item.fieldName}
</foreach>
TAGS
<foreach item="item" collection="tags" separator=","
open="(" close=")">
#{item.fieldValue}
</foreach>
</update>
</mapper>