Documentation
¶
Overview ¶
Package cassandra is a history Store backed by Apache Cassandra via gocql.
Schema (created by InitializeSchema=true):
CREATE TABLE <keyspace>.<table> (
conversation_id TEXT,
seq TIMEUUID,
message TEXT,
PRIMARY KEY ((conversation_id), seq)
) WITH CLUSTERING ORDER BY (seq ASC);
`conversation_id` is the partition key and `seq` is a client-generated TIMEUUID clustering key. Each Write reserves a strictly increasing local sequence range and sends one unlogged batch to that partition. Concurrent calls and writes from distinct Store instances have no defined relative order.
Example:
cluster := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "scope"
sess, _ := cluster.CreateSession()
defer sess.Close()
store, _ := cassandra.NewStore(ctx, cassandra.StoreConfig{
Session: sess,
Keyspace: "scope",
InitializeSchema: true,
})
Index ¶
- Constants
- type Store
- func (s *Store) Clear(ctx context.Context, conversationID history.ConversationID) (err error)
- func (s *Store) Conversations(ctx context.Context) (ids []history.ConversationID, err error)
- func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) (storedMessages []chat.Message, err error)
- func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, ...) (err error)
- type StoreConfig
Constants ¶
const ( DefaultKeyspace = "scope" DefaultTableName = "chat_history" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists each conversation in one Cassandra partition through a caller-owned session. It never closes that session. A Write preserves its argument order with a locally monotonic TIMEUUID range; relative ordering across concurrent calls or separate Store values remains unspecified.
func (*Store) Conversations ¶
Conversations returns every stored conversation ID in lexical order.
SELECT DISTINCT on the partition key reads only partition metadata, so no ALLOW FILTERING is needed.
func (*Store) Read ¶
func (s *Store) Read(ctx context.Context, conversationID history.ConversationID) (storedMessages []chat.Message, err error)
Read returns every message stored under conversationID in insertion order (TIMEUUID ascending).
func (*Store) Write ¶
func (s *Store) Write(ctx context.Context, conversationID history.ConversationID, messages ...chat.Message) (err error)
Write appends every message under conversationID in one single-partition unlogged batch. Client-generated TIMEUUIDs are strictly increasing within one call; concurrent calls have no defined relative order.
type StoreConfig ¶
type StoreConfig struct {
// Session is the live gocql session. Required. Callers own
// session lifetime.
Session *gocql.Session
// Keyspace is the CQL keyspace. Optional: defaults to
// [DefaultKeyspace]. The keyspace must already exist (Cassandra
// keyspace creation needs replication-strategy choices the store
// cannot make on the user's behalf).
Keyspace string
// TableName is the CQL table. Optional: defaults to
// [DefaultTableName] ("chat_history").
TableName string
// InitializeSchema, when true, creates the table if it doesn't
// already exist. The keyspace itself is NOT created.
InitializeSchema bool
}
func (StoreConfig) Validate ¶
func (s StoreConfig) Validate() error