Skip to content

Commit

Permalink
Merge pull request #311 from vadimalekseev/main
Browse files Browse the repository at this point in the history
chore: automatic column inference for the UUID column
  • Loading branch information
ernado authored Jun 21, 2023
2 parents b7e3366 + 6a4fd4f commit e616553
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions proto/col_auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func (c *ColAuto) Infer(t ColumnType) error {
c.Data = new(ColDate)
case "Map(String,String)":
c.Data = NewMap[string, string](new(ColStr), new(ColStr))
case ColumnTypeUUID:
c.Data = new(ColUUID)
case ColumnTypeArray.Sub(ColumnTypeUUID):
c.Data = new(ColUUID).Array()
case ColumnTypeNullable.Sub(ColumnTypeUUID):
c.Data = new(ColUUID).Nullable()
default:
switch t.Base() {
case ColumnTypeDateTime:
Expand Down
3 changes: 3 additions & 0 deletions proto/col_auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ func TestColAuto_Infer(t *testing.T) {
ColumnTypeNothing,
"Nullable(Nothing)",
"Array(Nothing)",
ColumnTypeUUID,
ColumnTypeArray.Sub(ColumnTypeUUID),
ColumnTypeNullable.Sub(ColumnTypeUUID),
} {
r := AutoResult("foo")
require.NoError(t, r.Data.(Inferable).Infer(columnType))
Expand Down
10 changes: 10 additions & 0 deletions proto/col_uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ func (c ColUUID) Row(i int) uuid.UUID { return c[i] }
func (c *ColUUID) Reset() { *c = (*c)[:0] }
func (c *ColUUID) Append(v uuid.UUID) { *c = append(*c, v) }
func (c *ColUUID) AppendArr(v []uuid.UUID) { *c = append(*c, v...) }

// Nullable is helper that creates Nullable(uuid.UUID).
func (c *ColUUID) Nullable() *ColNullable[uuid.UUID] {
return NewColNullable[uuid.UUID](c)
}

// Array is helper that creates Array of uuid.UUID.
func (c *ColUUID) Array() *ColArr[uuid.UUID] {
return NewArray[uuid.UUID](c)
}

0 comments on commit e616553

Please sign in to comment.