88 lines
3.4 KiB
XML
88 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="tableManagement">
|
|
|
|
<!-- 테이블 목록 조회 -->
|
|
<select id="selectTableList" resultType="map">
|
|
SELECT
|
|
t.table_name as "tableName",
|
|
COALESCE(tl.table_label, t.table_name) as "displayName",
|
|
COALESCE(tl.description, '') as "description",
|
|
(SELECT COUNT(*) FROM information_schema.columns
|
|
WHERE table_name = t.table_name AND table_schema = 'public') as "columnCount"
|
|
FROM information_schema.tables t
|
|
LEFT JOIN table_labels tl ON t.table_name = tl.table_name
|
|
WHERE t.table_schema = 'public'
|
|
AND t.table_type = 'BASE TABLE'
|
|
AND t.table_name NOT LIKE 'pg_%'
|
|
AND t.table_name NOT LIKE 'sql_%'
|
|
ORDER BY t.table_name
|
|
</select>
|
|
|
|
<!-- 컬럼 정보 조회 -->
|
|
<select id="selectColumnList" parameterType="map" resultType="map">
|
|
SELECT
|
|
c.column_name as "columnName",
|
|
COALESCE(cl.column_label, c.column_name) as "displayName",
|
|
c.data_type as "dbType",
|
|
COALESCE(cl.web_type, 'text') as "webType",
|
|
COALESCE(cl.detail_settings, '') as "detailSettings",
|
|
COALESCE(cl.description, '') as "description",
|
|
c.is_nullable as "isNullable",
|
|
c.column_default as "defaultValue",
|
|
c.character_maximum_length as "maxLength",
|
|
c.numeric_precision as "numericPrecision",
|
|
c.numeric_scale as "numericScale",
|
|
cl.code_category as "codeCategory",
|
|
cl.code_value as "codeValue",
|
|
cl.reference_table as "referenceTable",
|
|
cl.reference_column as "referenceColumn"
|
|
FROM information_schema.columns c
|
|
LEFT JOIN column_labels cl ON c.table_name = cl.table_name AND c.column_name = cl.column_name
|
|
WHERE c.table_name = #{tableName}
|
|
ORDER BY c.ordinal_position
|
|
</select>
|
|
|
|
<!-- 테이블이 table_labels에 없으면 자동 추가 -->
|
|
<insert id="insertTableIfNotExists" parameterType="string">
|
|
INSERT INTO table_labels (table_name, table_label, description)
|
|
VALUES (#{tableName}, #{tableName}, '')
|
|
ON CONFLICT (table_name) DO NOTHING
|
|
</insert>
|
|
|
|
<update id="updateColumnSettings" parameterType="map">
|
|
INSERT INTO column_labels (
|
|
table_name,
|
|
column_name,
|
|
column_label,
|
|
web_type,
|
|
detail_settings,
|
|
code_category,
|
|
code_value,
|
|
reference_table,
|
|
reference_column
|
|
) VALUES (
|
|
#{tableName},
|
|
#{columnName},
|
|
#{columnLabel},
|
|
#{webType},
|
|
#{detailSettings},
|
|
#{codeCategory},
|
|
#{codeValue},
|
|
#{referenceTable},
|
|
#{referenceColumn}
|
|
)
|
|
ON CONFLICT (table_name, column_name) DO UPDATE SET
|
|
column_label = EXCLUDED.column_label,
|
|
web_type = EXCLUDED.web_type,
|
|
detail_settings = EXCLUDED.detail_settings,
|
|
code_category = EXCLUDED.code_category,
|
|
code_value = EXCLUDED.code_value,
|
|
reference_table = EXCLUDED.reference_table,
|
|
reference_column = EXCLUDED.reference_column,
|
|
updated_date = now()
|
|
</update>
|
|
|
|
</mapper>
|