diff --git a/session_pool.go b/session_pool.go index 2accca1f..c699c8bc 100644 --- a/session_pool.go +++ b/session_pool.go @@ -319,6 +319,16 @@ func (pool *SessionPool) CreateTag(tag LabelSchema) (*ResultSet, error) { return rs, nil } +func (pool *SessionPool) AddTagTTL(tagName string, colName string, duration uint) (*ResultSet, error) { + q := fmt.Sprintf(`ALTER TAG %s TTL_DURATION = %d, TTL_COL = "%s";`, tagName, duration, colName) + rs, err := pool.ExecuteAndCheck(q) + if err != nil { + return nil, err + } + + return rs, nil +} + func (pool *SessionPool) DescTag(tagName string) ([]Label, error) { q := fmt.Sprintf("DESC TAG %s;", tagName) rs, err := pool.ExecuteAndCheck(q) @@ -353,6 +363,16 @@ func (pool *SessionPool) CreateEdge(edge LabelSchema) (*ResultSet, error) { return rs, nil } +func (pool *SessionPool) AddEdgeTTL(tagName string, colName string, duration uint) (*ResultSet, error) { + q := fmt.Sprintf(`ALTER EDGE %s TTL_DURATION = %d, TTL_COL = "%s";`, tagName, duration, colName) + rs, err := pool.ExecuteAndCheck(q) + if err != nil { + return nil, err + } + + return rs, nil +} + func (pool *SessionPool) DescEdge(edgeName string) ([]Label, error) { q := fmt.Sprintf("DESC EDGE %s;", edgeName) rs, err := pool.ExecuteAndCheck(q) diff --git a/session_pool_test.go b/session_pool_test.go index 1113ca2f..9cffd210 100644 --- a/session_pool_test.go +++ b/session_pool_test.go @@ -413,12 +413,24 @@ func TestSessionPoolApplySchema(t *testing.T) { Type: "int64", Nullable: true, }, + { + Field: "created_at", + Type: "timestamp", + Nullable: false, + }, }, } _, err = sessionPool.CreateTag(tagSchema) if err != nil { t.Fatal(err) } + + // Add TTL to tag + _, err = sessionPool.AddTagTTL("account", "created_at", 86400) + if err != nil { + t.Fatal(err) + } + tags, err := sessionPool.ShowTags() if err != nil { t.Fatal(err) @@ -429,13 +441,15 @@ func TestSessionPoolApplySchema(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, 3, len(labels), "should have 3 labels") - assert.Equal(t, "name", labels[0].Field, "field name should be name") - assert.Equal(t, "string", labels[0].Type, "field type should be string") - assert.Equal(t, "email", labels[1].Field, "field name should be email") - assert.Equal(t, "string", labels[1].Type, "field type should be string") - assert.Equal(t, "phone", labels[2].Field, "field name should be phone") - assert.Equal(t, "int64", labels[2].Type, "field type should be int64") + assert.Equal(t, 4, len(labels)) + assert.Equal(t, "name", labels[0].Field) + assert.Equal(t, "string", labels[0].Type) + assert.Equal(t, "email", labels[1].Field) + assert.Equal(t, "string", labels[1].Type) + assert.Equal(t, "phone", labels[2].Field) + assert.Equal(t, "int64", labels[2].Type) + assert.Equal(t, "created_at", labels[3].Field) + assert.Equal(t, "timestamp", labels[3].Type) edgeSchema := LabelSchema{ Name: "account_email", @@ -444,12 +458,24 @@ func TestSessionPoolApplySchema(t *testing.T) { Field: "email", Nullable: false, }, + { + Field: "created_at", + Type: "timestamp", + Nullable: false, + }, }, } _, err = sessionPool.CreateEdge(edgeSchema) if err != nil { t.Fatal(err) } + + // Add TTL to edge + _, err = sessionPool.AddEdgeTTL("account_email", "created_at", 86400) + if err != nil { + t.Fatal(err) + } + edges, err := sessionPool.ShowEdges() if err != nil { t.Fatal(err) @@ -460,9 +486,12 @@ func TestSessionPoolApplySchema(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, 1, len(labels), "should have 1 labels") - assert.Equal(t, "email", labels[0].Field, "field name should be email") - assert.Equal(t, "string", labels[0].Type, "field type should be string") + assert.Equal(t, 2, len(labels), "should have 2 labels") + assert.Equal(t, "email", labels[0].Field) + assert.Equal(t, "string", labels[0].Type) + assert.Equal(t, "created_at", labels[1].Field) + assert.Equal(t, "timestamp", labels[1].Type) + } func TestIdleSessionCleaner(t *testing.T) {