backend/pkg/library/cassandra/query_helper.go

31 lines
764 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cassandra
import (
"context"
"time"
"github.com/scylladb/gocqlx/v3"
)
// queryHelper 封裝查詢相關的輔助方法
type queryHelper struct{}
// withTimestamp 為查詢添加時間戳
func (h *queryHelper) withTimestamp(q *gocqlx.Queryx) *gocqlx.Queryx {
return q.WithTimestamp(time.Now().UnixNano() / 1e3)
}
// withContextAndTimestamp 為查詢添加 context 和時間戳
func (h *queryHelper) withContextAndTimestamp(ctx context.Context, q *gocqlx.Queryx) *gocqlx.Queryx {
return q.WithContext(ctx).WithTimestamp(time.Now().UnixNano() / 1e3)
}
// getKeyspace 獲取 keyspace如果為空則使用預設值
func getKeyspace(db *CassandraDB, keyspace string) string {
if keyspace == "" {
return db.defaultKeyspace
}
return keyspace
}