backend/pkg/library/cassandra/query_helper.go

31 lines
764 B
Go
Raw Normal View History

2025-11-17 09:31:58 +00:00
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
}