mirror of
https://github.com/vran-dev/databasir.git
synced 2025-10-29 11:29:19 +08:00
feature: support add description to table or column (#46)
* feat: generate document description model * feat: add description field to document * fix: checkstyle * feat:update frontend resources
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package com.databasir.dao.impl;
|
||||
|
||||
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
|
||||
import com.databasir.dao.tables.records.DocumentDescriptionRecord;
|
||||
import lombok.Getter;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.DOCUMENT_DESCRIPTION;
|
||||
|
||||
@Repository
|
||||
public class DocumentDescriptionDao extends BaseDao<DocumentDescriptionPojo> {
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private DSLContext dslContext;
|
||||
|
||||
public DocumentDescriptionDao() {
|
||||
super(DOCUMENT_DESCRIPTION, DocumentDescriptionPojo.class);
|
||||
}
|
||||
|
||||
public boolean exists(Integer projectId, String tableName, String columnName) {
|
||||
Condition condition = DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId)
|
||||
.and(DOCUMENT_DESCRIPTION.TABLE_NAME.eq(tableName));
|
||||
if (columnName == null) {
|
||||
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull());
|
||||
} else {
|
||||
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.eq(columnName));
|
||||
}
|
||||
return this.exists(condition);
|
||||
}
|
||||
|
||||
public void update(DocumentDescriptionPojo pojo) {
|
||||
Condition condition = DOCUMENT_DESCRIPTION.TABLE_NAME.eq(pojo.getTableName());
|
||||
if (pojo.getColumnName() == null) {
|
||||
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull());
|
||||
} else {
|
||||
condition = condition.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.eq(pojo.getColumnName()));
|
||||
}
|
||||
DocumentDescriptionRecord record = getDslContext().newRecord(DOCUMENT_DESCRIPTION, pojo);
|
||||
getDslContext().executeUpdate(record, condition);
|
||||
}
|
||||
|
||||
public List<DocumentDescriptionPojo> selectByProjectId(Integer projectId) {
|
||||
return selectByCondition(DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId));
|
||||
}
|
||||
|
||||
public List<DocumentDescriptionPojo> selectTableDescriptionByProjectId(Integer projectId) {
|
||||
return selectByCondition(DOCUMENT_DESCRIPTION.PROJECT_ID.eq(projectId)
|
||||
.and(DOCUMENT_DESCRIPTION.COLUMN_NAME.isNull()));
|
||||
}
|
||||
|
||||
public List<DocumentDescriptionPojo> selectByCondition(Condition condition) {
|
||||
return this.getDslContext()
|
||||
.selectFrom(DOCUMENT_DESCRIPTION).where(condition)
|
||||
.fetchInto(DocumentDescriptionPojo.class);
|
||||
}
|
||||
}
|
||||
@@ -19,5 +19,21 @@ CREATE TABLE IF NOT EXISTS database_type
|
||||
REPLACE INTO databasir.database_type (id, database_type, icon, DESCRIPTION, jdbc_driver_file_url,
|
||||
jdbc_driver_class_name,
|
||||
jdbc_protocol, url_pattern)
|
||||
VALUES (1, 'mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql', '{{jdbc.protocol}}://{{db.url}}/{{db.name}}'),
|
||||
(2, 'postgresql', '', 'system default postgresql', 'N/A', 'org.postgresql.Driver', 'jdbc:postgresql', '{{jdbc.protocol}}://{{db.url}}/{{db.name}}');
|
||||
VALUES (1, 'mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql',
|
||||
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}'),
|
||||
(2, 'postgresql', '', 'system default postgresql', 'N/A', 'org.postgresql.Driver', 'jdbc:postgresql',
|
||||
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS document_description
|
||||
(
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
content TEXT NOT NULL,
|
||||
project_id INT NOT NULL,
|
||||
table_name VARCHAR(255) NOT NULL,
|
||||
column_name VARCHAR(255) DEFAULT NULL,
|
||||
update_by INT NOT NULL,
|
||||
update_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT UNIQUE uk_project_id_table_name_column_name (project_id, table_name, column_name)
|
||||
) CHARSET utf8mb4
|
||||
COLLATE utf8mb4_unicode_ci COMMENT 'custom document description';
|
||||
Reference in New Issue
Block a user