Skip to content

Commit

Permalink
[fix][dingo-sdk] Add table or col comment
Browse files Browse the repository at this point in the history
  • Loading branch information
guojn1 authored and ketor committed Nov 27, 2023
1 parent fc42813 commit 2b1fc2f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public interface Column {

boolean isAutoIncrement();

int getState();

String getComment();

default boolean isPrimary() {
return getPrimary() > -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import lombok.ToString;

@Builder
Expand All @@ -41,6 +42,11 @@ public class ColumnDefinition implements Column {
private int primary = -1;
private String defaultValue;
private boolean isAutoIncrement;
@Builder.Default
@Setter
private int state = 1;

private String comment;

@Deprecated
public ColumnDefinition(
Expand All @@ -52,7 +58,9 @@ public ColumnDefinition(
boolean nullable,
int primary,
String defaultValue,
boolean isAutoIncrement
boolean isAutoIncrement,
int state,
String comment
) {
this.name = name;
this.type = type;
Expand All @@ -63,6 +71,8 @@ public ColumnDefinition(
this.primary = primary;
this.defaultValue = defaultValue;
this.isAutoIncrement = isAutoIncrement;
this.state = state;
this.comment = comment;
}

@Override
Expand Down Expand Up @@ -109,4 +119,14 @@ public String getDefaultValue() {
public boolean isAutoIncrement() {
return isAutoIncrement;
}

@Override
public int getState() {
return state;
}

@Override
public String getComment() {
return comment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public interface Table {

IndexParameter getIndexParameter();

String getComment();

String getCharset();

String getCollate();

default int getPrimaryKeyCount() {
int count = 0;
for (Column column : getColumns()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ public class TableDefinition implements Table {
private long autoIncrement = 1;
private String createSql;
private IndexParameter indexParameter;
private String comment;
private String charset;
private String collate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public static Meta.TableDefinition mapping(Table table, Meta.DingoCommonId table
.putAllProperties(table.getProperties() == null ? new HashMap() : table.getProperties())
.setCreateSql(Parameters.cleanNull(table.getCreateSql(), ""))
.setIndexParameter(Optional.mapOrGet(table.getIndexParameter(), EntityConversion::mapping, () -> Common.IndexParameter.newBuilder().build()))
.setComment(table.getComment())
.setCharset(table.getCharset())
.setCollate(table.getCollate())
.build();
}

Expand All @@ -139,6 +142,9 @@ public static Table mapping(Meta.TableDefinitionWithId tableDefinitionWithId) {
.autoIncrement(tableDefinition.getAutoIncrement())
.createSql(tableDefinition.getCreateSql())
.indexParameter(Optional.mapOrNull(tableDefinition.getIndexParameter(), EntityConversion::mapping))
.comment(tableDefinition.getComment())
.charset(tableDefinition.getCharset())
.collate(tableDefinition.getCollate())
.build();
}

Expand Down Expand Up @@ -173,6 +179,8 @@ public static Column mapping(Meta.ColumnDefinition definition) {
.primary(definition.getIndexOfKey())
.defaultValue(definition.getDefaultVal())
.isAutoIncrement(definition.getIsAutoIncrement())
.state(definition.getState())
.comment(definition.getComment())
.build();
}

Expand Down Expand Up @@ -878,6 +886,8 @@ public static Meta.ColumnDefinition mapping(Column column) {
.setIndexOfKey(column.getPrimary())
.setSqlType(column.getType())
.setIsAutoIncrement(column.isAutoIncrement())
.setState(column.getState())
.setComment(column.getComment())
.build();
}

Expand Down
5 changes: 5 additions & 0 deletions proto/meta.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ message ColumnDefinition {
bool has_default_val = 8;
string default_val = 9;
bool is_auto_increment = 10;
int32 state = 11;
string comment = 12;
}

// Information about Index.
Expand Down Expand Up @@ -126,6 +128,9 @@ message TableDefinition {
int64 ttl = 3;
int64 auto_increment = 4;
string create_sql = 5;
string comment = 6;
string charset = 7;
string collate = 8;
PartitionRule table_partition = 20;
uint32 replica = 21;
dingodb.pb.common.Engine engine = 22;
Expand Down

0 comments on commit 2b1fc2f

Please sign in to comment.