Skip to content

Commit 2d83ec8

Browse files
consistency serial was added
1 parent 953e0df commit 2d83ec8

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

frame.go

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ const (
192192

193193
type Consistency uint16
194194

195+
type SerialConsistency = Consistency
196+
195197
const (
196198
Any Consistency = 0x00
197199
One Consistency = 0x01
@@ -202,6 +204,8 @@ const (
202204
LocalQuorum Consistency = 0x06
203205
EachQuorum Consistency = 0x07
204206
LocalOne Consistency = 0x0A
207+
Serial Consistency = 0x08
208+
LocalSerial Consistency = 0x09
205209
)
206210

207211
func (c Consistency) String() string {
@@ -224,6 +228,10 @@ func (c Consistency) String() string {
224228
return "EACH_QUORUM"
225229
case LocalOne:
226230
return "LOCAL_ONE"
231+
case Serial:
232+
return "SERIAL"
233+
case LocalSerial:
234+
return "LOCAL_SERIAL"
227235
default:
228236
return fmt.Sprintf("UNKNOWN_CONS_0x%x", uint16(c))
229237
}
@@ -253,13 +261,21 @@ func (c *Consistency) UnmarshalText(text []byte) error {
253261
*c = EachQuorum
254262
case "LOCAL_ONE":
255263
*c = LocalOne
264+
case "SERIAL":
265+
*c = Serial
266+
case "LOCAL_SERIAL":
267+
*c = LocalSerial
256268
default:
257269
return fmt.Errorf("invalid consistency %q", string(text))
258270
}
259271

260272
return nil
261273
}
262274

275+
func (c Consistency) IsSerial() bool {
276+
return c == Serial || c == LocalSerial
277+
278+
}
263279
func ParseConsistency(s string) Consistency {
264280
var c Consistency
265281
if err := c.UnmarshalText([]byte(strings.ToUpper(s))); err != nil {
@@ -286,41 +302,6 @@ func MustParseConsistency(s string) (Consistency, error) {
286302
return c, nil
287303
}
288304

289-
type SerialConsistency uint16
290-
291-
const (
292-
Serial SerialConsistency = 0x08
293-
LocalSerial SerialConsistency = 0x09
294-
)
295-
296-
func (s SerialConsistency) String() string {
297-
switch s {
298-
case Serial:
299-
return "SERIAL"
300-
case LocalSerial:
301-
return "LOCAL_SERIAL"
302-
default:
303-
return fmt.Sprintf("UNKNOWN_SERIAL_CONS_0x%x", uint16(s))
304-
}
305-
}
306-
307-
func (s SerialConsistency) MarshalText() (text []byte, err error) {
308-
return []byte(s.String()), nil
309-
}
310-
311-
func (s *SerialConsistency) UnmarshalText(text []byte) error {
312-
switch string(text) {
313-
case "SERIAL":
314-
*s = Serial
315-
case "LOCAL_SERIAL":
316-
*s = LocalSerial
317-
default:
318-
return fmt.Errorf("invalid consistency %q", string(text))
319-
}
320-
321-
return nil
322-
}
323-
324305
const (
325306
apacheCassandraTypePrefix = "org.apache.cassandra.db.marshal."
326307
)

session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,9 @@ func (q *Query) Bind(v ...interface{}) *Query {
12651265
// SERIAL. This option will be ignored for anything else that a
12661266
// conditional update/insert.
12671267
func (q *Query) SerialConsistency(cons SerialConsistency) *Query {
1268+
if !cons.IsSerial() {
1269+
panic("Serial consistency can only be SERIAL or LOCAL_SERIAL got " + cons.String())
1270+
}
12681271
q.serialCons = cons
12691272
return q
12701273
}
@@ -1915,6 +1918,9 @@ func (b *Batch) Size() int {
19151918
//
19161919
// Only available for protocol 3 and above
19171920
func (b *Batch) SerialConsistency(cons SerialConsistency) *Batch {
1921+
if !cons.IsSerial() {
1922+
panic("Serial consistency can only be SERIAL or LOCAL_SERIAL got " + cons.String())
1923+
}
19181924
b.serialCons = cons
19191925
return b
19201926
}

0 commit comments

Comments
 (0)