This is an automated email from the ASF dual-hosted git repository.

joaoreis pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 343007bf Add GetSerialConsistency to Query and Batch
343007bf is described below

commit 343007bf5fb06156e723bf17af45663de679fae3
Author: Tejas Lodaya <[email protected]>
AuthorDate: Mon Jan 12 10:11:26 2026 -0800

    Add GetSerialConsistency to Query and Batch
    
    Return the serial consistency as (Consistency, bool) so callers can detect 
"not set" and avoid using the zero value ANY for serial operations, which is 
invalid and can cause panics.
    
    patch by tejaslodayadd, joao-r-reis; reviewed by joao-r-reis, worryg0d for 
CASSGO-103
    
    Co-authored-by: João Reis <[email protected]>
---
 CHANGELOG.md    |  1 +
 session.go      | 14 ++++++++++++++
 session_test.go | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5832fa17..04a16f50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic 
Versioning](https://semver.org/spec/v2.0.0
 - Introduced configurable schema metadata caching modes to control what 
metadata is cached (CASSGO-107)
 - Support for session ready, host state, topology change and schema changes 
custom listeners (CASSGO-101)
 - Add Session.AllKeyspaceMetadata() (CASSGO-109)
+- Add GetSerialConsistency method to Query and Batch (CASSGO-103)
 
 ### Changed
 
diff --git a/session.go b/session.go
index bd4899dd..2895719f 100644
--- a/session.go
+++ b/session.go
@@ -1334,6 +1334,13 @@ func (q *Query) SerialConsistency(cons Consistency) 
*Query {
        return q
 }
 
+// GetSerialConsistency returns the currently configured serial consistency 
level
+// for the query. The boolean return value indicates whether a serial 
consistency
+// level has been set.
+func (q *Query) GetSerialConsistency() (Consistency, bool) {
+       return q.serialCons, q.serialCons.isSerial()
+}
+
 // PageState sets the paging state for the query to resume paging from a 
specific
 // point in time. Setting this will disable to query paging for this query, and
 // must be used for all subsequent pages.
@@ -2141,6 +2148,13 @@ func (b *Batch) SerialConsistency(cons Consistency) 
*Batch {
        return b
 }
 
+// GetSerialConsistency returns the currently configured serial consistency 
level
+// for the batch. The boolean return value indicates whether a serial 
consistency
+// level has been set.
+func (b *Batch) GetSerialConsistency() (Consistency, bool) {
+       return b.serialCons, b.serialCons.isSerial()
+}
+
 // DefaultTimestamp will enable the with default timestamp flag on the query.
 // If enable, this will replace the server side assigned
 // timestamp as default timestamp. Note that a timestamp in the query itself
diff --git a/session_test.go b/session_test.go
index 3eeba22f..b1c7b747 100644
--- a/session_test.go
+++ b/session_test.go
@@ -108,6 +108,15 @@ func TestQueryBasicAPI(t *testing.T) {
                t.Fatalf("expected Query.GetConsistency to return 'All', got 
'%s'", qry.GetConsistency())
        }
 
+       if sc, ok := qry.GetSerialConsistency(); ok {
+               t.Fatalf("expected Query.GetSerialConsistency to return false 
when not set, got '%s'", sc)
+       }
+
+       qry.SerialConsistency(Serial)
+       if sc, ok := qry.GetSerialConsistency(); !ok || sc != Serial {
+               t.Fatalf("expected Query.GetSerialConsistency to return 
'Serial', got '%v' (ok=%v)", sc, ok)
+       }
+
        trace := &traceWriter{}
        qry.Trace(trace)
        if qry.trace != trace {
@@ -194,6 +203,16 @@ func TestBatchBasicAPI(t *testing.T) {
                t.Fatalf("expected batch.GetConsistency() to return 'One', got 
'%s'", b.GetConsistency())
        }
 
+       // Test Serial Consistency
+       if sc, ok := b.GetSerialConsistency(); ok {
+               t.Fatalf("expected batch.GetSerialConsistency() to return false 
when not set, got '%s'", sc)
+       }
+
+       b.SerialConsistency(Serial)
+       if sc, ok := b.GetSerialConsistency(); !ok || sc != Serial {
+               t.Fatalf("expected batch.GetSerialConsistency() to return 
'Serial', got '%v' (ok=%v)", sc, ok)
+       }
+
        trace := &traceWriter{}
        b.Trace(trace)
        if b.trace != trace {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to