diff --git a/result_set.go b/result_set.go index d7ba3f2c..4d614f66 100644 --- a/result_set.go +++ b/result_set.go @@ -320,6 +320,7 @@ func (res ResultSet) Scan(v interface{}) error { } colNames := res.GetColNames() + fmt.Println("DEBUG TTL", colNames) rows := res.GetRows() t := reflect.TypeOf(v).Elem().Elem() 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..20506aa8 100644 --- a/session_pool_test.go +++ b/session_pool_test.go @@ -413,6 +413,11 @@ func TestSessionPoolApplySchema(t *testing.T) { Type: "int64", Nullable: true, }, + { + Field: "created_at", + Type: "timestamp", + Nullable: false, + }, }, } _, err = sessionPool.CreateTag(tagSchema) @@ -429,13 +434,28 @@ 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) + + // Add TTL to tag + _, err = sessionPool.AddTagTTL("account", "created_at", 86400) + if err != nil { + t.Fatal(err) + } + fmt.Println("DEBUG TTL") + labels, err = sessionPool.DescTag("account") + for _, label := range labels { + if label.Field == "created_at" { + fmt.Println("DEBUG TTL field") + } + } edgeSchema := LabelSchema{ Name: "account_email", @@ -444,6 +464,11 @@ func TestSessionPoolApplySchema(t *testing.T) { Field: "email", Nullable: false, }, + { + Field: "created_at", + Type: "timestamp", + Nullable: false, + }, }, } _, err = sessionPool.CreateEdge(edgeSchema) @@ -460,9 +485,17 @@ 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) + + // Add TTL to edge + _, err = sessionPool.AddEdgeTTL("account_email", "created_at", 86400) + if err != nil { + t.Fatal(err) + } } func TestIdleSessionCleaner(t *testing.T) {