31 lines
764 B
Go
31 lines
764 B
Go
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
|
||
}
|
||
|