Skip to content

Commit aa7fded

Browse files
authored
Merge pull request #150 from earlgray283/master
[v1] add allowCommitTimestamp field to models.Column
2 parents 297189b + 2c3db2f commit aa7fded

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

loaders/parser.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,29 @@ func (s *SpannerLoaderFromDDL) ColumnList(name string) ([]*models.Column, error)
132132
if _, ok := c.DefaultSemantics.(*ast.GeneratedColumnExpr); ok {
133133
isGenerated = true
134134
}
135+
136+
allowCommitTimestamp := false
137+
if c.Options != nil {
138+
for _, r := range c.Options.Records {
139+
if r.Name.Name == "allow_commit_timestamp" {
140+
boolLiteral, ok := r.Value.(*ast.BoolLiteral)
141+
if !ok {
142+
return nil, fmt.Errorf("the type of 'allow_commit_timestamp' should be 'bool', but got '%T'", r.Value)
143+
}
144+
allowCommitTimestamp = boolLiteral.Value
145+
break
146+
}
147+
}
148+
}
149+
135150
cols = append(cols, &models.Column{
136-
FieldOrdinal: i + 1,
137-
ColumnName: c.Name.Name,
138-
DataType: c.Type.SQL(),
139-
NotNull: c.NotNull,
140-
IsPrimaryKey: pk,
141-
IsGenerated: isGenerated,
151+
FieldOrdinal: i + 1,
152+
ColumnName: c.Name.Name,
153+
DataType: c.Type.SQL(),
154+
NotNull: c.NotNull,
155+
IsPrimaryKey: pk,
156+
IsGenerated: isGenerated,
157+
AllowCommitTimestamp: allowCommitTimestamp,
142158
})
143159
}
144160

models/model.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ type Table struct {
2828

2929
// Column represents column info.
3030
type Column struct {
31-
FieldOrdinal int // field_ordinal
32-
ColumnName string // column_name
33-
DataType string // data_type
34-
NotNull bool // not_null
35-
IsPrimaryKey bool // is_primary_key
36-
IsGenerated bool // is_generated
31+
FieldOrdinal int // field_ordinal
32+
ColumnName string // column_name
33+
DataType string // data_type
34+
NotNull bool // not_null
35+
IsPrimaryKey bool // is_primary_key
36+
IsGenerated bool // is_generated
37+
AllowCommitTimestamp bool // allow_commit_timestamp
3738
}
3839

3940
// Index represents an index.

0 commit comments

Comments
 (0)