package com.jwipc.sharding.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Set;

/**
 * @author shenyang.ou
 * @date 2024/3/22 12:58
 * @desc
 */
@Mapper
public interface DataShardingMapper {
    @Select("SELECT COUNT(*) FROM information_schema.tables WHERE table_name =  #{table}")
    Integer getTablesNumByName(@Param("table") String table);

    @Update("CREATE TABLE IF NOT EXISTS ${newTable}  LIKE  ${originalTable}")
    void copyTables(@Param("originalTable") String originalTable, @Param("newTable") String newTable);

    @Select("SELECT TABLE_NAME FROM information_schema.tables WHERE table_name LIKE  #{tableName}")
    @DS("master")
    Set<String> getFactoryCodes(@Param("tableName") String table);

}
