package com.vci.ubcs.ddl.mapper;
|
|
import com.vci.ubcs.ddl.bo.DdlTableBO;
|
import com.vci.ubcs.ddl.bo.DdlTableInDataBaseBO;
|
import org.apache.ibatis.annotations.*;
|
import org.springframework.stereotype.Repository;
|
|
import java.util.List;
|
|
/**
|
* Description: MySql数据库操作类
|
*
|
* @author LiHang
|
* @date 2023/4/24
|
*/
|
@Repository
|
public interface DdlMySqlMapper extends DdlMapper{
|
/**
|
* 创建数据库表
|
* @param tableName 表格的名称
|
* @param attributeSql 属性的sql
|
* @return 影响的行数
|
*/
|
@Update("create table ${tableName} ( ${attributeSql} )")
|
@ResultType(Integer.class)
|
int createTableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql);
|
|
/**
|
* 为表格添加注释内容
|
* @param tableName 表格的名称
|
* @param comment 注释的内容
|
* @return 受影响的行数
|
*/
|
@Update("COMMENT ON TABLE ${tableName} IS '${comment}' ")
|
@ResultType(Integer.class)
|
int commentTable(@Param("tableName") String tableName, @Param("comment") String comment);
|
|
|
/**
|
* 为表格的列添加注释内容
|
* @param tableName 表格的名称
|
* @param columnName 列
|
* @param comment 注释的内容
|
* @return 受影响的行数
|
*/
|
@Update("COMMENT ON column ${tableName}.${columnName} IS '${comment}' ")
|
@ResultType(Integer.class)
|
int commentColumnTable(@Param("tableName") String tableName,@Param("columnName")String columnName, @Param("comment") String comment);
|
|
|
/**
|
* 批量修改数据库的字段--
|
* @param tableName 表格的名称
|
* @param attributeSql 属性新的sql
|
* @return 影响的行数
|
*/
|
@Update("alter table ${tableName} ${attributeSql} ")
|
@ResultType(Integer.class)
|
int modifyTableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql);
|
|
/**
|
* 向数据库表中批量添加字段
|
* @param tableName 表格的名称
|
* @param attributeSql 要添加的新的sql
|
* @return 影响的行数
|
*/
|
@Update("alter table ${tableName} ${attributeSql} ")
|
@ResultType(Integer.class)
|
int addColumn2TableBySql(@Param("tableName") String tableName, @Param("attributeSql") String attributeSql);
|
|
/**
|
* 删除表格
|
* @param tableName 表格名称
|
* @return 影响的行数
|
*/
|
@Update("drop table if exists ${tableName}")
|
@ResultType(Integer.class)
|
int dropTable(@Param("tableName") String tableName);
|
|
/**
|
* 校验数据库表或者视图
|
* @param tableName 表格名称
|
* @return 存在的个数
|
*/
|
@Select("use information_scheam;select count(table_name) from tables where table_name = #{tableName,jdbcType=VARCHAR}")
|
@ResultType(Integer.class)
|
int checkTableExist(@Param("tableName") String tableName);
|
|
/**
|
* 查询表格的字段信息--sql server
|
* @param tableName 表格的名称
|
* @return 数据库表的字段信息
|
*/
|
@ResultMap("ddlTableColumnInfo")
|
@Select("")
|
List<DdlTableInDataBaseBO> selectTableColumnInfo(@Param("tableName")String tableName);
|
|
/**
|
* 删除表格中的列
|
* @param tableName 表名称
|
* @param columnName 列名称
|
* @return 受影响的行数
|
*/
|
int dropTableColumn(@Param("tableName")String tableName, @Param("columnName")String columnName);
|
|
|
/**
|
* 获取所有的表格名称
|
* @return 表格名称
|
*/
|
@Select("use information_scheam;select table_name from tables")
|
List<String> selectAllTableName();
|
|
/**
|
* 查询表格的中文名称
|
* @param tableName 表格名称
|
* @return 表格名称和表格中文名称
|
*/
|
DdlTableBO selectTableComment(@Param("tableName")String tableName);
|
|
}
|