github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/table/ttl.go (about)

     1  package table
     2  
     3  import (
     4  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
     5  
     6  	"github.com/ydb-platform/ydb-go-sdk/v3/table/options"
     7  )
     8  
     9  func NewTimeToLiveSettings(settings *Ydb_Table.TtlSettings) *options.TimeToLiveSettings {
    10  	if settings == nil {
    11  		return nil
    12  	}
    13  	switch mode := settings.GetMode().(type) {
    14  	case *Ydb_Table.TtlSettings_DateTypeColumn:
    15  		return &options.TimeToLiveSettings{
    16  			ColumnName:         mode.DateTypeColumn.GetColumnName(),
    17  			ExpireAfterSeconds: mode.DateTypeColumn.GetExpireAfterSeconds(),
    18  			Mode:               options.TimeToLiveModeDateType,
    19  		}
    20  
    21  	case *Ydb_Table.TtlSettings_ValueSinceUnixEpoch:
    22  		return &options.TimeToLiveSettings{
    23  			ColumnName:         mode.ValueSinceUnixEpoch.GetColumnName(),
    24  			ColumnUnit:         timeToLiveUnit(mode.ValueSinceUnixEpoch.GetColumnUnit()),
    25  			ExpireAfterSeconds: mode.ValueSinceUnixEpoch.GetExpireAfterSeconds(),
    26  			Mode:               options.TimeToLiveModeValueSinceUnixEpoch,
    27  		}
    28  	}
    29  
    30  	return nil
    31  }
    32  
    33  func timeToLiveUnit(unit Ydb_Table.ValueSinceUnixEpochModeSettings_Unit) *options.TimeToLiveUnit {
    34  	var res options.TimeToLiveUnit
    35  	switch unit {
    36  	case Ydb_Table.ValueSinceUnixEpochModeSettings_UNIT_SECONDS:
    37  		res = options.TimeToLiveUnitSeconds
    38  	case Ydb_Table.ValueSinceUnixEpochModeSettings_UNIT_MILLISECONDS:
    39  		res = options.TimeToLiveUnitMilliseconds
    40  	case Ydb_Table.ValueSinceUnixEpochModeSettings_UNIT_MICROSECONDS:
    41  		res = options.TimeToLiveUnitMicroseconds
    42  	case Ydb_Table.ValueSinceUnixEpochModeSettings_UNIT_NANOSECONDS:
    43  		res = options.TimeToLiveUnitNanoseconds
    44  	case Ydb_Table.ValueSinceUnixEpochModeSettings_UNIT_UNSPECIFIED:
    45  		res = options.TimeToLiveUnitUnspecified
    46  	default:
    47  		panic("ydb: unknown Ydb unit for value since epoch")
    48  	}
    49  
    50  	return &res
    51  }